Advertisement

Rotate point around vector

Started by November 01, 2002 09:01 PM
10 comments, last by shrooboo 22 years, 3 months ago
I have a 3d point and a vector that I want to rotate the point around. Is there a vector equation to accomplish this?
Off the top of my head I would say...

Two words: Vector Addition

Add a magnitude that is at the angle you want to achive and equal in magnitude to the existing vector.

[Edit}
Opps... Looking back on this post I forgot something, that you would have to bring back the vector to its original magnitude. Easy enough to figure out, but I can just see someone trying this and not seeing why they get an odd result.
[/Edit]

[edited by - thewayout_is_through on November 1, 2002 10:20:50 PM]
"Who are you, and how did you get in here?""I''m the locksmith, and I''m the locksmith."
Advertisement
But how do I get a vector in the angle of the rotation?
the order of rotation matters. however, there are ways around it.

people will tell you to use quarternions, but if you cant understand them, there is a solution.

when dt is small the order of rotation doesnt matter!

what I do at the moment is devide the timestep by 128.

Then you can rotate by that tinydt 128 times and the rotation will be accurate.

---

this method can be improved about by using rotation matrices. see this code for inspiration.

/possible speedup: quarternions?
ident=matrix::RotateMatrix(ident,rot.x,rot.y,rot.z); //1 A
ident=matrix::AmultB(ident,ident); //A^2=AA //2
ident=matrix::AmultB(ident,ident); //A^4=A^2A^2 //4
ident=matrix::AmultB(ident,ident); //A^8=A^4A^4 //16
ident=matrix::AmultB(ident,ident); //A^16=A^8A^8 //256

ident=matrix::AmultB(ident,ident); //A^32=A^16A16
ident=matrix::AmultB(ident,ident); //A^64=A^32A32
ident=matrix::AmultB(ident,ident); //A^128=A^64A64 //this represents a rotation 128
//times larger than that which occured
//over time dt/128
//An accurate alternative to quaternions.




----------------------------
http://www.digitalsentience.pwp.blueyonder.co.uk
Well, thanks for trying guys, but I must be an idiot, because Im lost.
Alright, time for the visual aid.



Excuse the 2D nature, but I generally work in 2D more than 3D. The white line represents our existing vector, the red is the vector we add and green is the resulting vector. The magnitude of white matches red and the angle of red to white is twice the end result. However, the resulting magnitude of green must be reduced to that of our original vector white.

edit by ze: Hm. Fixed image, I think.

[edited by - zealouselixir on November 2, 2002 5:46:09 PM]
"Who are you, and how did you get in here?""I''m the locksmith, and I''m the locksmith."
Advertisement
what you''re basically trying to do is rotate around one vector around another.

One vector is you''re axis of rotation - its magnitude equals the angle you want to rotate around.

This vector has components

axis.x axis.y axis.z
(remember |axis|=angle to turn around)

the vector you''re rotating, call it v

well what u would like to do is rotate:

v.x,v.y by angle axis.z
v.z,v.x by angle axis.y
v.z,v.x by angle axis.x

well that wont work because the order which u perform the rotations will affect the final result.

but if we devided axis by say 128 and then perform 128 rotations then the result is accurate(ish).

most people know how to rotate about an axis so if they dont know more precise ways then this is a good way to approximate. U get basically the same answer.

----------------------------
http://www.digitalsentience.pwp.blueyonder.co.uk
kindfluffysteve, I understand what you mean now, but I would like to use something precise. These points make up models, and I dont want them deformed the least bit :-/

If there is a way using quatranions or something, that would be preferred.

Thanks for clearing it up though.

thewayout_is_through, Your image doesnt show up.

If anyone needs any clarification, it is basically 2 vectors. 1 is the axis and the other rotates "a" degrees around the axis.

[EDIT]
thewayout_is_through, I see your image now, but that isn't my problem :-/ My explanation sucked.

[edited by - shrooboo on November 1, 2002 12:54:57 AM]
my view is that in dynamics simulations things are always approximate.

the approach isnt too bad, the rotation happens over a time small dt - which is then devided by 128

to see the result of this operation check the torque physics demo on my web page.

----------------------------
http://www.digitalsentience.pwp.blueyonder.co.uk
oh yeah, somebody posted this once...

...http://mathworld.wolfram.com/RotationFormula.html

I imagine I''ll be using this in the future.

----------------------------
http://www.digitalsentience.pwp.blueyonder.co.uk

This topic is closed to new replies.

Advertisement