•      Sign In
• Create Account

Rotate point around vector

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

13 replies to this topic

#1Alessandro  Members   -  Reputation: 284

Like
0Likes
Like

Posted 10 April 2012 - 11:46 AM

I hope I can explain what I need to do, I also attach this image, which should be helpful:

I have a point A (with coordinates A.x, A.y, A.z) and a point B (B.x, B.y, B.z).

I'd like to rotate point B around the local X axis (1,0,0) of point A.

Is this clear enough?

Thanks again for any kind of support!

EDIT: just posted a better image, the previous was a bit cryptic...

Sponsor:

#2Álvaro  Members   -  Reputation: 6185

Like
1Likes
Like

Posted 10 April 2012 - 12:12 PM

If we knew how to rotate around the origin, we could solve your problem like this:

B'' = A + rotate_around_origin(B' - A)

So I'll just concentrate on rotating a point P around the origin, giving P' as result.

Now, how would we go about rotating around the X axis? Well, this is particularly simple because we'll just leave the x coordinate alone and do a 2D rotation on coordinates y and z

P'.x = P.x
P'.y = cos(alpha)*P.y - sin(alpha)*P.z
P'.z = sin(alpha)*P.y + cos(alpha)*P.z

If you want to rotate around a general axis, it gets trickier. You can do it using quaternions, which are not easy to understand but worth the trouble. Here's some code you can use.

#3Alessandro  Members   -  Reputation: 284

Like
0Likes
Like

Posted 10 April 2012 - 03:24 PM

Thank you very much Alvaro, that link you posted, about another thread where you helped with a similar problem, it's very interesting.

#4Alessandro  Members   -  Reputation: 284

Like
0Likes
Like

Posted 10 April 2012 - 04:32 PM

I tried the quaternion solution posted by Alvaro, related to point rotation around vector and it works (tried some debug values).

However, if you take a look at the attached picture (it's updated), I need to rotate point B around the X local axis of point A (or general axis, as Alvaro calls it).

What I tried to do, is to Normalize vector A, and calculate the cross product of such normalized vector with (0,1,0). That way, I get the perpendicular vector to those; however this vector is normalized, and a rotation of point B around it will be done relative to origin (0,0,0), and not point A.
So how'd I account for that?

#5Álvaro  Members   -  Reputation: 6185

Like
0Likes
Like

Posted 10 April 2012 - 04:46 PM

Read the first two lines of my original response.

EDIT: Wait, what do you mean by "the X local axis of point A"? In your diagram, that doesn't seem to be parallel to the x axis...

#6Alessandro  Members   -  Reputation: 284

Like
0Likes
Like

Posted 10 April 2012 - 05:25 PM

Sorry for the mess: I made a new image that should explain better.

Say you have a line in 3D space made of 4 points, ABCD. You want to rotate it so that A is the origin, and more precisely you want to rotate it around the local X axis of point A (the one represented as a yellow line). And finally get A'B'C'D'.

I included both a perspective and a top view that should show better how points are disposed in 3D space...

#7Álvaro  Members   -  Reputation: 6185

Like
0Likes
Like

Posted 10 April 2012 - 07:27 PM

You are still not explaining what "the local X axis of point A" means. I asked for clarification and you simply used the exact same expression again.

#8Alessandro  Members   -  Reputation: 284

Like
0Likes
Like

Posted 11 April 2012 - 01:46 AM

You're right, sorry. The "local X axis of point A", represented by the yellow line in the above picture, is a vector perpendicular to AB and 0,1,0 (so the cross product of those two vector). It's the axis that I'd like to use to rotate point B,C,D around.
I hope this is more clear...

#9Álvaro  Members   -  Reputation: 6185

Like
0Likes
Like

Posted 11 April 2012 - 02:22 AM

I already gave you your answer...

#10Alessandro  Members   -  Reputation: 284

Like
0Likes
Like

Posted 11 April 2012 - 05:39 AM

True, the quaternion solution used to define a rotation worked perfectly.
The problem subsequent to that, and that I couldn't quite explain was how to position back the rotated point (since the rotation was performed around a normalized vector). A simple vector sum did it.
Thanks for your help Alvaro.

#11taby  Members   -  Reputation: 285

Like
0Likes
Like

Posted 11 April 2012 - 12:39 PM

MY DEAR SWEET GOD, SOMEONE ON GAMEDEV.NET THANKED SOMEONE FOR HELPING THEM. ;)

#12Alessandro  Members   -  Reputation: 284

Like
0Likes
Like

Posted 11 April 2012 - 04:48 PM

It's the least I can do to thank another person which has been so kind and helpful.

#13Álvaro  Members   -  Reputation: 6185

Like
1Likes
Like

Posted 11 April 2012 - 05:23 PM

I don't know what Taby's experience has been on this website, but people thank me all the time around here. Indicating posts as useful is another way of thanking, and that happens a lot too.

#14taby  Members   -  Reputation: 285

Like
0Likes
Like

Posted 11 April 2012 - 07:12 PM

I WAS TEASING. ;) It's a long story, and where's Owl?

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS