# Matrix3

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/Matrix3.kt+class:androidx.xr.runtime.math.Matrix3) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

*** ** * ** ***


```
public final class Matrix3
```

<br />

*** ** * ** ***

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

```
[0, 3, 6]
[1, 4, 7]
[2, 5, 8]
```

## Summary

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

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

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#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/Matrix3#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/Matrix3#equals(kotlin.Any)`. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#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 3x3 rotation matrix from the given `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3.Companion#fromQuaternion(androidx.xr.runtime.math.Quaternion)`, which is first normalized. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#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/Matrix3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#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. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull float[]` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#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/Matrix3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#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/Matrix3#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/Matrix3#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/Matrix3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#getTranspose()()` Returns a matrix that is the transpose of this matrix. |
| `int` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#hashCode()()` Standard hash code calculation using constructor values. |
| `final boolean` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#isTrs()()` True if the matrix represents a valid rotation-scale transformation. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#times(androidx.xr.runtime.math.Matrix3)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3 other)` Multiplies this matrix by `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3#times(androidx.xr.runtime.math.Matrix3)`. |
| `@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/Matrix3#toString()()` Standard toString() implementation. |

## Public fields

### IDENTITY

```
public static final @NonNull Matrix3 IDENTITY
```

Returns an identity matrix.

### ZERO

```
public static final @NonNull Matrix3 ZERO
```

Returns a zero matrix.

## Public constructors

### Matrix3

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

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

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

### Matrix3

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

```
public Matrix3(@NonNull Matrix3 other)
```

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

## Public methods

### copy

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

```
public final @NonNull Matrix3 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/Matrix3#equals(kotlin.Any)`.

### fromQuaternion

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

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

Returns a new 3x3 rotation matrix from the given `https://developer.android.com/reference/androidx/xr/runtime/math/Matrix3.Companion#fromQuaternion(androidx.xr.runtime.math.Quaternion)`, which is first normalized. This function uses a standard formula for the conversion, though alternative algebraic expressions exist due to differing conventions. The resulting matrix typically transforms 3D column vectors by pre-multiplication (e.g.,

$v'_{new} = M \\cdot v_{old}$
).

<br />

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

### fromScale

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

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

Returns a new uniform scale matrix.

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

### fromScale

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

```
public static final @NonNull Matrix3 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 |

### getData

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

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

Returns an array of the components of this matrix.

### getInverse

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

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

Returns a matrix that performs the opposite transformation.

### getRotation

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

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

Returns the rotation component of this matrix.

### getScale

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

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

Returns the scale component of this matrix.

### getTranspose

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

```
public final @NonNull Matrix3 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](https://developer.android.com/jetpack/androidx/releases/xr-runtime#1.0.0)

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

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

### times

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

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

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

### toString

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

Standard toString() implementation.