# Matrix

``` public class Matrix ```
``` extends Object ``` ``` ```

 java.lang.Object ↳ com.viro.core.Matrix

Matrix represents a 4x4 floating-point Matrix. Values are column-major.

## Summary

### Public constructors

``` Matrix() ```

Construct a new Matrix, initialized to identity.

``` Matrix(float[] values) ```

Construct a new Matrix with the given values in a float, in column-major order.

### Public methods

``` boolean``` ``` equals(Object obj) ```
``` Quaternion``` ``` extractRotation(Vector scale) ```

Extract the rotation embedded in this Matrix and return it as a `Quaternion`.

``` Vector``` ``` extractScale() ```

Extract the scale component of this Matrix and return it as a `Vector`.

``` Vector``` ``` extractTranslation() ```

Extract the translation component of this Matrix and return it as a `Vector`.

``` int``` ``` hashCode() ```
``` Matrix``` ``` invert() ```

Invert this Matrix and return the result (this Matrix is not mutated by the operation).

``` static Matrix``` ``` makeIdentity() ```

Return a new identity matrix.

``` static Matrix``` ``` makeRotation(float angleRad, Vector origin, Vector dir) ```

Return a new rotation matrix about the given axis.

``` static Matrix``` ``` makeScale(float sx, float sy, float sz) ```

Return a new scale matrix.

``` static Matrix``` ``` makeTranslation(float tx, float ty, float tz) ```

Return a new translation matrix.

``` Vector``` ``` multiply(Vector vector) ```

Multiply this Matrix by the given `Vector` and return the result (neither this Matrix nor the input Vector are mutated by this operation).

``` Matrix``` ``` multiply(Matrix matrix) ```

Multiply this Matrix by the given matrix and return the result (neither this Matrix nor the input Matrix are mutated by this operation).

``` String``` ``` toString() ```
``` Matrix``` ``` transpose() ```

Transpose this Matrix and return the result (this Matrix is not mutated by the operation).

## Public constructors

### Matrix

`Matrix ()`

Construct a new Matrix, initialized to identity.

### Matrix

`Matrix (float[] values)`

Construct a new Matrix with the given values in a float, in column-major order.

Parameters
`values` `float`: The column-major component values for the Matrix, in an array of length 16.

## Public methods

### equals

`boolean equals (Object obj)`

Parameters
`obj` `Object`

Returns
`boolean`

### extractRotation

`Quaternion extractRotation (Vector scale)`

Extract the rotation embedded in this Matrix and return it as a `Quaternion`. This matrix is not mutated by this operation. The scale component of this Matrix is required to compute the rotation: this can be retrieved via `extractScale()`.

Parameters
`scale` `Vector`: The scale component of the Matrix, as returned by `extractScale()`.

Returns
`Quaternion` The rotation component of this Matrix as a `Quaternion`.

### extractScale

`Vector extractScale ()`

Extract the scale component of this Matrix and return it as a `Vector`. This Matrix is not mutated by this operation.

Returns
`Vector` The scale (X, Y, and Z) embedded bin this Matrix.

### extractTranslation

`Vector extractTranslation ()`

Extract the translation component of this Matrix and return it as a `Vector`. This Matrix is not mutated by this operation.

Returns
`Vector` The translation (X, Y, and Z) embedded in this Matrix.

### hashCode

`int hashCode ()`

Returns
`int`

### invert

`Matrix invert ()`

Invert this Matrix and return the result (this Matrix is not mutated by the operation).

Returns
`Matrix` The inverted Matrix.

### makeIdentity

`Matrix makeIdentity ()`

Return a new identity matrix.

Returns
`Matrix` Identity matrix.

### makeRotation

```Matrix makeRotation (float angleRad,
Vector origin,
Vector dir)```

Return a new rotation matrix about the given axis. Multiplying this Matrix with a `Vector` will rotate the vector by the given radians about the provided axis.

Parameters
`angleRad` `float`: The rotation amount in radians.

`origin` `Vector`: The origin of the axis of rotation.

`dir` `Vector`: The direction of the axis of rotation.

Returns
`Matrix` The rotation Matrix.

### makeScale

```Matrix makeScale (float sx,
float sy,
float sz)```

Return a new scale matrix. Multiplying this Matrix with a `Vector` will scale the Vector by the given amounts.

Parameters
`sx` `float`: The X scale.

`sy` `float`: The Y scale.

`sz` `float`: The Z scale.

Returns
`Matrix` The scale Matrix.

### makeTranslation

```Matrix makeTranslation (float tx,
float ty,
float tz)```

Return a new translation matrix. Multiplying this Matrix with a `Vector` will translate the Vector by the given amounts.

Parameters
`tx` `float`: The X translation.

`ty` `float`: The Y translation.

`tz` `float`: The Z translation.

Returns
`Matrix` The translation Matrix.

### multiply

`Vector multiply (Vector vector)`

Multiply this Matrix by the given `Vector` and return the result (neither this Matrix nor the input Vector are mutated by this operation).

Parameters
`vector` `Vector`: The `Vector` to multiply by this Matrix.

Returns
`Vector` The result of the multiplication.

### multiply

`Matrix multiply (Matrix matrix)`

Multiply this Matrix by the given matrix and return the result (neither this Matrix nor the input Matrix are mutated by this operation).

Parameters
`matrix` `Matrix`: The Matrix to multiply by this one.

Returns
`Matrix` The product of the two matrices.

### toString

`String toString ()`

Returns
`String`

### transpose

`Matrix transpose ()`

Transpose this Matrix and return the result (this Matrix is not mutated by the operation).

Returns
`Matrix` The transposed Matrix.