Matrix rotation of a Vector3 around three planes of rotation

Hi all,

I have a Vector3 instance (v3_orig) that represents a point where a line segment has passed through a plane. In the application, the plane can have arbitrary rotation values (0 < x < 180, 0 < y <180, 0 < z < 180). After determining the point where the line segment crosses the plane, I want to rotate the point from its initial intersection position to a new position so that the point would be at the same position on the plane if the plane orientation had been normalized (Quaternion.identity). I do not want to use Transforms, as the Vector3 is part of a larger mesh object, and I simply want to rotate the vertex position.

I have solutions that work if the initial plane is only rotated in two of three axes (XY, YZ, or ZX) but I can’t get it to work if all three axes have a value != 0.

Here is the original code (c#):

Vector3 v3_orig = Vector3(4,3,5) // some point that intersects with plane
Quaternion q = Quaternion.identity;
q.eulerAngles = new Vector3(-20, -20, 40); // Corrected angles to virtually rotate plane
Matrix4x4 m = Matrix4x4.TRS(, q ,;

Vector3 v3_final = m.MultiplyPoint3x4(v3_orig);

I have tried several variants on this theme and will post if anyone thinks they can give me a hand with this problem. Would also be happy to post a few images that help explain the problem if my explanation is not adequate.

Thank you.

Brian Stone posted this answer on the forum and it addresses my problem perfectly.

Here is what he wrote:

If you have a matrix or quaternion which represents the orientation of the plane, then all you need to do is calculate the Inverse of that transform and multiply it to the point. This will transform the point to the World’s identity orientation (X:<1,0,0>, Y<0,1,0>, Z<0,0,1>), because any matrix multiplied by its inverse is the identity matrix*.

Matrix4x4 M; // set this to the plane's orientation
Vector3 v3_orig; // some point that intersects with the plane
Matrix4x4 Mi = M.inverse; 
Vector3 v3_final = Mi * v3_orig;
  • implies that the matrix is square and non-singular.

And to demo with Quaternion:

Quaternion qi = Quaternion.Inverse(plane.transform.rotation);
Vector3 v3_final = qi * v3_orig;