Since there is no Debug.DrawPlane
Well, let's make our own tools to help us visualize it then.
// Mimics Debug.DrawLine, drawing a plane containing the 3 provided worldspace points,
// with the visualization centered on the centroid of the triangle they form.
public static void DrawPlane(Vector3 a, Vector3 b, Vector3 c, float size,
Color color, float duration = 0f, bool depthTest = true) {
var plane = new Plane(a, b, c);
var centroid = (a + b + c)/3f;
DrawPlaneAtPoint(plane, centroid, size, color, duration, depthTest);
}
// Draws the portion of the plane closest to the provided point,
// with an altitude line colour-coding whether the point is in front (cyan)
// or behind (red) the provided plane.
public static void DrawPlaneNearPoint(Plane plane, Vector3 point, float size, Color color, float duration = 0f, bool depthTest = true) {
var closest = plane.ClosestPointOnPlane(point);
Color side = plane.GetSide(point) ? Color.cyan : Color.red;
Debug.DrawLine(point, closest, side, duration, depthTest);
DrawPlaneAtPoint(plane, closest, size, color, duration, depthTest);
}
// Non-public method to do the heavy lifting of drawing the grid of a given plane segment.
static void DrawPlaneAtPoint(Plane plane, Vector3 center, float size, Color color, float duration, bool depthTest) {
var basis = Quaternion.LookRotation(plane.normal);
var scale = Vector3.one * size / 10f;
var right = Vector3.Scale(basis * Vector3.right, scale);
var up = Vector3.Scale(basis * Vector3.up, scale);
for(int i = -5; i <= 5; i++) {
Debug.DrawLine(center + right * i - up * 5, center + right * i + up * 5, color, duration, depthTest);
Debug.DrawLine(center + up * i - right * 5, center + up * i + right * 5, color, duration, depthTest);
}
}
Or, if you want to play with planes interactively, you can drop this script into an empty scene and toy with its position & inspector parameters to visualize how they affect the geometry of the plane.
public class PlaneVisualizer : MonoBehaviour {
public Vector3 a = Vector3.right;
public Vector3 b = Vector3.up;
public Vector3 c = Vector3.forward;
void OnDrawGizmos() {
var plane = new Plane(a, b, c);
// Draw our three input points in world space.
// b and c are drawn as lollipops from the preceding point,
// so that you can see the clockwise winding direction.
Gizmos.color = Color.white;
Gizmos.DrawWireSphere(a, 0.1f);
Gizmos.color = Color.gray;
Gizmos.DrawLine(a, b);
Gizmos.DrawWireSphere(b, 0.1f);
Gizmos.color = Color.black;
Gizmos.DrawLine(b, c);
Gizmos.DrawWireSphere(c, 0.1f);
// Draw this object's position,
// as a lollipop sticking out from our plane,
// blue-green if in front (in the positive half-space),
// and red if behind (negative half-space).
Gizmos.color = plane.GetSide(transform.position) ? Color.cyan : Color.red;
Gizmos.DrawLine(plane.ClosestPointOnPlane(transform.position), transform.position);
Gizmos.DrawWireSphere(transform.position, 0.2f);
// Draw plane normal.
Gizmos.color = Color.yellow;
var center = (a + b + c) / 3f;
Gizmos.DrawLine(center, center + plane.normal);
// Draw planar grid.
Gizmos.color = Color.blue;
var matrix = Gizmos.matrix;
Gizmos.matrix = Matrix4x4.TRS(center, Quaternion.LookRotation(plane.normal), Vector3.one);
for(int i = -10; i <= 10; i++) {
Gizmos.DrawLine(new Vector3(i, -10, 0), new Vector3(i, 10, 0));
Gizmos.DrawLine(new Vector3(-10, i, 0), new Vector3(10, i, 0));
}
Gizmos.matrix = matrix;
}
}