Ashutosh Pandey
Ashutosh Pandey

Reputation: 145

ARKit – What do the different columns in Transform Matrix represent?

An ARAnchor's 4x4 matrix has 4 columns. The fourth column of the matrix contains 3 translate values for x, y, and z coordinates.

I was wondering what the other 3 columns represent?

Upvotes: 9

Views: 5784

Answers (2)

Andy Jazz
Andy Jazz

Reputation: 58563

4x4 SIMD Matrix

RealityKit, ARKit, SceneKit and ARCore (as well as deprecated Sceneform) frameworks use 4x4 Transform Matrices (simd_float4x4 matrices) to translate, rotate, scale and shear 3D objects. In 3D Graphics we use matrices with 16 elements. The Identity (i.e. default) 4x4 Matrix is as following:

enter image description here

Between those sixteen elements there are 6 different shearing coefficients:

shear XY
shear XZ
shear YX
shear YZ
shear ZX
shear ZY

In Shear Matrix they are as followings:

enter image description here

Because there are no Rotation coefficients in this Matrix, six Shear coefficients along with three Scale coefficients allow you rotate 3D objects about X, Y, and Z axis using magical trigonometry (sin and cos).

Here's an example how to rotate 3D object (CCW) about its Z axis using Shear and Scale elements:

enter image description here

Look at 3 different Rotation patterns that use Shear and Scale elements:

enter image description here

3 translation elements (tx,ty,tz) in the 4x4 Matrix are located in the last column:

 ┌               ┐
 |  1  0  0  tx  |
 |  0  1  0  ty  |
 |  0  0  1  tz  |
 |  0  0  0  1   |
 └               ┘

The columns' indices in ARKit, ARCore, RealityKit and SceneKit are: 0, 1, 2, 3. The fourth column (index 3) contains translation values:

var translation = matrix_identity_float4x4

translation.columns.3.x
translation.columns.3.y
translation.columns.3.z

Additional materials

I recommend you read my illustrated story about 4x4 Transform Matrices on Medium.

I also recommend reading the post on how to Record Matrices ​​to file in order to pass them to Maya.

Perspective and orthographic projections

Look at the example how to setup an orthographic projection in ARCore and Sceneform.

Values located in the bottom row of a 4x4 matrix is used for perspective projection.

Upvotes: 26

John Scalo
John Scalo

Reputation: 3421

If you're new to 3D then these transformation matrices will seem like magic. Basically, every "point" in ARKit space is represented by a 4x4 transform matrix. This matrix describes the distance from the ARKit origin (the point at which ARKit woke up to the world), commonly known as the translation, and the orientation of the device, aka pitch, roll, and yaw. A transform matrix can also describe scale, although typically you won't deal with scale until you render something.

What do the columns mean? That gets complicated but just remember that the first 3 elements of the 4th column are the x,y,z translation. That will come in handy. The rest holds scale and rotation information.

Upvotes: 18

Related Questions