Gravity with Vector calculation

  • Thread starter Sword7
  • Start date
  • #1
19
2

Main Question or Discussion Point

Hello folks,

I implemented class Vector into my C++ gravity simulation program that I recently started to write from scratch. I changed individual variables into Vector variable but gcc compiler refuse compile gravity formula with Vector. My original code was:

Fgx = (G * M * m * Px) / (r*r*r);
Fgy = (G * M * m * Py) / (r*r*r);
Fgz = (G * M * m * Pz) / (r*r*r);

Ax = Fgx / m; Ay = Fgy / m; Az = Fgz / m;
Vx += Ax; Vy += Ay, Vz += Az;

My new code is:

Vector Ps, Fs;

Ps = Vector(7000 * 1000, 0, 0);

Fs = (G * M * m * Ps) / (r*r*r);

As = Fs / m;
Vs += As;

I tried to compile that but gcc compiler complaint about operator * not defined in class Vector for that. I had changed that code and it now worked:

Fs.x = (G * M * m * Ps.x) / (r*r*r);
:

Does anyone know any solution with vector calculation within gravity formula? I am new to vector math.

Thanks!
Sword7
 

Answers and Replies

  • #2
287
0
You have to define the * operation for the class Vector. Google "operator overload".
 
Top