---
title: Set the alignment
summary: Store, read and clear the 4×4 alignment matrix of a version, and let the server compute one from point pairs.
order: 40
languages: [javascript]
terms: [alignment, version, vid]
see-also: [explanation/alignment, how-to/viewer3d/align-pdf-floor-plans, how-to/geo/set-the-geo-reference, how-to/viewer3d/geo-mode]
notion: https://app.notion.com/p/31ee41afde7f804cbda6e9a0fdbffb3a
---

# Set the alignment

An [[term:alignment]] moves, rotates and possibly scales a model version relative to the other models. It is one 4×4 matrix stored on the [[term:version]]; nothing is recorded about which models were loaded when it was defined or which one it was aligned to. The viewers apply it in both LOCAL and GEO mode, and the BIM.works UI has an *Align models* tool and an *Alignment* section in the node popup (with [[feature:MODEL_ALIGNMENT]]) that write the same matrix. Its *Manual alignment* moves and turns the whole loaded model with the same controls as moving objects ([[page:how-to/using-bimworks/edit-a-model#move-and-rotate]]): drag it, turn it on the ring or with Space, type exact values; Enter stores the stored alignment combined with that change.

## Before you start

You need a client with the `model:write` scope for setting and `fs:read` for reading, and the [[term:vid|Vid]] of the version. The matrix is sixteen numbers in the storage order of the server's `Matrix4d`, column-major with the translation in elements 12, 13 and 14 (the WebGL convention), in millimetres.

The JavaScript SDK wraps setting and computing the matrix (`client.geometry3d`, [[js:@bimworks/jssdk/Geometry3d|Geometry3d]]). Over HTTP, [[openapi:UpdateVersion]] sets and clears it and [[openapi:GetVersion]] reads it ([[page:how-to/geo/set-the-alignment#http|below]]). The Java SDK has no alignment calls.

## Steps

1. **Set the matrix.** The identity below shifted by 2 metres in x; the response is the updated version.

   ```javascript {#set}
   const factory = new BimWorksClientFactory(BIM_WORKS_ADDRESS);
   const client = await factory.createClientWithApiToken(BIM_WORKS_API_TOKEN);

   const alignment = [
   	1, 0, 0, 0,
   	0, 1, 0, 0,
   	0, 0, 1, 0,
   	2000, 0, 0, 1
   ];
   await client.geometry3d.setAlignment(BIM_WORKS_SECOND_MODEL, alignment);
   ```

2. **Read it back** with [[openapi:GetVersion]] ([[page:how-to/geo/set-the-alignment#http|below]]): the version's `alignment` holds the sixteen numbers, and is absent when the version has none.

3. **Clear it** by setting `null`: `await client.geometry3d.setAlignment(BIM_WORKS_SECOND_MODEL, null)`.

4. **Compute one from points.** `CalculateAlignment` returns the matrix that maps the `b` points, in the model to move, onto the `a` points: `point1a` and `point1b` are required. One pair only moves the model; two pairs also turn it and scale it, with one scale for every direction; three pairs give a full linear transform, which can scale each direction differently, skew and mirror; across the plane of the three points, which they leave open, it scales by the geometric mean of the in-plane scales. This is what the UI's alignment tool does with the points the user clicks; [[page:how-to/viewer3d/align-pdf-floor-plans]] picks them in two viewers.

   ```javascript {#calculate}
   const matrix = await client.geometry3d.calculateAlignment(
   	{x: 2000, y: 0, z: 0}, {x: 0, y: 0, z: 0},        // where a point should land, and that point in the model to move
   	{x: 12000, y: 0, z: 0}, {x: 10000, y: 0, z: 0}   // a second pair
   );
   await client.geometry3d.setAlignment(BIM_WORKS_SECOND_MODEL, matrix);
   ```

   A point is `[x, y, z]`, an array or a `vec3`, or an object `{x, y, z}`, in millimetres.

A loaded viewer does not pick up a changed alignment by itself: reload the version (`modelManager.removeModels` and `addModels`) or call `viewer.updateModel(vid)`.

## Over HTTP {#http}

[[openapi:UpdateVersion]] sets the matrix as `alignment`, the same sixteen numbers in millimetres, and leaves the version's other fields as they are. It answers the updated version.

```try-it
operation: UpdateVersion
method: POST
path: /openapi/fs/UpdateVersion
body: |
  {
    "version_uuid": BIM_WORKS_SECOND_MODEL,
    "alignment": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2000, 0, 0, 1]
  }
```

`"clear": ["alignment"]` in place of `alignment` removes it. [[openapi:GetVersion]] answers the version with its `alignment`:

```try-it
operation: GetVersion
method: POST
path: /openapi/fs/GetVersion
body: |
  {
    "uuid": BIM_WORKS_SECOND_MODEL
  }
```

Computing a matrix from point pairs has no operation; it is the JavaScript SDK's `calculateAlignment`.

## Check

[[openapi:GetVersion]] answers the sixteen numbers you set as `alignment`, and the model appears shifted by 2 m in the 3D viewer after reloading it.
