Tools for agents: Exact ray-box intersection

Compute the exact forward-ray interval inside a closed axis-aligned 3D box.

Connect with MCP

{
  "mcpServers": {
    "super-agent-tools": {
      "url": "https://app.getsupers.com/sites/agent-ray-box/mcp"
    }
  }
}
Streamable HTTP · No API key · Stateless

Use this URL in any client supporting remote Streamable HTTP MCP. Calls return structured JSON; inputs are processed without persistence.

Call intersect_ray_box

Ray equation is origin+t*direction with t >= 0. Direction is nonzero and need not be normalized; t is not Euclidean distance. Box boundaries are included; equal min/max coordinates permit flat, line or point boxes. A tangent intersection returns a single-point interval. If the origin is in the closed box, interval start is 0 and entry_point is the origin, not the backward boundary crossing. Parallel components are handled without division by zero. A miss returns null interval and points; single_point is then false. Inputs are integers or quoted decimal/fraction strings; JSON floats and booleans are rejected. Results use exact rational strings without geometric epsilon. Axes and units must match; this does not transform oriented boxes or intersect arbitrary meshes.

Input and output schemas
{
  "name": "intersect_ray_box",
  "title": "Exact ray-box intersection",
  "description": "Intersect origin+t*direction, t>=0, with a closed axis-aligned box. Return an exact interval and endpoint coordinates, including tangent and degenerate-box hits.",
  "inputSchema": {
    "properties": {
      "origin": {
        "maxItems": 3,
        "minItems": 3,
        "prefixItems": [
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          }
        ],
        "title": "Origin",
        "type": "array"
      },
      "direction": {
        "maxItems": 3,
        "minItems": 3,
        "prefixItems": [
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          }
        ],
        "title": "Direction",
        "type": "array"
      },
      "box_min": {
        "maxItems": 3,
        "minItems": 3,
        "prefixItems": [
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          }
        ],
        "title": "Box Min",
        "type": "array"
      },
      "box_max": {
        "maxItems": 3,
        "minItems": 3,
        "prefixItems": [
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          },
          {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "string"
              }
            ]
          }
        ],
        "title": "Box Max",
        "type": "array"
      }
    },
    "required": [
      "origin",
      "direction",
      "box_min",
      "box_max"
    ],
    "title": "intersect_ray_boxArguments",
    "type": "object"
  },
  "outputSchema": {
    "additionalProperties": true,
    "title": "intersect_ray_boxDictOutput",
    "type": "object"
  },
  "icons": null,
  "annotations": {
    "title": null,
    "readOnlyHint": true,
    "destructiveHint": false,
    "idempotentHint": true,
    "openWorldHint": false
  },
  "meta": null,
  "execution": null
}

Run the example to see the actual result.

HTTP alternative

POST https://app.getsupers.com/sites/agent-ray-box/call
Content-Type: application/json

{
  "origin": [
    -2,
    1,
    1
  ],
  "direction": [
    2,
    0,
    0
  ],
  "box_min": [
    0,
    0,
    0
  ],
  "box_max": [
    3,
    2,
    2
  ]
}

The HTTP and MCP interfaces execute the same implementation. Validation errors are returned explicitly. See the tool notes above for its supported inputs and behavior.

Closed slabs intersect a forward ray exactly

Read the explanation

The supplied ray starts at minus two, one, one and points along two, zero, zero. The box spans zero to three in x and zero to two in y and z. The diagram shows its z equals one slice. X equals minus two plus two t: reaching zero gives t one and reaching three gives t five halves. The gold segment shows the closed interval inside the box; endpoints are included. Parallel y and z coordinates already lie inside their slabs. Doubling direction to four, zero, zero gives the same geometric line and entry and exit points. Parameter values halve to one half and five quarters. T is not Euclidean distance because direction need not be normalized. Distance traveled is parameter times direction magnitude. If a parallel coordinate lies outside its closed slab, the ray misses without dividing by zero. The exact rational contract uses no geometric epsilon. Moving the origin to one, one, one places it inside the box. For direction two, zero, zero, the returned interval starts at zero and ends at one, with the origin as the entry point. It does not return the backward boundary crossing. Tangencies and flat boxes can return a single-point interval. A miss returns null interval and points. These calculations explain the published contract; no remote HTTP or MCP call was made and backend execution remains unverified.

Exact Ray-Box Intersection and the Slab Method

How does the slab method compute the exact interval where a forward ray intersects an axis-aligned 3D box?

An axis-aligned 3D box can be defined as the geometric intersection of three perpendicular pairs of parallel boundary planes, known as slabs. Ray-box intersection evaluates the parametric ray equation p(t) = origin + t * direction for t >= 0 against each coordinate slab independently. For each axis where direction is nonzero, solving for the slab boundary crossings yields a 1D interval [t_near, t_far]. Intersecting these intervals across all axes—by taking the latest entry time and the earliest exit time—determines whether the forward ray penetrates the box and yields the exact rational entry and exit endpoints.

The implementation assumes an axis-aligned box; oriented bounding boxes or general meshes require coordinate transformation or mesh triangle solvers. Parameter t measures multiples of the supplied direction vector rather than Euclidean distance unless the direction is unit length. When the ray origin starts inside the box, the forward interval start clamps to 0 rather than reporting backward crossings (t < 0).

Try a worked example

With the default inputs (origin [-2, 1, 1], direction [2, 0, 0], and box bounds [0, 0, 0] to [3, 2, 2]), clicking 'Run tool' executes intersect_ray_box without floating-point rounding. Along the x axis, the ray solves (-2) + t*2 = 0 at t = 1 and (-2) + t*2 = 3 at t = 5/2. Along the y and z axes, direction components are 0 while the origin coordinates (1 and 1) lie strictly within [0, 2], confirming parallel containment. The resulting structured JSON returns 'hit': true, with an interval from start '1' to end '5/2', entry_point ['0', '1', '1'], and exit_point ['3', '1', '1'].

The Slab Intersection Method

In computer graphics and ray tracing, an axis-aligned bounding box (AABB) is framed by three orthogonal pairs of parallel planes: x = x_min and x_max, y = y_min and y_max, and z = z_min and z_max. Evaluating the ray parameter equation along each dimension isolates the 1D interval where the ray resides within that slab. Ray-Box Intersection

The overall 3D intersection is the intersection of these coordinate intervals. If the latest entry parameter exceeds the earliest exit parameter (enter > leave), the ray misses the volume entirely. Ray-Box Intersection

Handling Zero Directions and Forward Constraints

When a ray's direction component along an axis is zero, the ray travels parallel to that coordinate slab. The algorithm checks whether the origin component falls between the minimum and maximum boundaries: if it is outside, the ray misses; if inside, the slab imposes no constraint on parameter t. Ray-Box Intersection

Because this tool restricts intersection to forward rays (t >= 0), any ray origin located inside the closed box yields an entry parameter of 0, returning the origin itself as entry_point rather than a negative backward boundary crossing.

Sources and further reading