Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Gravity with Vector calculation

  1. Feb 24, 2009 #1
    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
     
  2. jcsd
  3. Feb 24, 2009 #2
    You have to define the * operation for the class Vector. Google "operator overload".
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Gravity with Vector calculation
  1. Aghhh vectors (Replies: 2)

  2. Gravity with Java (Replies: 4)

  3. C++ Vectors (Replies: 1)

Loading...