pythagoras.f

## Class Matrix3

• All Implemented Interfaces:
Serializable

```public class Matrix3
extends Object
implements Serializable```
A 3x3 column-major matrix.
Serialized Form
• ### Field Summary

Fields
Modifier and Type Field and Description
`static Matrix3` `IDENTITY`
the identity matrix.
`float` `m00`
The values of the matrix.
`float` `m01`
`float` `m02`
`float` `m10`
The values of the matrix.
`float` `m11`
`float` `m12`
`float` `m20`
The values of the matrix.
`float` `m21`
`float` `m22`
• ### Constructor Summary

Constructors
Constructor and Description
`Matrix3()`
Creates an identity matrix.
`Matrix3(float[] values)`
Creates a matrix from an array of values.
```Matrix3(float m00, float m10, float m20, float m01, float m11, float m21, float m02, float m12, float m22)```
Creates a matrix from its components.
`Matrix3(Matrix3 other)`
Copy constructor.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`Matrix3` `add(pythagoras.f.IMatrix3 other)`
`Matrix3` ```add(pythagoras.f.IMatrix3 other, Matrix3 result)```
Adds this matrix to another and stores the result in the object provided.
`Matrix3` `addLocal(pythagoras.f.IMatrix3 other)`
Adds `other` to this matrix, in place.
`float` `approximateUniformScale()`
Returns an approximation of the uniform scale for this matrix (the square root of the signed area of the parallelogram spanned by the axis vectors).
`float` ```element(int row, int col)```
Returns the matrix element at the specified row and column.
`boolean` `equals(Object other)`
`float` `extractRotation()`
Extracts the rotation component of the matrix.
`Vector` `extractScale()`
Extracts the scale component of the matrix.
`Vector` `extractScale(Vector result)`
Extracts the scale component of the matrix and places it in the provided result vector.
`FloatBuffer` `get(FloatBuffer buf)`
Places the contents of this matrix into the given buffer in the standard OpenGL order.
`void` ```getColumn(int col, Vector3 result)```
Copies the requested column (0, 1, 2) into `result`.
`void` ```getRow(int row, Vector3 result)```
Copies the requested row (0, 1, 2) into `result`.
`int` `hashCode()`
`Matrix3` `invert()`
Inverts this matrix.
`Matrix3` `invert(Matrix3 result)`
Inverts this matrix and places the result in the given object.
`Matrix3` `invertAffine()`
Inverts this matrix as an affine matrix.
`Matrix3` `invertAffine(Matrix3 result)`
Inverts this matrix as an affine matrix and places the result in the given object.
`Matrix3` `invertAffineLocal()`
Inverts this matrix in-place as an affine matrix.
`Matrix3` `invertLocal()`
Inverts this matrix in-place.
`boolean` `isAffine()`
Determines whether this matrix represents an affine transformation.
`Matrix3` ```lerp(pythagoras.f.IMatrix3 other, float t)```
Linearly interpolates between this and the specified other matrix.
`Matrix3` ```lerp(pythagoras.f.IMatrix3 other, float t, Matrix3 result)```
Linearly interpolates between this and the specified other matrix, placing the result in the object provided.
`Matrix3` ```lerpAffine(pythagoras.f.IMatrix3 other, float t)```
Linearly interpolates between this and the specified other matrix, treating the matrices as affine.
`Matrix3` ```lerpAffine(pythagoras.f.IMatrix3 other, float t, Matrix3 result)```
Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in the object provided.
`Matrix3` ```lerpAffineLocal(pythagoras.f.IMatrix3 other, float t)```
Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in this matrix.
`Matrix3` ```lerpLocal(pythagoras.f.IMatrix3 other, float t)```
Linearly interpolates between the this and the specified other matrix, placing the result in this matrix.
`float` `m00()`
Returns column 0, row 0 of the matrix.
`float` `m01()`
Returns column 0, row 1 of the matrix.
`float` `m02()`
Returns column 0, row 2 of the matrix.
`float` `m10()`
Returns column 1, row 0 of the matrix.
`float` `m11()`
Returns column 1, row 1 of the matrix.
`float` `m12()`
Returns column 1, row 2 of the matrix.
`float` `m20()`
Returns column 2, row 0 of the matrix.
`float` `m21()`
Returns column 2, row 1 of the matrix.
`float` `m22()`
Returns column 2, row 2 of the matrix.
`Matrix3` `mult(pythagoras.f.IMatrix3 other)`
Multiplies this matrix by another.
`Matrix3` ```mult(pythagoras.f.IMatrix3 other, Matrix3 result)```
Multiplies this matrix by another and stores the result in the object provided.
`Matrix3` `multAffine(pythagoras.f.IMatrix3 other)`
Multiplies this matrix by another, treating the matrices as affine.
`Matrix3` ```multAffine(pythagoras.f.IMatrix3 other, Matrix3 result)```
Multiplies this matrix by another, treating the matrices as affine, and stores the result in the object provided.
`Matrix3` `multAffineLocal(pythagoras.f.IMatrix3 other)`
Multiplies this matrix in-place by another, treating the matricees as affine.
`Matrix3` `multLocal(pythagoras.f.IMatrix3 other)`
Multiplies this matrix in-place by another.
`Matrix3` `set(float[] values)`
Copies the elements of an array.
`Matrix3` ```set(float m00, float m10, float m20, float m01, float m11, float m21, float m02, float m12, float m22)```
Sets all of the matrix's components at once.
`Matrix3` `set(pythagoras.f.IMatrix3 other)`
Copies the contents of another matrix.
`void` ```setColumn(int col, float x, float y, float z)```
Sets the specified column (0, 1, 2) to the supplied values.
`void` ```setColumn(int col, Vector3 v)```
Sets the specified column (0, 1, 2) to the supplied vector.
`void` ```setElement(int row, int col, float value)```
Sets the matrix element at the specified row and column.
`void` ```setRow(int row, float x, float y, float z)```
Sets the specified row (0, 1, 2) to the supplied values.
`void` ```setRow(int row, Vector3 v)```
Sets the specified row (0, 1, 2) to the supplied vector.
`Matrix3` `setToIdentity()`
Sets this matrix to the identity matrix.
`Matrix3` ```setToReflection(float x, float y, float z)```
Sets this to a reflection across a plane intersecting the origin with the supplied normal.
`Matrix3` `setToReflection(IVector3 normal)`
Sets this to a reflection across a plane intersecting the origin with the supplied normal.
`Matrix3` `setToRotation(float angle)`
Sets this to a rotation matrix.
`Matrix3` ```setToRotation(float angle, float x, float y, float z)```
Sets this to a rotation matrix.
`Matrix3` ```setToRotation(float angle, IVector3 axis)```
Sets this to a rotation matrix.
`Matrix3` `setToRotation(IQuaternion quat)`
Sets this to a rotation matrix.
`Matrix3` ```setToRotation(IVector3 from, IVector3 to)```
Sets this to a rotation matrix that rotates one vector onto another.
`Matrix3` `setToScale(float s)`
Sets this to a uniform scale matrix.
`Matrix3` ```setToScale(float x, float y, float z)```
Sets this to a scale matrix.
`Matrix3` `setToScale(IVector3 scale)`
Sets this to a scale matrix.
`Matrix3` ```setToTransform(IVector translation, float rotation)```
Sets this to a matrix that first rotates, then translates.
`Matrix3` ```setToTransform(IVector translation, float rotation, float scale)```
Sets this to a matrix that first scales, then rotates, then translates.
`Matrix3` ```setToTransform(IVector translation, float rotation, IVector scale)```
Sets this to a matrix that first scales, then rotates, then translates.
`Matrix3` ```setToTranslation(float x, float y)```
Sets this to a translation matrix.
`Matrix3` `setToTranslation(IVector translation)`
Sets this to a translation matrix.
`Matrix3` `setToZero()`
Sets this matrix to all zeroes.
`Matrix3` ```setTranslation(float x, float y)```
Sets the translation component of this matrix.
`Matrix3` `setTranslation(IVector translation)`
Sets the translation component of this matrix.
`String` `toString()`
`Vector3` `transform(IVector3 vector)`
Transforms a vector by this matrix.
`Vector3` ```transform(IVector3 vector, Vector3 result)```
Transforms a vector by this matrix and places the result in the object provided.
`Vector3` `transformLocal(Vector3 vector)`
Transforms a vector in-place by the inner 3x3 part of this matrix.
`Vector` `transformPoint(IVector point)`
Transforms a point by this matrix.
`Vector` ```transformPoint(IVector point, Vector result)```
Transforms a point by this matrix and places the result in the object provided.
`Vector` `transformPointLocal(Vector point)`
Transforms a point in-place by this matrix.
`Vector` `transformVector(IVector vector)`
Transforms a vector by this inner 2x2 part of this matrix.
`Vector` ```transformVector(IVector vector, Vector result)```
Transforms a vector by the inner 2x2 part of this matrix and places the result in the object provided.
`Vector` `transformVectorLocal(Vector vector)`
Transforms a vector in-place by the inner 2x2 part of this matrix.
`Matrix3` `transpose()`
Transposes this matrix.
`Matrix3` `transpose(Matrix3 result)`
Transposes this matrix, storing the result in the provided object.
`Matrix3` `transposeLocal()`
Transposes this matrix in-place.
• ### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`
• ### Field Detail

• #### IDENTITY

`public static final Matrix3 IDENTITY`
the identity matrix.
• #### m00

`public float m00`
The values of the matrix. The names take the form `mCOLROW`.
• #### m10

`public float m10`
The values of the matrix. The names take the form `mCOLROW`.
• #### m20

`public float m20`
The values of the matrix. The names take the form `mCOLROW`.
• #### m01

`public float m01`
• #### m11

`public float m11`
• #### m21

`public float m21`
• #### m02

`public float m02`
• #### m12

`public float m12`
• #### m22

`public float m22`
• ### Constructor Detail

• #### Matrix3

```public Matrix3(float m00,
float m10,
float m20,
float m01,
float m11,
float m21,
float m02,
float m12,
float m22)```
Creates a matrix from its components.
• #### Matrix3

`public Matrix3(float[] values)`
Creates a matrix from an array of values.
• #### Matrix3

`public Matrix3(Matrix3 other)`
Copy constructor.
• #### Matrix3

`public Matrix3()`
Creates an identity matrix.
• ### Method Detail

• #### setElement

```public void setElement(int row,
int col,
float value)```
Sets the matrix element at the specified row and column.
• #### setRow

```public void setRow(int row,
float x,
float y,
float z)```
Sets the specified row (0, 1, 2) to the supplied values.
• #### setRow

```public void setRow(int row,
Vector3 v)```
Sets the specified row (0, 1, 2) to the supplied vector.
• #### setColumn

```public void setColumn(int col,
float x,
float y,
float z)```
Sets the specified column (0, 1, 2) to the supplied values.
• #### setColumn

```public void setColumn(int col,
Vector3 v)```
Sets the specified column (0, 1, 2) to the supplied vector.
• #### setToIdentity

`public Matrix3 setToIdentity()`
Sets this matrix to the identity matrix.
Returns:
a reference to this matrix, for chaining.
• #### setToZero

`public Matrix3 setToZero()`
Sets this matrix to all zeroes.
Returns:
a reference to this matrix, for chaining.
• #### setToRotation

```public Matrix3 setToRotation(IVector3 from,
IVector3 to)```
Sets this to a rotation matrix that rotates one vector onto another.
Returns:
a reference to this matrix, for chaining.
• #### setToRotation

```public Matrix3 setToRotation(float angle,
IVector3 axis)```
Sets this to a rotation matrix.
Returns:
a reference to this matrix, for chaining.
• #### setToRotation

```public Matrix3 setToRotation(float angle,
float x,
float y,
float z)```
Sets this to a rotation matrix. The formula comes from the OpenGL documentation for the glRotatef function.
Returns:
a reference to this matrix, for chaining.
• #### setToRotation

`public Matrix3 setToRotation(IQuaternion quat)`
Sets this to a rotation matrix. The formula comes from the Matrix and Quaternion FAQ.
Returns:
a reference to this matrix, for chaining.
• #### setToScale

`public Matrix3 setToScale(IVector3 scale)`
Sets this to a scale matrix.
Returns:
a reference to this matrix, for chaining.
• #### setToScale

`public Matrix3 setToScale(float s)`
Sets this to a uniform scale matrix.
Returns:
a reference to this matrix, for chaining.
• #### setToScale

```public Matrix3 setToScale(float x,
float y,
float z)```
Sets this to a scale matrix.
Returns:
a reference to this matrix, for chaining.
• #### setToReflection

`public Matrix3 setToReflection(IVector3 normal)`
Sets this to a reflection across a plane intersecting the origin with the supplied normal.
Returns:
a reference to this matrix, for chaining.
• #### setToReflection

```public Matrix3 setToReflection(float x,
float y,
float z)```
Sets this to a reflection across a plane intersecting the origin with the supplied normal.
Returns:
a reference to this matrix, for chaining.
• #### setToTransform

```public Matrix3 setToTransform(IVector translation,
float rotation)```
Sets this to a matrix that first rotates, then translates.
Returns:
a reference to this matrix, for chaining.
• #### setToTransform

```public Matrix3 setToTransform(IVector translation,
float rotation,
float scale)```
Sets this to a matrix that first scales, then rotates, then translates.
Returns:
a reference to this matrix, for chaining.
• #### setToTransform

```public Matrix3 setToTransform(IVector translation,
float rotation,
IVector scale)```
Sets this to a matrix that first scales, then rotates, then translates.
Returns:
a reference to this matrix, for chaining.
• #### setToTranslation

`public Matrix3 setToTranslation(IVector translation)`
Sets this to a translation matrix.
Returns:
a reference to this matrix, for chaining.
• #### setToTranslation

```public Matrix3 setToTranslation(float x,
float y)```
Sets this to a translation matrix.
Returns:
a reference to this matrix, for chaining.
• #### setTranslation

`public Matrix3 setTranslation(IVector translation)`
Sets the translation component of this matrix.
Returns:
a reference to this matrix, for chaining.
• #### setTranslation

```public Matrix3 setTranslation(float x,
float y)```
Sets the translation component of this matrix.
Returns:
a reference to this matrix, for chaining.
• #### setToRotation

`public Matrix3 setToRotation(float angle)`
Sets this to a rotation matrix.
Returns:
a reference to this matrix, for chaining.
• #### transposeLocal

`public Matrix3 transposeLocal()`
Transposes this matrix in-place.
Returns:
a reference to this matrix, for chaining.
• #### multLocal

`public Matrix3 multLocal(pythagoras.f.IMatrix3 other)`
Multiplies this matrix in-place by another.
Returns:
a reference to this matrix, for chaining.

`public Matrix3 addLocal(pythagoras.f.IMatrix3 other)`
Adds `other` to this matrix, in place.
Returns:
a reference to this matrix, for chaining.
• #### multAffineLocal

`public Matrix3 multAffineLocal(pythagoras.f.IMatrix3 other)`
Multiplies this matrix in-place by another, treating the matricees as affine.
Returns:
a reference to this matrix, for chaining.
• #### invertLocal

`public Matrix3 invertLocal()`
Inverts this matrix in-place.
Returns:
a reference to this matrix, for chaining.
• #### invertAffineLocal

`public Matrix3 invertAffineLocal()`
Inverts this matrix in-place as an affine matrix.
Returns:
a reference to this matrix, for chaining.
• #### lerpLocal

```public Matrix3 lerpLocal(pythagoras.f.IMatrix3 other,
float t)```
Linearly interpolates between the this and the specified other matrix, placing the result in this matrix.
Returns:
a reference to this matrix, for chaining.
• #### lerpAffineLocal

```public Matrix3 lerpAffineLocal(pythagoras.f.IMatrix3 other,
float t)```
Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in this matrix.
Returns:
a reference to this matrix, for chaining.
• #### set

`public Matrix3 set(pythagoras.f.IMatrix3 other)`
Copies the contents of another matrix.
Returns:
a reference to this matrix, for chaining.
• #### set

`public Matrix3 set(float[] values)`
Copies the elements of an array.
Returns:
a reference to this matrix, for chaining.
• #### set

```public Matrix3 set(float m00,
float m10,
float m20,
float m01,
float m11,
float m21,
float m02,
float m12,
float m22)```
Sets all of the matrix's components at once.
Returns:
a reference to this matrix, for chaining.
• #### m00

`public float m00()`
Returns column 0, row 0 of the matrix.
• #### m10

`public float m10()`
Returns column 1, row 0 of the matrix.
• #### m20

`public float m20()`
Returns column 2, row 0 of the matrix.
• #### m01

`public float m01()`
Returns column 0, row 1 of the matrix.
• #### m11

`public float m11()`
Returns column 1, row 1 of the matrix.
• #### m21

`public float m21()`
Returns column 2, row 1 of the matrix.
• #### m02

`public float m02()`
Returns column 0, row 2 of the matrix.
• #### m12

`public float m12()`
Returns column 1, row 2 of the matrix.
• #### m22

`public float m22()`
Returns column 2, row 2 of the matrix.
• #### element

```public float element(int row,
int col)```
Returns the matrix element at the specified row and column.
• #### getRow

```public void getRow(int row,
Vector3 result)```
Copies the requested row (0, 1, 2) into `result`.
• #### getColumn

```public void getColumn(int col,
Vector3 result)```
Copies the requested column (0, 1, 2) into `result`.
• #### transpose

`public Matrix3 transpose()`
Transposes this matrix.
Returns:
a new matrix containing the result.
• #### transpose

`public Matrix3 transpose(Matrix3 result)`
Transposes this matrix, storing the result in the provided object.
Returns:
the result matrix, for chaining.
• #### mult

`public Matrix3 mult(pythagoras.f.IMatrix3 other)`
Multiplies this matrix by another.
Returns:
a new matrix containing the result.
• #### mult

```public Matrix3 mult(pythagoras.f.IMatrix3 other,
Matrix3 result)```
Multiplies this matrix by another and stores the result in the object provided.
Returns:
a reference to the result matrix, for chaining.

`public Matrix3 add(pythagoras.f.IMatrix3 other)`
Returns:
a new matrix containing the result.

```public Matrix3 add(pythagoras.f.IMatrix3 other,
Matrix3 result)```
Adds this matrix to another and stores the result in the object provided.
Returns:
a reference to the result matrix, for chaining.
• #### isAffine

`public boolean isAffine()`
Determines whether this matrix represents an affine transformation.
• #### multAffine

`public Matrix3 multAffine(pythagoras.f.IMatrix3 other)`
Multiplies this matrix by another, treating the matrices as affine.
Returns:
a new matrix containing the result.
• #### multAffine

```public Matrix3 multAffine(pythagoras.f.IMatrix3 other,
Matrix3 result)```
Multiplies this matrix by another, treating the matrices as affine, and stores the result in the object provided.
Returns:
a reference to the result matrix, for chaining.
• #### invert

`public Matrix3 invert()`
Inverts this matrix.
Returns:
a new matrix containing the result.
• #### invert

```public Matrix3 invert(Matrix3 result)
throws SingularMatrixException```
Inverts this matrix and places the result in the given object. This code is based on the examples in the Matrix and Quaternion FAQ.
Returns:
a reference to the result matrix, for chaining.
Throws:
`SingularMatrixException`
• #### invertAffine

`public Matrix3 invertAffine()`
Inverts this matrix as an affine matrix.
Returns:
a new matrix containing the result.
• #### invertAffine

```public Matrix3 invertAffine(Matrix3 result)
throws SingularMatrixException```
Inverts this matrix as an affine matrix and places the result in the given object.
Returns:
a reference to the result matrix, for chaining.
Throws:
`SingularMatrixException`
• #### lerp

```public Matrix3 lerp(pythagoras.f.IMatrix3 other,
float t)```
Linearly interpolates between this and the specified other matrix.
Returns:
a new matrix containing the result.
• #### lerp

```public Matrix3 lerp(pythagoras.f.IMatrix3 other,
float t,
Matrix3 result)```
Linearly interpolates between this and the specified other matrix, placing the result in the object provided.
Returns:
a reference to the result object, for chaining.
• #### lerpAffine

```public Matrix3 lerpAffine(pythagoras.f.IMatrix3 other,
float t)```
Linearly interpolates between this and the specified other matrix, treating the matrices as affine.
Returns:
a new matrix containing the result.
• #### lerpAffine

```public Matrix3 lerpAffine(pythagoras.f.IMatrix3 other,
float t,
Matrix3 result)```
Linearly interpolates between this and the specified other matrix (treating the matrices as affine), placing the result in the object provided.
Returns:
a reference to the result object, for chaining.
• #### get

`public FloatBuffer get(FloatBuffer buf)`
Places the contents of this matrix into the given buffer in the standard OpenGL order.
Returns:
a reference to the buffer, for chaining.
• #### transformLocal

`public Vector3 transformLocal(Vector3 vector)`
Transforms a vector in-place by the inner 3x3 part of this matrix.
Returns:
a reference to the vector, for chaining.
• #### transform

`public Vector3 transform(IVector3 vector)`
Transforms a vector by this matrix.
Returns:
a new vector containing the result.
• #### transform

```public Vector3 transform(IVector3 vector,
Vector3 result)```
Transforms a vector by this matrix and places the result in the object provided.
Returns:
a reference to the result, for chaining.
• #### transformPointLocal

`public Vector transformPointLocal(Vector point)`
Transforms a point in-place by this matrix.
Returns:
a reference to the point, for chaining.
• #### transformPoint

`public Vector transformPoint(IVector point)`
Transforms a point by this matrix.
Returns:
a new vector containing the result.
• #### transformPoint

```public Vector transformPoint(IVector point,
Vector result)```
Transforms a point by this matrix and places the result in the object provided.
Returns:
a reference to the result, for chaining.
• #### transformVectorLocal

`public Vector transformVectorLocal(Vector vector)`
Transforms a vector in-place by the inner 2x2 part of this matrix.
Returns:
a reference to the vector, for chaining.
• #### transformVector

`public Vector transformVector(IVector vector)`
Transforms a vector by this inner 2x2 part of this matrix.
Returns:
a new vector containing the result.
• #### transformVector

```public Vector transformVector(IVector vector,
Vector result)```
Transforms a vector by the inner 2x2 part of this matrix and places the result in the object provided.
Returns:
a reference to the result, for chaining.
• #### extractRotation

`public float extractRotation()`
Extracts the rotation component of the matrix. This uses the iterative polar decomposition algorithm described by Ken Shoemake.
• #### extractScale

`public Vector extractScale()`
Extracts the scale component of the matrix.
Returns:
a new vector containing the result.
• #### extractScale

`public Vector extractScale(Vector result)`
Extracts the scale component of the matrix and places it in the provided result vector.
Returns:
a reference to the result vector, for chaining.
• #### approximateUniformScale

`public float approximateUniformScale()`
Returns an approximation of the uniform scale for this matrix (the square root of the signed area of the parallelogram spanned by the axis vectors).
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### hashCode

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• #### equals

`public boolean equals(Object other)`
Overrides:
`equals` in class `Object`