# Tracking a point on an object during rotation

I've been trying to solve for this a while now. What I am trying to do is to find the coordinates of a point on an object while it rotates. After digging around I have found the following equation which in it's basic form is what I want

x = x*cos(θ) - y*sin(θ)
y = x*sin(θ) + y*cos(θ)


With the screenshots below I've attached a white dot to the point I'm currently tracking which is really just the X Y of the red rectangle. As you can see assuming the middle screenshot is my starting point I want to have the white square be in the same spot regardless of rotation. Right now (because rotation isnt being taken into account) the white dot movies around on the rectangle as it rotates.

I know I need to take rotation into account but I'm not sure how to go about calculating it. This red rectangle moves about another object that is attached to a flexible joint so the coordinates of rotation aren't something particularly easy to come by. The rotation point of the red rectangle is center top, however.

Can anyone guide me in the right direction?

-
I think you'll need to tell us more about what you're currently doing to obtain these dots and rectangles, and how you'd want them to behave instead. –  joriki Oct 25 '11 at 3:19
I guess that's the paradox of using a physics engine. 99% of the work is done for you until you need to do something specific. The engine handles attaching objects in space via joints and other mechanics, and exposes coordinates, rotation angles etc.. So I have access to the coordinate of the rectangle and its rotation. –  methodin Oct 25 '11 at 3:58

If this is all in 2D, you have the coordinates of a point on the object, and want the coordinates of another point on the object, you can call the position of the known point $(x_0,y_0)$ and the offset from the known point to your dot $(x_1,y_1)$ when the rotation is $0$. Then at any time your dot is at $(x_0+x_1 \cos \theta -y_1 \sin \theta,y_0+y_1 \cos \theta +x_1 \sin \theta)$, which is just applying your equations to the known point.
If this is 3D the same basic idea applies, but you need three coordinates and two angles to specify the position of your dot. If we measure the angles from when the dot is above the fixed point by distance $r$, the position is $(x_0+r\cos \phi \sin \theta,y_0+r\sin \phi \sin \theta,z_0+r\cos \theta)$ where $\theta$ is a rotation around $y$ and $\phi$ is a subsequent rotation around $z$