# 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)

*** ** * ** ***


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

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

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#fromQuaternion(androidx.xr.runtime.math.Quaternion)(quaternion: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion)` Returns a new 3x3 rotation matrix from the given `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3.Companion#fromQuaternion(androidx.xr.runtime.math.Quaternion)`, which is first normalized. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#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/Matrix3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#fromScale(androidx.xr.runtime.math.Vector3)(scale: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3)` Returns a new scale matrix. |

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

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#Matrix3(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/Matrix3#Matrix3(androidx.xr.runtime.math.Matrix3)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3)` Creates a new matrix with a deep copy of the data from the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3`. |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#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/Matrix3#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/Matrix3#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/Matrix3#hashCode()()` Standard hash code calculation using constructor values. |
| `operator https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#times(androidx.xr.runtime.math.Matrix3)(other: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3)` Multiplies this matrix by `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#times(androidx.xr.runtime.math.Matrix3)`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#toString()()` Standard toString() implementation. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#data()` Returns an array of the components of this matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#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/Matrix3#isTrs()` True if the matrix represents a valid rotation-scale transformation. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#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/Matrix3#scale()` Returns the scale component of this matrix. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3` | `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix3#transpose()` Returns a matrix that is the transpose of this matrix. |

## Public companion functions

### fromQuaternion

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

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

Returns a new 3x3 rotation matrix from the given `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `quaternion: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Quaternion` | the quaternion to convert |

### fromScale

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

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

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): Matrix3
```

Returns a new scale matrix.

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

## Public companion properties

### IDENTITY

```
val IDENTITY: Matrix3
```

Returns an identity matrix.

### ZERO

```
val ZERO: Matrix3
```

Returns a zero matrix.

## Public constructors

### Matrix3

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

```
Matrix3(dataToCopy: FloatArray)
```

| Parameters |
|---|---|
| `dataToCopy: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html` | 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)

```
Matrix3(other: Matrix3)
```

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

## 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): Matrix3
```

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/Matrix3#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: Matrix3): Matrix3
```

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

### toString

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

Standard toString() implementation.

## 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: Matrix3
```

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 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.

### transpose

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

```
val transpose: Matrix3
```

Returns a matrix that is the transpose of this matrix.