I have two 3d vectors originating from the same point. What I want to do is rotate the top vector by a certain angle along the axis between the vectors. Let me show a diagram: (Red lines are the original vector, green is the angle I want to rotate, and orange is the final vector)
Keep in mind they are 3d vectors, not 2d. Does anyone know the math to do this?
The dot product of the two vectors would give me the angle between them, so I don't believe your code would give me the correct position. (It also doesn't consider the angle I want to rotate it by).
EDIT: On trying it out, yours only pushes the point down one of the already known vectors.
If v1 and v2 are not colinear, they define a plane, and I think you are saying you want to rotate v1 in that plane. One way would be to find orthogonal unit vectors in that plane and go from there.
v1.normalize is the first unit vector (v1 - v1.dot(v2)).normalize is the second unit vector
Now you can rotate v1 through theta radians by using those orthogonal unit vectors:
(Let "x" denote cross product)
Since the normal of the plane the circle is on is (v1 x v2)
a2 would be (v1 x (v1 x v2)).normalize or maybe ((v1 x v2) x v1).normalize
It eludes me at the moment which one is correct, since Irrlicht uses (I think) left hand coordinate system.
(Let "x" denote cross product)
Since the normal of the plane the circle is on is (v1 x v2)
a2 would be (v1 x (v1 x v2)).normalize
Yep, look up the vector identity for repeated cross products and you'll see it reduces to the form for a2 that I gave. Fewer multiplies in the end, if you care about that kind of thing.
But the RogerBorg snippet looks like an elegant way to go that uses Irrlicht built-ins.
And yes, I'm replying multiple messages after the Ducky said he found some code. Vector math rocks!