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.