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)
David z
source share