
-----------------------------------
bass_maniac
Mon Nov 15, 2004 5:24 pm

Finding the Moon's position in orbit
-----------------------------------
I'm trying to make a program in which the Earth (a circle) is at the center of the screen. It has a radius of 25. I want to have the moon orbit the Earth at a distance of 100 pixels from the center of the Earth in a counter-clockwise direction. 

If the initial values are:
earthX := maxx div 2
earthY := maxy div 2
moonX := earthX + 100
moonY := earthY

How do I calculate the next position of the moon?

-----------------------------------
Tony
Mon Nov 15, 2004 6:26 pm


-----------------------------------
use an equation of the circle

x**2 + y**2 = r**2


btw, Earth is not at the center of the world, make it orbit the sun :wink:

-----------------------------------
Mazer
Mon Nov 15, 2004 6:40 pm


-----------------------------------
btw, Earth is not at the center of the world, make it orbit the sun :wink:
The Earth isn't at the center of the world? Damn. But why would you want the moon to orbit the Sun?

From my understanding, you just want to use trig, right? So that for whatever angle you have, the moon's x is equal to 100 * the cosine of the angle. Same goes for the y coord, just replacing cosine with sine. (Don't forget to add half the screen width and height to the coordinates)

-----------------------------------
bass_maniac
Mon Nov 15, 2004 7:00 pm


-----------------------------------
Thank you Coutsos. Just for interest's sake, here's what I've come up with so far,

View.Set ("graphics:max;max,offscreenonly")
var earthX := maxx div 2
var earthY := maxy div 2
var moonX : real := earthX + 100
var moonY : real := earthY
var angle := 0.0

loop
    drawfilloval (earthX, earthY, 25, 25, 7)
    drawfilloval (round (moonX), round (moonY), 3, 3, 7)
    moonX := 100 * (cos (angle)) + (maxx div 2)
    moonY := 100 * (sin (angle)) + (maxy div 2)
    angle += .05
    delay (30)
    View.Update
    cls
end loop

