Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Finding the Moon's position in orbit
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
bass_maniac




PostPosted: Mon Nov 15, 2004 5:24 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Mon Nov 15, 2004 6:26 pm   Post subject: (No subject)

use an equation of the circle
code:

x**2 + y**2 = r**2


btw, Earth is not at the center of the world, make it orbit the sun Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Mazer




PostPosted: Mon Nov 15, 2004 6:40 pm   Post subject: (No subject)

tony wrote:
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




PostPosted: Mon Nov 15, 2004 7:00 pm   Post subject: (No subject)

Thank you Coutsos. Just for interest's sake, here's what I've come up with so far,

code:
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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: