Skip to main content
GameDev.net gamedev.net
🔒 Locked

Rotating around a point (2d)

Started by leggyguy Sep 13, 2006 at 1:14 PM 4 replies 2.2k views
Original Post
leggyguy
leggyguy
Hi. I have searched the forums, and found all sorts of help on rotating around a point, but I think I have confused myself. I have a point A at (2.0f, 0.0f, 3.0f) and point B at (3.5f, 3.0f, 3.0f). Notice that the z is the same, and will always stay the same. I want to find the point if I rotated B around A by x degrees, so that it is the same distance from A as it was before, but x degrees clockwise. Now, I know this is easy for some of you guys, but I have foxed myself by looking at all the 3d implementations, and I want need something simpler (I think) as the Z will always be the same. If anyone could provide a real quick snipet that helps I would appreciate the help. I know this is something I learnt at school, but damn if it isn't a long time since I was at school :)
Zakwayda
Zakwayda
1. Translate the point you wish to rotate by the negative of the point you wish to rotate about
2. Apply the rotation
3. Translate back

I'm sort of glossing over the point/vector distinction here, but the idea should be clear. Anyway, you'll need the 2D rotation formula, which you should be able to find online by googling for '2D rotation', 'vector rotation', or 'point rotation'. Then, just apply the above steps.

I can't be much more specific since I don't know much about the context (API, notation conventions, and so on), but post back if you need more details.
leggyguy
leggyguy
I am using C++ and opengl.

I'll try googling again.

I did find this:

x' = cos(theta)* x - sin(theta)*y;
y' = sin(theta)* x + cos(theta)*y;

Now when I use that, the line I am drawing is not where it is supposed to be. I am guessing then that that formula uses radians rather than degrees.

[Edited by - leggyguy on September 13, 2006 2:25:40 PM]
Zakwayda
Zakwayda
Quote:
Original post by leggyguy
I am using C++ and opengl.

I'll try googling again.

I did find this:

x' = cos(theta)* x - sin(theta)*y;
y' = sin(theta)* x + cos(theta)*y;

Now when I use that, the line I am drawing is not where it is supposed to be. I am guessing then that that formula uses radians rather than degrees.
Well, C/C++ math functions use radians, and OpenGL functions use degrees, so you do need to convert where appropriate. The above equation is what you're looking for though.

I you want to do it through OpenGL instead it's just a matter of calling the appropriate GL transform functions in the right order. If you're not getting the results you're expecting, you might post your code so we can take a look at it (use the [ source ] tag to preserve formatting).
leggyguy
leggyguy
Scratcg this post, I didn;t describe the problem well. Basically my rotation isn;t working how I expect it to.

[Edited by - leggyguy on September 13, 2006 3:51:15 PM]
leggyguy
leggyguy
Bah I solved it, I was updating variables then using them again as though they were unchanged.

Sorry to waste time :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.