---
title: Measure the distance between two objects
summary: Compute the shortest distance between the surfaces of two objects, or vertically or horizontally, interactively or from two Qids, and draw or restore the result as a measurement.
order: 75
since: 3.0
languages: [javascript]
terms: [qid]
see-also: [how-to/viewer3d/measure, how-to/using-bimworks/measure-in-the-3d-viewer, reference/viewer3d/key-bindings]
---

# Measure the distance between two objects

The object distance reads the triangles of two objects, finds the two points that are closest to each other and draws a dimension between them with the distance as its label: the clearance between a pipe and the floor under it, without hunting for the right two vertices. Nothing has to be snapped; the endpoints are computed. This guide starts the tool and computes the same result without interaction.

## Live demo

```demo
name: measurements
title: Measuring
models: ac11
height: 560
notes: |
  Choose **Object distance**, click a pipe or a beam, then the slab under it. The label shows the clearance and the arrowed segment shows where it is measured. Hover the label for the X, Y and Z components of the segment. **Vertical** and **Horizontal** constrain the segment to run straight up or down, or level. Press **O** (or the *Centre line* button) to measure to the pipe's centre line instead of its surface. Two objects that touch or run through each other report **0 mm (intersecting)**.
```

## Steps

1. **Let the user pick.** `startObjectDistanceMeasurement()` starts the interactive tool: object A, then object B. It finishes by itself once the distance is known; Escape cancels. `startObjectDistanceMeasurement({mode: "vertical"})` and `{mode: "horizontal"}` constrain the segment to run straight up or down, or to stay level.

2. **Or compute it from code.** `measureObjectDistance(qidA, qidB)` computes the same result without interaction and resolves to the distance in millimetres, the two closest points and the [[term:qid|Qids]]; with `{add: true}` the finished measurement is drawn as well, and `mode` and `references` choose the direction and whether a side is measured to its centre line.

   ```example
   name: measurements-api
   code: javascript/viewer3d/measurements.js
   notes: The button starts the interactive tool. `measureObjectDistance(qidA, qidB)` computes the same result without interaction and resolves to the distance, the two closest points and the qids; with `{add: true}` the finished measurement is drawn as well. `addObjectDistanceMeasurement(id, result)` restores a stored result without recomputing it, and `viewFitMeasurement(measurement)` on the viewer is the "Zoom to" of the list.
   ```

3. **Store and restore.** Keep the result `measureObjectDistance` returned; `addObjectDistanceMeasurement(id, result)` draws it again later without recomputing.

## What the result means

- **Shortest** is the 3D distance between the surfaces, drawn between the two closest points with an arrowhead at each end. Two objects that touch or run through each other report 0 and a single marker; the penetration depth is not computed, that is what clash detection is for.
- **Vertical** is the shortest segment that runs straight up or down — the floor-to-pipe clearance even when the pipe is not exactly above the nearest point of the floor. **Horizontal** stays level — the gap between a pipe and the wall it runs along. When no such segment exists, because the footprints (vertical) or the height ranges (horizontal) of the two objects do not overlap, the result is the height difference or the horizontal distance between their nearest points instead, and the tooltip says so.
- **To the centre line**: a side can be measured to its reference geometry instead of its surface — the centre line of a pipe, duct, beam or column, the axis plane of a wall. The references are the ones the server derives at check-in; an object without one, such as a slab, stays on its surface.
- **Vertical centre lines**: doors, windows, furniture, flow terminals (light fittings, sprinklers) and other objects without an axis get a vertical centre line over their own height — through the centre of the opening a door or window fills, otherwise through the centre of the object's plan rectangle. Shortest and vertical measure a vertical line from its middle, the object's centre point, so two of them (two windows, a lamp and a column) are measured centre to centre, with `referenceKind: "centreToCentre"` in the result: shortest gives the distance between the two centres, vertical the difference of their centre heights, horizontal their distance in plan whatever their heights. The reference has `vertical: true` and the `method` `openingCentre` or `planCentre`.
- **Precision**: vertex positions are stored quantised, so the distance carries a small error bound; a distance below that bound is shown as "< 1 mm".
- The measurement is **not editable** (its endpoints are computed) and **static**: moving an object afterwards does not recompute it.

## Limits

The distance is computed in the browser from the geometry the viewer has, so an object over two million triangles is refused. Only triangle geometry counts: lines and points are ignored, and point clouds, GIS layers and terrain cannot be picked. Clicking the same object twice, or an object without surface geometry, is refused with a short message and the tool keeps waiting for a second object. The value is measured between surfaces, so an object fully inside another reports the gap between their surfaces, not 0. Vertical and horizontal are taken along the axes of the viewer, which are the axes of the model's placement, not of the building's own grid when the two differ.

## Check

`await measureObjectDistance(pipeQid, slabQid, {add: true})` resolves to a distance in millimetres and draws the dimension between the pipe and the slab.
