# Gravity around a point? (In 2D, like planets orbiting)

## Recommended Posts

I've been trying to do this today but I keep getting awkward results. Does anyone know of a good way to calculate gravity around a point, like planets orbiting a star?

##### Share on other sites
This might be obvious but if you just want quick results.

http://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation

##### Share on other sites
Quote:
 Original post by SirisianThis might be obvious but if you just want quick results.http://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation

Yeah I was using that but I was mostly having problems putting it into x and y coords. I could only figure out the hypotenuse of the force, and had trouble converting it into x and y.

##### Share on other sites
It's been a while since I wrote a planet simulation but here.

Vector directionOfForce = object1.position - object2.position;

//radius = Math.Sqrt((object1.x - object2.x)*(object1.x - object2.x) + (object1.y - object2.y) * (object1.y - object2.y));

//normalize the direction
directionOfForce.Normalize();

Once you understand that then:

float gConstant = 1;

for(int i = 0; i < AllObjects.Count; ++i){
for(int j = 0; j < AllObjects.Count; ++j){
if(i != j){
Vector directionOfForce = AllObjects[i].position - AllObjects[j].position;
directionOfForce.Normalize();
}
}
}

I think that's right. Try it.

Basically for every object apply the force of every other object in relations to it's mass.

##### Share on other sites
Given a radius r and an angle θ:
x = r cos θy = r sin θ

##### Share on other sites
Quote:
 Original post by OluseyiGiven a radius r and an angle θ:x = r cos θy = r sin θ

Useful if you have the angle, but you don't.

You probably want:

F = G * m1 * m2 / r3 * r

where r = p2 - p1 and r = |r|

##### Share on other sites
Quote:
Original post by Julian90
Quote:
 Original post by OluseyiGiven a radius r and an angle θ:x = r cos θy = r sin θ

Useful if you have the angle, but you don't.

You probably want:

F = G * m1 * m2 / r3 * r

where r = p2 - p1 and r = |r|

But then how do I get that into x and y?

##### Share on other sites
Quote:
Original post by NateTheGreat
Quote:
Original post by Julian90
Quote:
 Original post by OluseyiGiven a radius r and an angle θ:x = r cos θy = r sin θ

Useful if you have the angle, but you don't.

You probably want:

F = G * m1 * m2 / r3 * r

where r = p2 - p1 and r = |r|

But then how do I get that into x and y?

Quote:
 where r = p2 - p1

that is how. p2 and p1 have both x, and y components. breaking it up it goes like this

rX = pX2 - pX1
rY = pY2 - pY1

FX = G * m1 * m2 / r3 * rX
FY = G * m1 * m2 / r3 * rY

##### Share on other sites
Thanks everyone, I got it working now :)

##### Share on other sites
Where did you guys get a formula for Newtonian gravitation with r^3 terms in it?

The formulas are:

F = G*M*m/r^2;
a = F/m;

##### Share on other sites
Quote:
 Original post by tabyWhere did you guys get a formula for Newtonian gravitation with r^3 terms in it?The formulas are:F = G*M*m/r^2;a = F/m;

becuase it is also normalizing the unit vector r by making it ^3 rather than ^2

##### Share on other sites
Normalizing the unit vector is like melting water. It's already melted.

tau = t * sqrt(1 - Rs/r)
dtau/dr ~ Rs/(2r^2)
dtau/dr * c^2 ~ GM/r^2

...

A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)

Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

##### Share on other sites
Quote:
 Original post by tabyNormalizing the unit vector is like melting water. It's already melted.tau = t * sqrt(1 - Rs/r)dtau/dr ~ Rs/(2r^2)dtau/dr * c^2 ~ GM/r^2...A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

The point is there is no need for a unit vector in the 1 / r^3 form. It is very common actually to see it written like that and it's more efficient to compute:

A = 1/r^3 * ( r_sun - r_planet ) = 1 square root and 1 division.

A = 1/r^2 * normalize( r_sun - r_planet ) = 1 square root and 4 divisions.

##### Share on other sites
Quote:
Original post by My_Mind_Is_Going
Quote:
 Original post by tabyNormalizing the unit vector is like melting water. It's already melted.tau = t * sqrt(1 - Rs/r)dtau/dr ~ Rs/(2r^2)dtau/dr * c^2 ~ GM/r^2...A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

The point is there is no need for a unit vector in the 1 / r^3 form. It is very common actually to see it written like that and it's more efficient to compute:

A = 1/r^3 * ( r_sun - r_planet ) = 1 square root and 1 division.

A = 1/r^2 * normalize( r_sun - r_planet ) = 1 square root and 4 divisions.

I know enough about grade 5 arithmetic to get the point of what's going on there. :)

What I was saying is that it's nonsensical to those who are just learning gravitation, because they might get the impression that this is common. Perhaps my physics books are out of date, but I've never seen an introduction that works by intentially confusing the reader in order to avoid a SINGLE vector normalization operation.

The simplification of the Schwarzschild solution, as I've posted above, contains the proper r^2 form. Anyone now learning Newtonian gravitation using the r^3 method who later moves on to General Relativity will only be confused. GR is confusing enough, and only someone who does not appreciate the underlying calculus would go about adjusting the formulas that have existed in the proper form for 300 years!

##### Share on other sites
Quote:
Original post by taby
Quote:
Original post by My_Mind_Is_Going
Quote:
 Original post by tabyNormalizing the unit vector is like melting water. It's already melted.tau = t * sqrt(1 - Rs/r)dtau/dr ~ Rs/(2r^2)dtau/dr * c^2 ~ GM/r^2...A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

The point is there is no need for a unit vector in the 1 / r^3 form. It is very common actually to see it written like that and it's more efficient to compute:

A = 1/r^3 * ( r_sun - r_planet ) = 1 square root and 1 division.

A = 1/r^2 * normalize( r_sun - r_planet ) = 1 square root and 4 divisions.

I know enough about grade 5 arithmetic to get the point of what's going on there. :)

What I was saying is that it's nonsensical to those who are just learning gravitation, because they might get the impression that this is common. Perhaps my physics books are out of date, but I've never seen an introduction that works by intentially confusing the reader in order to avoid a SINGLE vector normalization operation.

The simplification of the Schwarzschild solution, as I've posted above, contains the proper r^2 form. Anyone now learning Newtonian gravitation using the r^3 method who later moves on to General Relativity will only be confused. GR is confusing enough, and only someone who does not appreciate the underlying calculus would go about adjusting the formulas that have existed in the proper form for 300 years!

No ones adjusting anything the scalar form is always written as r^2 and the vector form as r^3, theres nothing confusing about it and if someone can't understand it then perhaps they should learn some more maths before trying to do this stuff. As for this being a standard form, well I'm not the only one, this is the form that is used in all the text books I have. Anyone who even considers studying general relativity better have enough of a maths background that they wouldn't even give this a second thought, even if they'd only ever seen one form converting to the other should only take a few seconds of thought otherwise they're going to be confused by a lot more then just this. Seriously, don't you have something better to do then argue about this?

##### Share on other sites
Quote:
Original post by Julian90
Quote:
Original post by taby
Quote:
Original post by My_Mind_Is_Going
Quote:
 Original post by tabyNormalizing the unit vector is like melting water. It's already melted.tau = t * sqrt(1 - Rs/r)dtau/dr ~ Rs/(2r^2)dtau/dr * c^2 ~ GM/r^2...A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

The point is there is no need for a unit vector in the 1 / r^3 form. It is very common actually to see it written like that and it's more efficient to compute:

A = 1/r^3 * ( r_sun - r_planet ) = 1 square root and 1 division.

A = 1/r^2 * normalize( r_sun - r_planet ) = 1 square root and 4 divisions.

I know enough about grade 5 arithmetic to get the point of what's going on there. :)

What I was saying is that it's nonsensical to those who are just learning gravitation, because they might get the impression that this is common. Perhaps my physics books are out of date, but I've never seen an introduction that works by intentially confusing the reader in order to avoid a SINGLE vector normalization operation.

The simplification of the Schwarzschild solution, as I've posted above, contains the proper r^2 form. Anyone now learning Newtonian gravitation using the r^3 method who later moves on to General Relativity will only be confused. GR is confusing enough, and only someone who does not appreciate the underlying calculus would go about adjusting the formulas that have existed in the proper form for 300 years!

No ones adjusting anything the scalar form is always written as r^2 and the vector form as r^3, theres nothing confusing about it and if someone can't understand it then perhaps they should learn some more maths before trying to do this stuff. As for this being a standard form, well I'm not the only one, this is the form that is used in all the text books I have. Anyone who even considers studying general relativity better have enough of a maths background that they wouldn't even give this a second thought, even if they'd only ever seen one form converting to the other should only take a few seconds of thought otherwise they're going to be confused by a lot more then just this. Seriously, don't you have something better to do then argue about this?

I do have better things to do THAN this, yes, however I'm arguing from the standpoint that if you guys actually knew the calculus behind this, you would realize that this "vector" form is ridiculous. What's even more ridiculous is that the denominator in the equation you list on wikipedia is a scalar gathered from a vector. Well, so is the standard version, so this "vector" version is no more "vector" than the standard version. Then this "vector" version also multiplies the force by the unit vector. Well, so does the standard version. The only thing being done truly different in this "vector" version is screwing up the meaning behind the equation. It's not just random arithmetic, it's based on the actual calculus of the potential's gradient based on distance.

f = GMm/r^2
a = f/m
A = a * unit vector pointing from satellite to source

The whole point of Newtonian gravitation is that it's a scalar field. For the author of the "vector" version to imply that the "scalar" version does not account for magnitude and direction is ridiculous, and is only successful in pissing on Newton's grave.

[Edited by - taby on March 8, 2008 10:05:57 PM]

##### Share on other sites
Quote:
Original post by taby
Quote:
Original post by Julian90
Quote:
Original post by taby
Quote:
Original post by My_Mind_Is_Going
Quote:
 Original post by tabyNormalizing the unit vector is like melting water. It's already melted.tau = t * sqrt(1 - Rs/r)dtau/dr ~ Rs/(2r^2)dtau/dr * c^2 ~ GM/r^2...A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

The point is there is no need for a unit vector in the 1 / r^3 form. It is very common actually to see it written like that and it's more efficient to compute:

A = 1/r^3 * ( r_sun - r_planet ) = 1 square root and 1 division.

A = 1/r^2 * normalize( r_sun - r_planet ) = 1 square root and 4 divisions.

I know enough about grade 5 arithmetic to get the point of what's going on there. :)

What I was saying is that it's nonsensical to those who are just learning gravitation, because they might get the impression that this is common. Perhaps my physics books are out of date, but I've never seen an introduction that works by intentially confusing the reader in order to avoid a SINGLE vector normalization operation.

The simplification of the Schwarzschild solution, as I've posted above, contains the proper r^2 form. Anyone now learning Newtonian gravitation using the r^3 method who later moves on to General Relativity will only be confused. GR is confusing enough, and only someone who does not appreciate the underlying calculus would go about adjusting the formulas that have existed in the proper form for 300 years!

No ones adjusting anything the scalar form is always written as r^2 and the vector form as r^3, theres nothing confusing about it and if someone can't understand it then perhaps they should learn some more maths before trying to do this stuff. As for this being a standard form, well I'm not the only one, this is the form that is used in all the text books I have. Anyone who even considers studying general relativity better have enough of a maths background that they wouldn't even give this a second thought, even if they'd only ever seen one form converting to the other should only take a few seconds of thought otherwise they're going to be confused by a lot more then just this. Seriously, don't you have something better to do then argue about this?

I do have better things to do THAN this, yes, however I'm arguing from the standpoint that if you guys actually knew the calculus behind this, you would realize that this "vector" form is ridiculous. What's even more ridiculous is that the denominator in the equation you list on wikipedia is a scalar gathered from a vector. Well, so is the standard version, so this "vector" version is no more "vector" than the standard version. Then this "vector" version also multiplies the force by the unit vector in order to arrive at the final acceleration vector. Well, so does the standard version. The only thing being done in this "vector" version is screwing up the meaning behind the equation. It's not just random arithmetic, it's based on the actual calculus of the potential's gradient based on distance.

Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.... Massive Quote...

Of coarse the denominator is a scalar, division isn't defined for vectors, it's a vector form because the result force that it calculates is a vector, you know, like the scalar version calculates a scalar force (the magnitude of the vector version). The 'standard' version to which you keep referring is, I assume (since you insist it has a r2), the scalar version which is of coarse a scalar, F = G m1 m2 / r2.

Also, I only just noticed, but the version on wikipedia is actually wrong regardless, I didn't notice that they where multiplying by the unit vector rather then the actual vector which puts their equation out by a factor of 1/|r|.

Really there is no point to this, both are valid, both are mathematically equivalent, both forms are commonly used and both make just as much sense.

Quote:
 however I'm arguing from the standpoint that if you guys actually knew the calculus behind this

How about we refrain from insulting each others intelligence? I do know the maths behind this and I'm surprised that anyone who does would bother to argue about it since both of the equations are fine.

Edit:

Quote:
 f = GMm/r^2a = f/mA = a * unit vector pointing from satellite to sourceThe whole point of Newtonian gravitation is that it's a scalar field. For the author of the "vector" version to imply that the "scalar" version does not account for magnitude and direction is ridiculous, and is only successful in pissing on Newton's grave.

The scalar version accounts for the magnitude of the force, but not the direction, no one has implied anything different, obviously, it can also be treated as a vector field since the force must have a direction.

##### Share on other sites
Quote:
Original post by Julian90
Quote:
Original post by taby
Quote:
Original post by Julian90
Quote:
Original post by taby
Quote:
Original post by My_Mind_Is_Going
Quote:
 Original post by tabyNormalizing the unit vector is like melting water. It's already melted.tau = t * sqrt(1 - Rs/r)dtau/dr ~ Rs/(2r^2)dtau/dr * c^2 ~ GM/r^2...A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

The point is there is no need for a unit vector in the 1 / r^3 form. It is very common actually to see it written like that and it's more efficient to compute:

A = 1/r^3 * ( r_sun - r_planet ) = 1 square root and 1 division.

A = 1/r^2 * normalize( r_sun - r_planet ) = 1 square root and 4 divisions.

I know enough about grade 5 arithmetic to get the point of what's going on there. :)

What I was saying is that it's nonsensical to those who are just learning gravitation, because they might get the impression that this is common. Perhaps my physics books are out of date, but I've never seen an introduction that works by intentially confusing the reader in order to avoid a SINGLE vector normalization operation.

The simplification of the Schwarzschild solution, as I've posted above, contains the proper r^2 form. Anyone now learning Newtonian gravitation using the r^3 method who later moves on to General Relativity will only be confused. GR is confusing enough, and only someone who does not appreciate the underlying calculus would go about adjusting the formulas that have existed in the proper form for 300 years!

No ones adjusting anything the scalar form is always written as r^2 and the vector form as r^3, theres nothing confusing about it and if someone can't understand it then perhaps they should learn some more maths before trying to do this stuff. As for this being a standard form, well I'm not the only one, this is the form that is used in all the text books I have. Anyone who even considers studying general relativity better have enough of a maths background that they wouldn't even give this a second thought, even if they'd only ever seen one form converting to the other should only take a few seconds of thought otherwise they're going to be confused by a lot more then just this. Seriously, don't you have something better to do then argue about this?

I do have better things to do THAN this, yes, however I'm arguing from the standpoint that if you guys actually knew the calculus behind this, you would realize that this "vector" form is ridiculous. What's even more ridiculous is that the denominator in the equation you list on wikipedia is a scalar gathered from a vector. Well, so is the standard version, so this "vector" version is no more "vector" than the standard version. Then this "vector" version also multiplies the force by the unit vector in order to arrive at the final acceleration vector. Well, so does the standard version. The only thing being done in this "vector" version is screwing up the meaning behind the equation. It's not just random arithmetic, it's based on the actual calculus of the potential's gradient based on distance.

Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.... Massive Quote...

Of coarse the denominator is a scalar, division isn't defined for vectors, it's a vector form because the result force that it calculates is a vector, you know, like the scalar version calculates a scalar force (the magnitude of the vector version). The 'standard' version to which you keep referring is, I assume (since you insist it has a r2), the scalar version which is of coarse a scalar, F = G m1 m2 / r2.

Also, I only just noticed, but the version on wikipedia is actually wrong regardless, I didn't notice that they where multiplying by the unit vector rather then the actual vector which puts their equation out by a factor of 1/|r|.

Really there is no point to this, both are valid, both are mathematically equivalent, both forms are commonly used and both make just as much sense.

Quote:
 however I'm arguing from the standpoint that if you guys actually knew the calculus behind this

How about we refrain from insulting each others intelligence? I do know the maths behind this and I'm surprised that anyone who does would bother to argue about it since both of the equations are fine.

Right, except for where they make look like an inverse-cube law in order to skip a division operation...

##### Share on other sites
Quote:
Original post by taby
Quote:
Original post by Julian90
Quote:
Original post by taby
Quote:
Original post by Julian90
Quote:
Original post by taby
Quote:
Original post by My_Mind_Is_Going
Quote:
 Original post by tabyNormalizing the unit vector is like melting water. It's already melted.tau = t * sqrt(1 - Rs/r)dtau/dr ~ Rs/(2r^2)dtau/dr * c^2 ~ GM/r^2...A = GM/r^2 * normalize(Planet.Pos - Sun.Pos)Nowhere should an r^3 term come into play here, unless one wishes to confuse the reader.

The point is there is no need for a unit vector in the 1 / r^3 form. It is very common actually to see it written like that and it's more efficient to compute:

A = 1/r^3 * ( r_sun - r_planet ) = 1 square root and 1 division.

A = 1/r^2 * normalize( r_sun - r_planet ) = 1 square root and 4 divisions.

I know enough about grade 5 arithmetic to get the point of what's going on there. :)

What I was saying is that it's nonsensical to those who are just learning gravitation, because they might get the impression that this is common. Perhaps my physics books are out of date, but I've never seen an introduction that works by intentially confusing the reader in order to avoid a SINGLE vector normalization operation.

The simplification of the Schwarzschild solution, as I've posted above, contains the proper r^2 form. Anyone now learning Newtonian gravitation using the r^3 method who later moves on to General Relativity will only be confused. GR is confusing enough, and only someone who does not appreciate the underlying calculus would go about adjusting the formulas that have existed in the proper form for 300 years!

No ones adjusting anything the scalar form is always written as r^2 and the vector form as r^3, theres nothing confusing about it and if someone can't understand it then perhaps they should learn some more maths before trying to do this stuff. As for this being a standard form, well I'm not the only one, this is the form that is used in all the text books I have. Anyone who even considers studying general relativity better have enough of a maths background that they wouldn't even give this a second thought, even if they'd only ever seen one form converting to the other should only take a few seconds of thought otherwise they're going to be confused by a lot more then just this. Seriously, don't you have something better to do then argue about this?

I do have better things to do THAN this, yes, however I'm arguing from the standpoint that if you guys actually knew the calculus behind this, you would realize that this "vector" form is ridiculous. What's even more ridiculous is that the denominator in the equation you list on wikipedia is a scalar gathered from a vector. Well, so is the standard version, so this "vector" version is no more "vector" than the standard version. Then this "vector" version also multiplies the force by the unit vector in order to arrive at the final acceleration vector. Well, so does the standard version. The only thing being done in this "vector" version is screwing up the meaning behind the equation. It's not just random arithmetic, it's based on the actual calculus of the potential's gradient based on distance.

Weeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee.... Massive Quote...

Of coarse the denominator is a scalar, division isn't defined for vectors, it's a vector form because the result force that it calculates is a vector, you know, like the scalar version calculates a scalar force (the magnitude of the vector version). The 'standard' version to which you keep referring is, I assume (since you insist it has a r2), the scalar version which is of coarse a scalar, F = G m1 m2 / r2.

Also, I only just noticed, but the version on wikipedia is actually wrong regardless, I didn't notice that they where multiplying by the unit vector rather then the actual vector which puts their equation out by a factor of 1/|r|.

Really there is no point to this, both are valid, both are mathematically equivalent, both forms are commonly used and both make just as much sense.

Quote:
 however I'm arguing from the standpoint that if you guys actually knew the calculus behind this

How about we refrain from insulting each others intelligence? I do know the maths behind this and I'm surprised that anyone who does would bother to argue about it since both of the equations are fine.

Right, except for where they make look like an inverse-cube law in order to skip a division operation...

No one makes it look like anything in order to skip anything, taking out ht factor of 1/|r| is IMO a logical operation, it doesn't make it 'look like' anything, its still the same equation.

##### Share on other sites

Seriously.. the presumption is that the reader knows a bit of algebra..

If you don't know algebra then you certainly arent rationally trying to tackle integration and calculus. Its a prerequisit to understanding.

This isnt a code hand-out forum, right?

##### Share on other sites

Equation a = k*M/r^3 is frequently used in astronomy. There is nothing wrong with it, look at Wolfram pages, he mentions it as well.

Actually it could be also writen in form k/(va DOT va)^(3/2), or in the form
v = v12*k/d^3
a1o = a12 + Mass1 * v
a2o = a21 - Mass2 * v //Apply from smallest Mass*v to largest

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627726
• Total Posts
2978815

• 10
• 9
• 21
• 14
• 12