So I have this problem: if you have an object ("Planet") and a smaller object ("Moon") floating in the vacuum of space, how can you determine the velocity the moon must have to stay in (circular) orbit? (I will assume the moon will have no gravitational effect on the planet.)
My first guess was it needed to be the same as the gravity on the moon. I quickly saw that was horribly wrong. After that, I stopped thinking about it.
I'll call the gravity Fz and the initial velocity Fs. (For clarity: In this post and in my code, I use speed, velocity and force as synonyms ("move x pixels per step"). I know they are not, but for this purpose it doesn't matter.)
Here a crude drawing of what I mean.
Later, when I revisited the matter, I actually made a formula to calculate the needed velocity (the direction is simply the direction of Fz + 90 degrees, or - 90 degrees, depending on the direction you want the moon to go.).
Here be math:
l = d(moon, planet)
k = l - Fz
Fs = l * cos(sin-1(k / l))
Here Fs is the horizontal translation that goes with vertical translation Fz of point moon, so that moon' stays on the circle with center planet and radius d(planet, moon).
This image demonstrates it: (alpha = sin-1(k / l)
The problem seems to be my implementation and not the math. It works, except for the fact that the initial speed/velocity is way too much. Whatever I try, it keeps shooting out of reach of the planet.
Here it is:
Could someone please help me, and tell me whether my implementation is all wrong, or my math sucks?
Geometry/physics problem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Geometry/physics problem
Help us help you: attach a .love.
-
- Party member
- Posts: 215
- Joined: Sun Jan 18, 2009 8:03 pm
Re: Geometry/physics problem
Anything less than the escape velocity will keep the moon orbit earth, although it might not be a circle. To get a circle, see http://en.wikipedia.org/wiki/Kepler_problem.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
Re: Geometry/physics problem
One more suggestion: http://en.wikipedia.org/wiki/Escape_velocity
try
I'm not sure why its 87 not 100 though :/
87 was found using Newton's interval halving method.
EDIT: I set initial velocity to zero for the moon. I tested it and the moon was pulled to earth, accelerating as it approached then suddenly stopped in the earth's centre instead of going through it. Unless theres some weird collision thing that shouldn't happen. :/
try
Code: Select all
MoonDX = -ForceConstant*MoonSize*PlanetSize/87
--s*math.cos(a) -- (-G * mass1 * mass 2 )/ distance
MoonDY = 0--s*math.sin(a)
87 was found using Newton's interval halving method.
EDIT: I set initial velocity to zero for the moon. I tested it and the moon was pulled to earth, accelerating as it approached then suddenly stopped in the earth's centre instead of going through it. Unless theres some weird collision thing that shouldn't happen. :/
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Geometry/physics problem
osuf oboys wrote:Anything less than the escape velocity will keep the moon orbit earth, although it might not be a circle. To get a circle, see http://en.wikipedia.org/wiki/Kepler_problem.
Thanks for the suggestions! I've tried your code, appleide, and it works. I generalized the function a bit, so it works if the moon starts off somewhere else. The 87 seems to be specific for a distance of 100: I changed "-ForceConstant*MoonSize*PlanetSize/87" to "-ForceConstant*MoonSize*PlanetSize/(dist*.87)". Maybe it's a quadratic function of dist, instead of a linear one? Anyway, I'll have a look at the Wikipedia articles.appleide wrote:tryI'm not sure why its 87 not 100 though :/Code: Select all
MoonDX = -ForceConstant*MoonSize*PlanetSize/87 --s*math.cos(a) -- (-G * mass1 * mass 2 )/ distance MoonDY = 0--s*math.sin(a)
87 was found using Newton's interval halving method.
I thought that would happen. I used a naive calcforce() function:appleide wrote:I set initial velocity to zero for the moon. I tested it and the moon was pulled to earth, accelerating as it approached then suddenly stopped in the earth's centre instead of going through it. Unless theres some weird collision thing that shouldn't happen. :/
Code: Select all
dist = math.sqrt(xdist*xdist + ydist*ydist)
return ForceConstant * (PlanetSize * MoonSize) / (dist*dist)
And for completeness: a second try, with the generalized version of appleide's code, and some collision checking (the moon just stops at the surface of the planet).
Help us help you: attach a .love.
Re: Geometry/physics problem
For distance 122, the value is around 96... which isn't 0.87*122... The value for distance 50 is 61 ... :/ If your value isn't perfect than your orbit would be elliptical; The dist will change as it orbits.
so Here's our table of data
50:62
100:87
122:96
I plotted them on a graph and I got a straight line!
so the equation would be of the form:
y=cx+k
y is the value, x is the radius, c and k are constants.
I subbed in the values.... The equation is approximately...
y=0.5x+37.
Corresponding code:
This will give a more circular orbit. I haven't got a clue about the equation.
so Here's our table of data
50:62
100:87
122:96
I plotted them on a graph and I got a straight line!
so the equation would be of the form:
y=cx+k
y is the value, x is the radius, c and k are constants.
I subbed in the values.... The equation is approximately...
y=0.5x+37.
Corresponding code:
Code: Select all
function calcspeed()
local force = calcforce()
--local distleft = dist - force
return -ForceConstant*MoonSize*PlanetSize/(0.5*dist+37) --dist*math.cos(math.asin(distleft/dist))
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Geometry/physics problem
Thanks for the calculations. I tested it, and it's very close to circular orbit. Too bad we still don't know *why* that is. Now I really want to find out. Unfortunately, I have to study. In fact, by writing this post I am wasting time better spent on studying
Help us help you: attach a .love.
Who is online
Users browsing this forum: No registered users and 3 guests