Rotating about a point?

416 Views Asked by At

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?

1

There are 1 best solutions below

2
On BEST ANSWER

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).