3D plane rotation

I am doing something where I have a plane in sys A coordinate with a set of points, already on it. I also have a normal vector in the space N. How can I rotate the points on the coordinate sys A so that the plane lying in the plane has the same normal direction as N?

I wonder if anyone has a good idea on how to do this. Thanks

+7
source share
3 answers

If you or you can easily calculate the normal vector on the plane where your points are, I think that the easiest way to do this is to rotate around an axis common to the two planes. Here's how I do it:

  • Let M be the vector normal to your current plane, and N vector normal to the plane you want to rotate into. If M == N you can stop now and leave the starting points unchanged.
  • Calculate the rotation angle as

     costheta = dot(M,N)/(norm(M)*norm(N)) 
  • Calculate the axis of rotation as

     axis = unitcross(M, N) 

    where unitcross is a function that performs the cross product and normalizes it to a unit vector, i.e. unitcross(a, b) = cross(a, b) / norm(cross(a, b)) . As user1318499 noted in the comment, this step may cause an error if M == N , if your unitcross implementation unitcross not return (0,0,0) when a == b .

  • Calculate the rotation matrix along the axis and angle as

     c = costheta s = sqrt(1-c*c) C = 1-c rmat = matrix([ x*x*C+cx*y*Cz*sx*z*C+y*s ], [ y*x*C+z*sy*y*C+cy*z*Cx*s ] [ z*x*Cy*sz*y*C+x*sz*z*C+c ]) 

    where x , y and z are components of the axis . This formula is described on Wikipedia .

  • For each point, calculate its corresponding point on the new plane as

     newpoint = dot(rmat, point) 

    where the dot function performs matrix multiplication.

This is not unique, of course; as mentioned in peterk's answer, there are an infinite number of possible rotations that you could do to convert a plane normal to M to a plane normal to N This corresponds to the fact that after you follow the steps above, you can rotate the plane around N , and your points will be in different places, remaining in the same plane. (In other words, each rotation that you can do that suits your conditions corresponds to the procedure described above, and then another rotation around N ) But if you don't care where your points end up on the plane, I think it's a rotation around A common axis is the easiest way to just get the points in the plane you want.


If you do not have M , but you have the coordinates of the points in the original plane relative to the origin on this plane, you can calculate the initial normal vector from the positions of two points x1 and x2 as

 M = cross(x1, x2) 

(here you can also use unitcross , but that doesn't make any difference). If you have the coordinates of the points relative to a source that is not on the plane, you can still do this, but you will need the positions of three points:

 M = cross(x3-x1, x3-x2) 
+16
source

A single vector (your normal - N) will not be enough. You will need two more vectors for the other two dimensions. (Imagine your 3D space can still rotate / rotate around a normal vector, and you need 2 more vectors to nail it). If you have a normal one and another on the plane, the third should be easy to find (left or right depending on your system).

Make sure that all three are normalized (length 1) and placed in the matrix; use this matrix to transform any point in your three-dimensional space (use matrix multiplication). This should give you new coordinates.

+1
source

I’m thinking of making a unit vector [0,0,1] and using a dot product along two planes to find the difference angle, and shift all your points to these angles. This assumes that you want the z axis to coincide with the normal vector, otherwise just use [1,0,0] or [0,1,0] for x and y respectively.

0
source

All Articles