Find the rotation x, y, z between two normal vectors

I have two squares in three-dimensional space. I want to find the angles x, y, z between them. I started by looking for normal vectors for both squares, and I'm trying to figure out how to get the angle between them.

I am using XNA (C #) Vector3 objects.

I calculated normal vectors as follows:

        Vector3 normal1 = (Vector3.Cross(sq1.corners[0] - sq1.corners[1], sq1.corners[0] - sq1.corners[2]));
        Vector3 normal2 = (Vector3.Cross(sq2.corners[0] - sq2.corners[1], sq2.corners[0] - sq2.corners[2]));

I want to find a Euler turn that will become normal1, inverted in the same way as normal2

+3
source share
1 answer

Firstly, you can calculate the axis and the number of revolutions (assuming an arbitrary axis):

Vector3 axis = Vector3.Cross(normal1, normal2);
axis.Normalize();
double angle = Math.Acos(Vector3.Dot(normal1, normal2) / normal1.Length() / normal2.Length());

If the normals are normalized, then the calculation of the angle reduces to

double angle = Math.Acos(Vector3.Dot(normal1, normal2));

Then you can convert this to Euler angles using the function here

+8
source

All Articles