Skip to main content
Correcting handedness
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

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);

Note that because Unity uses a left-handed coordinate system, this z direction points down into the plane, not up out of it as in the diagram. You can flip your x or y direction if you want z pointing the other way.

We can turn this into a quaternion using:

var planeOrientation = Quaternion.LookRotation(z, y);

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);

Note that because Unity uses a left-handed coordinate system, this z direction points down into the plane, not up out of it as in the diagram. You can flip your x or y direction if you want z pointing the other way.

We can turn this into a quaternion using:

var planeOrientation = Quaternion.LookRotation(z, y);

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);
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

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);

Note that because Unity uses a left-handed coordinate system, this z direction points down into the plane, not up out of it as in the diagram. You can flip your x or y direction if you want z pointing the other way.

We can turn this into a quaternion using:

var planeOrientation = Quaternion.LookRotation(z, y);