Link to home
Start Free TrialLog in
Avatar of GoldStone32767
GoldStone32767

asked on

Vector Math

Lets say you have 2 vectors which are normals, A and B.

how would you go about findind the rotations, so that you can rotate Vector A to equal Vector B.

thx in advanced

 
Avatar of pimaster
pimaster

The two vectors establish a plane.  
First, find the angle Φ between the vectors A and B:
Φ = cosˉ¹      (Ax * Bx + Ay * By + Az * Bz) /
           ( sqrt(Ax²+Ay²+Az²) * sqrt(Bx²+By²+Bz²) )

Whew!

Next, find the vector normal to the plane:

Nx = Ay * Bz - Az * By
Ny = Ax * Bz - Az * Bx
Nz = Ax * By - Ay * Bx

The axis of rotation will be the normal vector N.

Rotate the point (Ax,Ay,Az) Φ radians about N.  

The DirectX SDK contains a very useful routine which produces a rotation matrix from an arbritrary vector
& angle of rotation.

There are also routines to calculate normals, dot products, etc.

I don't know if this is the easiest way to do this,  but it was the first method that came to mind.  You'll have to modify the normal calculations for a right handed system.  I haven't had time to test this, but the basic reasoning should be sound.
Ok, let's try it WITHOUT the useless Unicode characters:

The two vectors establish a plane.  
First, find the angle between the vectors A and B:
Theta = cos-1      (Ax * Bx + Ay * By + Az * Bz) /
              ( sqrt(Ax2+Ay2+Az2) * sqrt(Bx2+By2+Bz2) )

Whew!

Next, find the vector normal to the plane:

Nx = Ay * Bz - Az * By
Ny = Ax * Bz - Az * Bx
Nz = Ax * By - Ay * Bx

The axis of rotation will be the normal vector N.

Rotate the point (Ax,Ay,Az) Theta radians about N.

Ugh...
Avatar of GoldStone32767

ASKER

I understand how to calculate the cross product between the 2 vectors... but the problem im having is, how do you rotate around that vector?
ASKER CERTIFIED SOLUTION
Avatar of pimaster
pimaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial