I have 4 points as Vector3 in 3D space that shape a plane. How can I calculate the plane normal direction these four points create together, and express it as a Quaternion?
1 Answer
\$\begingroup\$
\$\endgroup\$
First, we'll average together the vertical and horizontal edges of your quad to get two vectors, pointing in the directions of the x and y axes of the transform gizmo in your diagram:
var x = C - A + D - B;
var y = C - D + A - B;
The z direction is then
var z = Vector3.Cross(x, y);
We can turn this into a quaternion using:
var planeOrientation = Quaternion.LookRotation(z, y);
