خرید بک لینک

Vote count: 0

I have a simulation with a planet orbiting a star. The equation for force on the planet is:

G*M1*M2*(q1-q2)/||q1-q2||^3

Where G is the gravitational constant, M1 and M2 are the masses of the star and planet, and q1-q2 is the difference between the position vectors of the two bodies.

I have converted this equation into component form where

Fx=G*M1*M2*(x1-x2)/||q1-q2||^3

Fy=G*M1*M2*(y1-y2)/||q1-q2||^3

with x1-x2 being the difference between the x component of the vectors, and y1-y2 being the difference between the y components of the vectors.

This is my code

    xdif = (planets[0].x - stars[0].x);
    ydif = (planets[0].y - stars[0].y);

    planets[0].ax = -10*xdif / pow((pow(xdif, 2) + pow(ydif, 2)), 1.5);
    planets[0].ay = -10*ydif / pow((pow(xdif, 2) + pow(ydif, 2)), 1.5);

For some reason, the planet does not follow an orbit like it should. Does anyone know what I got wrong?

asked 37 secs ago

برچسب: نویسنده: استخدام کار تاريخ: جمعه 11 تير 1395 ساعت: 6:36

صفحه بندی