Geometry/physics problem

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Geometry/physics problem

Post by Robin »

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.
Image

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)
Image
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:
planet_test.love
Version 0 -- is not working
(1.02 KiB) Downloaded 143 times
Could someone please help me, and tell me whether my implementation is all wrong, or my math sucks?
Help us help you: attach a .love.
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

Re: Geometry/physics problem

Post by osuf oboys »

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.
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: Geometry/physics problem

Post by appleide »

One more suggestion: http://en.wikipedia.org/wiki/Escape_velocity

try

Code: Select all

MoonDX = -ForceConstant*MoonSize*PlanetSize/87 
--s*math.cos(a) -- (-G * mass1 * mass 2 )/ distance
MoonDY = 0--s*math.sin(a)
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. :/
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Geometry/physics problem

Post by Robin »

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.
appleide wrote:try

Code: Select all

MoonDX = -ForceConstant*MoonSize*PlanetSize/87 
--s*math.cos(a) -- (-G * mass1 * mass 2 )/ distance
MoonDY = 0--s*math.sin(a)
I'm not sure why its 87 not 100 though :/
87 was found using Newton's interval halving method. ;)
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: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. :/
I thought that would happen. I used a naive calcforce() function:

Code: Select all

dist = math.sqrt(xdist*xdist + ydist*ydist)
return ForceConstant * (PlanetSize * MoonSize) / (dist*dist)
This means if xdist == 0 and ydist == 0, the "/ (dist*dist)" part will generate an error, which propagates upward, and cuts off the update() function, so moon no longer moves.

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).
planet_test2.love
Now with enhanced recipe!
(1.06 KiB) Downloaded 124 times
Help us help you: attach a .love.
User avatar
appleide
Party member
Posts: 323
Joined: Fri Jun 27, 2008 2:50 pm

Re: Geometry/physics problem

Post by appleide »

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:

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
This will give a more circular orbit. I haven't got a clue about the equation.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Geometry/physics problem

Post by Robin »

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.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests