# 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-beta02](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0-beta02)

*** ** * ** ***


```
public final 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/androidx/xr/runtime/math/Matrix4#(kotlin.FloatArray)` represent the following matrix layout:

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

## Summary

| ### Public fields |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#Identity()` Returns an identity matrix. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#Zero()` Returns a zero matrix. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#Matrix4(kotlin.FloatArray)(@https://developer.android.com/reference/androidx/annotation/NonNull float[] dataToCopy)` |
| `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#Matrix4(androidx.xr.runtime.math.Matrix4)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4 other)` Creates a new matrix with a deep copy of the data from the `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4`. |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#copy(kotlin.FloatArray)(@https://developer.android.com/reference/androidx/annotation/NonNull float[] data)` Returns a copy of the matrix. |
| `boolean` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` Returns true if this matrix is equal to `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#equals(kotlin.Any)`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#fromPose(androidx.xr.runtime.math.Pose)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose pose)` Returns a new rigid transformation matrix. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#fromQuaternion(androidx.xr.runtime.math.Quaternion)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Quaternion quaternion)` Returns a new rotation matrix. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#fromScale(kotlin.Float)(float scale)` Returns a new uniform scale matrix. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#fromScale(androidx.xr.runtime.math.Vector3)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 scale)` Returns a new scale matrix. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#fromTranslation(androidx.xr.runtime.math.Vector3)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 translation)` Returns a new translation matrix. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#fromTrs(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Quaternion,androidx.xr.runtime.math.Vector3)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 translation, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Quaternion rotation, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 scale )` Returns a new transformation matrix. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull float[]` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#getData()()` Returns an array of the components of this matrix. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#getInverse()()` Returns a matrix that performs the opposite transformation. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Quaternion` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#getRotation()()` Returns the rotation component of this matrix. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#getScale()()` Returns the scale component of this matrix. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#getTranslation()()` Returns the translation component of this matrix. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#getTranspose()()` Returns a matrix that is the transpose of this matrix. |
| `int` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#hashCode()()` Standard hash code calculation using constructor values |
| `final boolean` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#isTrs()()` True if the matrix represents a valid translation-rotation-scale transformation. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#times(androidx.xr.runtime.math.Matrix4)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4 other)` Multiplies this matrix by `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#times(androidx.xr.runtime.math.Matrix4)`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#toPose()()` Converts this matrix to a `https://developer.android.com/reference/androidx/xr/runtime/math/Pose` object. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#toString()()` Standard toString() implementation |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4#unscaled()()` Returns a normalized transformation matrix. |

## Public fields

### Identity

```
public static final @NonNull Matrix4 Identity
```

Returns an identity matrix.

### Zero

```
public static final @NonNull Matrix4 Zero
```

Returns a zero matrix.

## Public constructors

### Matrix4

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

```
public Matrix4(@NonNull float[] dataToCopy)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull float[] dataToCopy` | the array with 16 elements that will be copied over |

### Matrix4

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

```
public Matrix4(@NonNull Matrix4 other)
```

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

## Public methods

### copy

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

```
public final @NonNull Matrix4 copy(@NonNull float[] data)
```

Returns a copy of the matrix.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull float[] data` | the new data for the copied matrix |

### equals

```
public boolean equals(Object other)
```

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

### fromPose

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

```
public static final @NonNull Matrix4 fromPose(@NonNull Pose pose)
```

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

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

### fromQuaternion

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

```
public static final @NonNull Matrix4 fromQuaternion(@NonNull Quaternion quaternion)
```

Returns a new rotation matrix.

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

### fromScale

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

```
public static final @NonNull Matrix4 fromScale(float scale)
```

Returns a new uniform scale matrix.

| Parameters |
|---|---|
| `float scale` | the uniform scale factor |

### fromScale

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

```
public static final @NonNull Matrix4 fromScale(@NonNull Vector3 scale)
```

Returns a new scale matrix.

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

### fromTranslation

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

```
public static final @NonNull Matrix4 fromTranslation(@NonNull Vector3 translation)
```

Returns a new translation matrix.

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

### fromTrs

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

```
public static final @NonNull Matrix4 fromTrs(
    @NonNull Vector3 translation,
    @NonNull Quaternion rotation,
    @NonNull Vector3 scale
)
```

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

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

### getData

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

```
public final @NonNull float[] getData()
```

Returns an array of the components of this matrix.

### getInverse

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

```
public final @NonNull Matrix4 getInverse()
```

Returns a matrix that performs the opposite transformation.

### getRotation

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

```
public final @NonNull Quaternion getRotation()
```

Returns the rotation component of this matrix.

### getScale

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

```
public final @NonNull Vector3 getScale()
```

Returns the scale component of this matrix.

### getTranslation

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

```
public final @NonNull Vector3 getTranslation()
```

Returns the translation component of this matrix.

### getTranspose

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

```
public final @NonNull Matrix4 getTranspose()
```

Returns a matrix that is the transpose of this matrix.

### hashCode

```
public int hashCode()
```

Standard hash code calculation using constructor values

### isTrs

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

```
public final boolean isTrs()
```

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

### times

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

```
public final @NonNull Matrix4 times(@NonNull Matrix4 other)
```

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

### toPose

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

```
public final @NonNull Pose toPose()
```

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

### toString

```
public @NonNull String toString()
```

Standard toString() implementation

### unscaled

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

```
public final @NonNull Matrix4 unscaled()
```

Returns a normalized transformation matrix.

This method removes the scaling factors from this matrix, as determined by `https://developer.android.com/reference/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.