Hello Guest

Rotate plane so it is parallel to another plane

  • 1 Replies
  • 5288 Views
Rotate plane so it is parallel to another plane
« on: February 11, 2013, 12:24:33 »
Hello. My problem is that I have a surface in world space (three 3D points) that I want to rotate so that the resulting normal of those three points will be the same as another plane's normal, while maintaining the original surface's 'triangular shape'.

If the "destination" plane has a normal of (0, 0, 1) and a point on that plane is (0, 0, 0), and the "source" points are [-0.5, -0.5, -0.5] [-0.5, -0.5, 0.5] [-0.5, 0.5, 0.5], what calculation must I make to rotate those points so that the surface normal becomes (0, 0, 1)?

I have tried simply 'projecting' the "source" points to the "destination" plane using the following method "projectPointToPlane":

public static Vector3f projectPointToPlane(Vector3f point, Vector3f planePoint, Vector3f planeNormal)
{
   float dot = EEngineUtils.getDotProduct(EEngineUtils.getProjectionVector(point, planePoint), planeNormal);
   return new Vector3f(point.getX()+planeNormal.getX()*-dot, point.getY()+planeNormal.getY()*-dot, point.getZ()+planeNormal.getZ()*-dot);
}

public static Vector3f getProjectionVector(Vector3f to, Vector3f from)
{
   return new Vector3f(to.getX()-from.getX(), to.getY()-from.getY(), to.getZ()-from.getZ());
}

public static float getDotProduct(Vector3f v1, Vector3f v2)
{
   return (v1.getX()*v2.getX())+(v1.getY()*v2.getY())+(v1.getZ()*v2.getZ());
}

However I did not get the results I was hoping for.
For example, here are the source points:

Vector3f[-0.5, -0.5, -0.5] | Vector3f[-0.5, -0.5, 0.5] | Vector3f[-0.5, 0.5, 0.5]

here are the resulting points of the projection:

Vector3f[-0.5, -0.5, 0.0] | Vector3f[-0.5, -0.5, 0.0] | Vector3f[-0.5, 0.5, 0.0]

The first two resulting points are the same, which is not what I wanted. I wanted the shape of the resulting 'triangle' to be the same (in this case, a right-angled triangle).
My assumption is that 'projection' isn't what I need and that what I really need is some kind of "rotation", however I'm not sure how to accomplish this.

I thought about finding the angle between the two surface normals and rotating the points by that angle, but I wouldn't know what 'axis' vector to use for the rotation.
Any help would be appreciated. Please let me know if I'm being too vague.
« Last Edit: February 11, 2013, 12:27:15 by Maykin53 »

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: Rotate plane so it is parallel to another plane
« Reply #1 on: February 11, 2013, 14:56:21 »
Ok, here goes nothing (I normally make stupid mistakes in these sort of things)
Do the resultant normal (as in what you want to get to) subtract the original normal: Resultant - Original (I'm bad at explaining subtraction too). This becomes the z axis of your rotation matrix. Now use the cross product to obtain the two vectors perpendicular to them. (The direction these face might be significant but I can't remember right now) These become the x and y axis of the matrix. Now your matrix is simply:
x_x | x_y | x_z | 0
y_x | y_y | y_z | 0
z_x | z_y | z_z | 0
  0  |  0   |   0  | 1
where x_y means the y component of x axis.
I very much hope this will work for you. If not I could have done something stupid, I could have got it completely wrong. Either way drop another reply for a more intelligent person than I to answer.