Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is part of a program. I am trying to take an image at a given pair of coordinates and move it in a circular path around another given pair of coordinates.

The program is structured so that the image is redrawn 30 times per second, and with each redraw I need to update its position. That is to say, with each redraw I need to take its current coordinates [x,y], and update them to the next position along the circular path relative to the given center point. So I've been trying to determine the equation which would be a function of the present coordinates and the center coordinates and I haven't been able to do it no matter what.

Can someone help me out here? I also realize this should be a function of degrees. Say I move a fixed 5 degrees with each redraw. How do I calculate the new coordinates, relative to a given center?

share|cite|improve this question
P.S. If you're feeling charitable PLEASE do not give me a matrix answer; from experience I've learned I'm terrible at converting matrix math to code. – Aerovistae Jun 9 '12 at 19:35
up vote 3 down vote accepted

make a degree variable that holds the value of $\theta$. Every step do $\theta+=5\frac{\pi}{180}$ (to convert from degrees to radians). Then the coordinates of your picture are $$x=x_{center}+radius*\cos(\theta)$$ $$y=y_{center}-radius*\sin(\theta)$$

**minus on the $y$ because computer coordinate systems have $y$ increase downards, and this will produce clockwise rotation with increasing $\theta$ (i.e, angles work in the standard way).

share|cite|improve this answer
Okay, so I'd never gone graphical work before (first game), and it took me a solid twenty minutes of messing up the other day before I realized y increased downwards. And here I thought it was just the Allegro library. This is a common thing? WHY? – Aerovistae Jun 9 '12 at 19:42
It's the order in which the computer draws pixels. Remember, early computers were text based, and drew things in the order text was written: left to right, top to bottom. There wasn't really a point in introducing different conventions for different displays, so that carried over to graphical displays. While it's common enough that you'll have to get used to it (it doesn't take that long, promise), if you want you can use OpenGL to redefine the coordinate system however you like. – Robert Mastragostino Jun 9 '12 at 19:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.