#### Archived

This topic is now archived and is closed to further replies.

# Rotate point around vector

This topic is 5860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have a 3d point and a vector that I want to rotate the point around. Is there a vector equation to accomplish this?

##### Share on other sites
Off the top of my head I would say...

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]

##### Share on other sites
But how do I get a vector in the angle of the rotation?

##### Share on other sites
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

##### Share on other sites
Well, thanks for trying guys, but I must be an idiot, because Im lost.

##### Share on other sites
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]

##### Share on other sites
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

##### Share on other sites
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]

##### Share on other sites
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

##### Share on other sites
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

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633370
• Total Posts
3011544
• ### Who's Online (See full list)

There are no registered users currently online

×