← All math tools

Bounds Gizmos

Draw a wireframe of an axis-aligned box and find all eight corner coordinates from its center and full size.

View the Unity C# source on GitHub

3D view

Drag an orange handle to move it, or drag an arrow to move along one axis. Drag the background to orbit. Results are drawn in green.

Result

Inputs

Center
Size

Unity C#

The same calculation as a Unity C# helper.

using UnityEngine;

public static class BoundsGizmo
{
    public static Vector3[] GetCorners(Bounds bounds)
    {
        var corners = new Vector3[8];
        Vector3 min = bounds.min;
        Vector3 max = bounds.max;
        for (int i = 0; i < corners.Length; i++)
        {
            corners[i] = new Vector3(
                (i & 1) == 0 ? min.x : max.x,
                (i & 2) == 0 ? min.y : max.y,
                (i & 4) == 0 ? min.z : max.z);
        }
        return corners;
    }

    // Call from OnDrawGizmos or OnDrawGizmosSelected.
    public static void Draw(Bounds bounds, float cornerRadius = 0.05f)
    {
        Color previousColor = Gizmos.color;
        Gizmos.color = Color.green;
        Gizmos.DrawWireCube(bounds.center, bounds.size);
        foreach (Vector3 corner in GetCorners(bounds))
            Gizmos.DrawSphere(corner, cornerRadius);
        Gizmos.color = previousColor;
    }
}