# Matrix4

Artifact: [androidx.xr.runtime:runtime](https://developer.android.com/jetpack/androidx/releases/xr-runtime) [View Source](https://cs.android.com/search?q=file:androidx/xr/runtime/math/Matrix4.kt+class:androidx.xr.runtime.math.Matrix4) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

*** ** * ** ***


```
class Matrix4
```

<br />

*** ** * ** ***

An immutable 4x4 matrix that represents translation, scale, and rotation. The matrix is column major and right handed. The indexes of `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#(kotlin.FloatArray)` represent the following matrix layout:

```kotlin
[0, 4,  8, 12]
[1, 5,  9, 13]
[2, 6, 10, 14]
[3, 7, 11, 15]
```

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#fromPose(androidx.xr.runtime.math.Pose)(pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose)` Returns a new rigid transformation matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#fromQuaternion(androidx.xr.runtime.math.Quaternion)(quaternion: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion)` Returns a new rotation matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#fromScale(kotlin.Float)(scale: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Returns a new uniform scale matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#fromScale(androidx.xr.runtime.math.Vector3)(scale: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3)` Returns a new scale matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#fromTranslation(androidx.xr.runtime.math.Vector3)(translation: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3)` Returns a new translation matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#fromTrs(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Quaternion,androidx.xr.runtime.math.Vector3)(translation: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, rotation: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion, scale: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3)` Returns a new transformation matrix. |

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#Identity()` Returns an identity matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#Zero()` Returns a zero matrix. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#Matrix4(kotlin.FloatArray)(dataToCopy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html)` |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#Matrix4(androidx.xr.runtime.math.Matrix4)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4)` Creates a new matrix with a deep copy of the data from the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#copy(kotlin.FloatArray)(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html)` Returns a copy of the matrix. |
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` Returns true if this matrix is equal to `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#equals(kotlin.Any)`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#hashCode()()` Standard hash code calculation using constructor values |
| `operator https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#times(androidx.xr.runtime.math.Matrix4)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4)` Multiplies this matrix by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#times(androidx.xr.runtime.math.Matrix4)`. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#toPose()()` Converts this matrix to a `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` object. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#toString()()` Standard toString() implementation |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#unscaled()()` Returns a normalized transformation matrix. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#data()` Returns an array of the components of this matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#inverse()` Returns a matrix that performs the opposite transformation. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#isTrs()` True if the matrix represents a valid translation-rotation-scale transformation. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#rotation()` Returns the rotation component of this matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#scale()` Returns the scale component of this matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#translation()` Returns the translation component of this matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#transpose()` Returns a matrix that is the transpose of this matrix. |

## Public companion functions

### fromPose

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun fromPose(pose: Pose): Matrix4
```

Returns a new rigid transformation matrix. The returned matrix is such that it first rotates objects, and then translates them.

| Parameters |
|---|---|
| `pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` | the pose to convert |

### fromQuaternion

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun fromQuaternion(quaternion: Quaternion): Matrix4
```

Returns a new rotation matrix.

| Parameters |
|---|---|
| `quaternion: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion` | the rotation quaternion |

### fromScale

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun fromScale(scale: Float): Matrix4
```

Returns a new uniform scale matrix.

| Parameters |
|---|---|
| `scale: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | the uniform scale factor |

### fromScale

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun fromScale(scale: Vector3): Matrix4
```

Returns a new scale matrix.

| Parameters |
|---|---|
| `scale: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | the scale vector |

### fromTranslation

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun fromTranslation(translation: Vector3): Matrix4
```

Returns a new translation matrix.

| Parameters |
|---|---|
| `translation: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | the translation vector |

### fromTrs

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun fromTrs(translation: Vector3, rotation: Quaternion, scale: Vector3): Matrix4
```

Returns a new transformation matrix. The returned matrix is such that it first scales objects, then rotates them, and finally translates them.

| Parameters |
|---|---|
| `translation: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | the translation component |
| `rotation: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion` | the rotation component |
| `scale: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | the scale component |

## Public companion properties

### Identity

```
val Identity: Matrix4
```

Returns an identity matrix.

### Zero

```
val Zero: Matrix4
```

Returns a zero matrix.

## Public constructors

### Matrix4

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
Matrix4(dataToCopy: FloatArray)
```

| Parameters |
|---|---|
| `dataToCopy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` | the array with 16 elements that will be copied over |

### Matrix4

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
Matrix4(other: Matrix4)
```

Creates a new matrix with a deep copy of the data from the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4`.

## Public functions

### copy

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun copy(data: FloatArray = this.data): Matrix4
```

Returns a copy of the matrix.

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html = this.data` | the new data for the copied matrix |

### equals

```
open operator fun equals(other: Any?): Boolean
```

Returns true if this matrix is equal to `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#equals(kotlin.Any)`.

### hashCode

```
open fun hashCode(): Int
```

Standard hash code calculation using constructor values

### times

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
operator fun times(other: Matrix4): Matrix4
```

Multiplies this matrix by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#times(androidx.xr.runtime.math.Matrix4)`.

### toPose

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun toPose(): Pose
```

Converts this matrix to a `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` object.

### toString

```
open fun toString(): String
```

Standard toString() implementation

### unscaled

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
fun unscaled(): Matrix4
```

Returns a normalized transformation matrix.

This method removes the scaling factors from this matrix, as determined by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4#scale()`, while preserving its core rotational and translational components. The resulting matrix is therefore ideal for accurate normal vector transformations and pure orientation extraction.

## Public properties

### data

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val data: FloatArray
```

Returns an array of the components of this matrix.

### inverse

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val inverse: Matrix4
```

Returns a matrix that performs the opposite transformation.

### isTrs

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val isTrs: Boolean
```

True if the matrix represents a valid translation-rotation-scale transformation.

### rotation

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val rotation: Quaternion
```

Returns the rotation component of this matrix.

### scale

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val scale: Vector3
```

Returns the scale component of this matrix.

### translation

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val translation: Vector3
```

Returns the translation component of this matrix.

### transpose

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

```
val transpose: Matrix4
```

Returns a matrix that is the transpose of this matrix.