> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wherobots.com/llms.txt
> Use this file to discover all available pages before exploring further.

# ST_3DDWithin

Returns true if the 3D Euclidean distance between `A` and `B` is less than or equal to `distance`. Mirrors PostGIS `ST_3DDWithin`. Polymorphic over input type:

* `(Geometry, Geometry, Double)` — 3D distance via JTS; coordinates without a Z dimension are treated as `z = 0`.
* `(Box3D, Box3D, Double)` — closed-interval 3D distance between two axis-aligned cuboids. Throws `IllegalArgumentException` on inverted bounds (`xmin > xmax`, `ymin > ymax`, or `zmin > zmax`).

This is distinct from [ST\_DWithin](/reference/wherobots-db/geometry-data/predicates/ST_DWithin), which always measures planar (2D) distance regardless of input dimensionality — matching the PostGIS distinction between `ST_DWithin` and `ST_3DDWithin`.

<img src="https://mintcdn.com/wherobots/XpQVzmvmMISOboEb/images/sql-functions/box3d/st_3ddwithin_true.svg?fit=max&auto=format&n=XpQVzmvmMISOboEb&q=85&s=f598e41334bcd998f323ebc9f2d581f6" alt="ST_3DDWithin returning true: the 3D gap is within the distance" width="340" height="285" data-path="images/sql-functions/box3d/st_3ddwithin_true.svg" />

<img src="https://mintcdn.com/wherobots/XpQVzmvmMISOboEb/images/sql-functions/box3d/st_3ddwithin_false.svg?fit=max&auto=format&n=XpQVzmvmMISOboEb&q=85&s=54774f60edec81c193f17926e6672836" alt="ST_3DDWithin returning false: the 3D gap exceeds the distance" width="340" height="285" data-path="images/sql-functions/box3d/st_3ddwithin_false.svg" />

Returns `NULL` if any argument is `NULL`.

## Signatures

```sql theme={"system"}
ST_3DDWithin(A: Geometry, B: Geometry, distance: Double)
```

```sql theme={"system"}
ST_3DDWithin(A: Box3D, B: Box3D, distance: Double)
```

## Parameters

<ParamField body="A" type="Geometry | Box3D" required>
  The first geometry or 3D bounding box.
</ParamField>

<ParamField body="B" type="Geometry | Box3D" required>
  The second geometry or 3D bounding box.
</ParamField>

<ParamField body="distance" type="Double" required>
  The maximum 3D distance between `A` and `B`.
</ParamField>

## Return type

<ResponseField type="Boolean">
  `true` if the 3D distance between `A` and `B` is within `distance`.
</ResponseField>

## Example

```sql theme={"system"}
SELECT ST_3DDWithin(ST_PointZ(0, 0, 0), ST_PointZ(0, 0, 3), 3.0)
```

```
true
```

The same points are not within 2.9 units in 3D:

```sql theme={"system"}
SELECT ST_3DDWithin(ST_PointZ(0, 0, 0), ST_PointZ(0, 0, 3), 2.9)
```

```
false
```

## Optimization

`ST_3DDWithin(a, b, distance)` between two `Box3D` columns (or two geometry columns) is planned as a distance join. The planner expands each shape's XY footprint by `distance` for the R-tree pass — a valid superset filter, since the XY distance between two shapes is no greater than their 3D distance — and re-checks the full 3D distance per candidate pair.
