*
The moose likes Java in General and the fly likes How to calculate how many X/Y pixels to move object around a circle? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to calculate how many X/Y pixels to move object around a circle?" Watch "How to calculate how many X/Y pixels to move object around a circle?" New topic
Author

How to calculate how many X/Y pixels to move object around a circle?

Max Simpson
Ranch Hand

Joined: Sep 23, 2004
Posts: 30
Hi,
When a user presses left or right, I would like to have an object move left or right around a circle (not rotating, but actually following the path of a circle). I need to figure out how many pixels on the X and Y axis to move on each step to move around a circle. Is their an easy way to calculate this? The radius of the circle is 50 pixels.
Thanks!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
One way would be to keep track of the angle that defines where the user is along the circle. From this angle and the radius of the circle, you can use some trigonometry and algebra to figure out the (x, y) coordinates.

HTH

Layne


Java API Documentation
The Java Tutorial
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I did something in Pascal once to rotate an entire line drawing picture. To calculate the new position for each pixel I converted x,y coordinates to polar, added or subtracted some degrees, and converted back. There were some tricky cases for negatives as I recall. (I was a music major but my dad taught college math for 32 years and got me through some of it.) If you don't want to rotate your image you could use the same technique just to compute a new position for one corner of the image.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
 
subject: How to calculate how many X/Y pixels to move object around a circle?
 
Similar Threads
Circular motion.......
Random Direction Change of Object
A probability problem
Non-static variable cannot be referenced from static context
Help in Algorithm Construction