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

Username:   Password: 
 RegisterRegister   
 Turing Make an object move in a circular motion
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Satisfaction




PostPosted: Fri May 09, 2008 8:17 pm   Post subject: Turing Make an object move in a circular motion

I'm trying to make a solar system but im having trouble making the planets move in a circular motion... Please someone help me...
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Fri May 09, 2008 8:23 pm   Post subject: RE:Turing Make an object move in a circular motion

Well, do you know the universal gravitation and forces equation equations?
Satisfaction




PostPosted: Fri May 09, 2008 8:42 pm   Post subject: RE:Turing Make an object move in a circular motion

Sadly no
CodeMonkey2000




PostPosted: Fri May 09, 2008 8:49 pm   Post subject: Re: Turing Make an object move in a circular motion

This is the universal gravitation equation: Posted Image, might have been reduced in size. Click Image to view fullscreen. . Where G is the gravitational constant, I don't know the value by heart, but you can google it. This equation gives you the gravitational force between to bodies of mass. This isn't particularly useful, what you want is the gravitational field acting on your planet (acceleration). Remember F=ma, so to to get a we can just dive F by m. If we do this in the universal gravitation equation we get the formula: Posted Image, might have been reduced in size. Click Image to view fullscreen.. Now r is the distance between the two bodies of masses, you can figure this out using the distance equation or just math.distance. But wait! This is scalar and acceleration is a vector. You can figure out the the angle between the two masses with some trig. Now you should have the x and y components of the velocity of the planets. The x and y components of the velocity will increase by the x and y component of the acceleration (again you can figure this out using trig). And finally the x and y components of the position will be incremented by the x and y components of velocity. Essentially acceleration is the hardest part. Once you have acceleration down you do something like this:
code:

figure out acceleration using trig and universal gravitation and forces equations
break the acceleration in to x and y components using trig

velocityX+=accelerationX
positionX+=velocityX
velocityY+=accelerationY
positionY+=velocityY


It's pretty complicated but it can be done. Before you start coding you should sit down and think about how you will implement this. I made this in VB last semester, you can check out the code at there but I doubt that you'll find it useful.

Here is the link to the one I did in VB.
Satisfaction




PostPosted: Fri May 09, 2008 10:52 pm   Post subject: RE:Turing Make an object move in a circular motion

Can this help me with making a oval/circle move in circular motion? o.o It's so complex..
CodeMonkey2000




PostPosted: Sat May 10, 2008 1:37 am   Post subject: RE:Turing Make an object move in a circular motion

If you want constant circular motion, it's a lot more simple. The basic formula is y=r* sind (angle)+yOfWhatYouAreOrbiting and x= r* cosd(angle)+ xOfWhatYouAreOrbiting, r is the constant radius. To move the object, just increase the angle. Elliptical motion is a bit different though, you'll need to play around with the circular motion a bit. Although this isn't really planetary motion.
isaiahk9




PostPosted: Sat May 10, 2008 7:07 am   Post subject: RE:Turing Make an object move in a circular motion

CAn you not use Pic.Rotate, and have your picture have a bit of a axel farther out, like this :

o X

o is your axel, and x is your picture. If you rotate that, it will appear that x is moving in a circle.
[Gandalf]




PostPosted: Sat May 10, 2008 3:07 pm   Post subject: RE:Turing Make an object move in a circular motion

You could, but you'll be limited to that exact circular motion unless you change the original image. Also, you'll need an increasingly large image the larger you want your radius to be. With something a little more complicated, as CodeMonkey2000 describes, you get a faster and more flexible program.
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Sat May 10, 2008 8:06 pm   Post subject: RE:Turing Make an object move in a circular motion

Plus isaiahk9's method will be much slower, since you keep generating and freeing images for each cycle. Pic.Rotate actually allocates memory for the newly generated rotation.
Satisfaction




PostPosted: Sat May 10, 2008 8:07 pm   Post subject: RE:Turing Make an object move in a circular motion

Any of you guys wanna help me do that? I'm so confused lol. I just want to make a solar system using pictures and make it move for my assumptive o.o
isaiahk9




PostPosted: Sat May 10, 2008 8:11 pm   Post subject: RE:Turing Make an object move in a circular motion

About memory for each picture, Codemonkey2000, wouldn't Pic.Free fix that. And wouldn't setscreen("offscreenonly") and View.Update make it just as fast?

To Satisfaction, if CodeMonkey2000 says that my way is less effective, I wouldn't doubt him. It would probably be best for him to explain his way. I've always used Pic.Rotate in the past through. lol
Tony




PostPosted: Sat May 10, 2008 9:16 pm   Post subject: RE:Turing Make an object move in a circular motion

@isaiahk9 -- There's certainly something wrong if saving current screen as an image, editing that image, saving it as a new instance in the memory, and loading that image onto screen... if all that takes about the same time as adding two vectors (velocity + acceleration) to a 2D position.

The only thing Pic.Free does is that it prevents your program from running out of picture identifiers and crashing runtime.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
CodeMonkey2000




PostPosted: Sat May 10, 2008 9:39 pm   Post subject: Re: Turing Make an object move in a circular motion

Well, Satisfaction doesn't seem to have the physics background for this, so I'm going explain basic circular motion. With circular motion you have a the object that is moving, and a focal point at the center. Now the distance from the focal point to the object is always constant, that's why we call it a radius. Now we can express the coordinates of the object as x and y, or we can express it using trig (I hope you know trigonometry... ). Consider this figure.

Posted Image, might have been reduced in size. Click Image to view fullscreen.


Px and Py is known, and stays constant. That's the point we orbit around. x and y is the coordinate of our object, or planet. To get x and y we need to add a to Px to get x and add b to Py to get y. r is constant, that's the radius. To get a we do r*cosd theta and to get b we do r*sind theta. Theta will vary from 0 to 360 degrees. Using this we see that
code:

   x=Px+r*cosd theta
   y=Py+r*sind theta


Now we just vary theta and keep calculating the new coordinate (then drawing it of course).
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  [ 13 Posts ]
Jump to:   


Style:  
Search: