I made a simulation in C++ with Newtons law and test it comparing the planets positions with the position from Solar system Calculator Don Cross (which I converted from JavaScript to C++)
http://cosinekitty.com/solar_system.html
What I do is every time step(usually 1 second but step 0.2 second is very similar to 10 seconds step) :
- Calculate accelaration ( $= $ newton forzes $\times$ deltatime)
- Update speed and positions
- Compare postions with results from Don Cross solar calculator alghorithms
But after 10 days of simulation I get this distance deviation (to the calculator from Don Cross) results :
$\mathrm{Mercury} \ 4498.7 \ \mathrm{km}$
$\mathrm{Venus \ X} \ 1939.8 \ \mathrm{km}$
$\mathrm{Earth \ X} \ 10614.6 \ \mathrm{km}$
$\mathrm{Moon \ X} \ 7800.2 \ \mathrm{km}$
$\mathrm{Mars \ X} \ 445.2 \ \mathrm{km}$
$\mathrm{Ceres \ X} \ 129.5 \ \mathrm{km}$
$\mathrm{Pallas \ X} \ 432.4 \ \mathrm{km}$
$\mathrm{Juno \ X} \ 151.4 \ \mathrm{km}$
$\mathrm{Vesta \ X} \ 157.6 \ \mathrm{km}$
$\mathrm{Ida \ X} \ 73.6 \ \mathrm{km}$
$\mathrm{Gaspra} \ 455.3 \ \mathrm{km}$
$\mathrm{9P/T1} \ 241.5 \ \mathrm{km}$
$\mathrm{19P/B} \ 402.7 \ \mathrm{km}$
$\mathrm{67P/C-G} \ 533.2 \ \mathrm{km}$
$\mathrm{81P/W2} \ 110.7 \ \mathrm{km}$
$\mathrm{Jupiter} \ 172.3 \ \mathrm{km}$
$\mathrm{Saturn} \ 261.2 \ \mathrm{km}$
$\mathrm{Uranus} \ 71.4 \ \mathrm{km}$
$\mathrm{Neptune} \ 31.3 \ \mathrm{km}$
$\mathrm{Pluto \ X \ } \ 45.7 \ \mathrm{km}$
As you see some planets have little desviations and some bigger, so my question is: Can Newton's be accurate? or Don Cross solar system calculator is not? Or there is black matter in that region? Or what else?
void CGravitator::CalcAceleration(double timeseconds){
unsigned int i,j,iend;
if (sunStatic)iend=m_np-1;
else iend=m_np;
for (i = 0; i < iend; i++) {
m_planetas[i].aceleration.set(0,0,0);
CVector3 totalGravitationalForce;
// Loop through all bodies in the universe to calculate their gravitational pull on the object (TODO: Ignore very far away objects for better performance)
for (j = 0; j < m_np; j++) {
if (i == j) continue; // No need to calculate the gravitational pull of a body on itself as it will always be 0.
double distancia =CVector3::Distancia(m_planetas[i].pos,m_planetas[j].pos);
double force = KGNEWTON * m_planetas[i].masa * m_planetas[j].masa / pow(distancia, 2);
CVector3 forceDirection = CVector3::Normalize(m_planetas[j].pos - m_planetas[i].pos);
totalGravitationalForce += forceDirection * force;
}
CVector3 incspeed = totalGravitationalForce / m_planetas[i].masa ;
m_planetas[i].aceleration += incspeed * timeseconds;
}
m_planetas[i].masa
. Cancel those out. (And change "force" in your variable names to "acceleration".) #2 You're first (presumably) taking a square root insideCVector3::Distancia
and then squaring the distance. Cancel those out too. And #3 yes, avoid Euler integration. And #4 please include your actual velocity and position update code in your question — it might have bugs or numerical inaccuracies that affect your results. $\endgroup$