Skip to content

Matrix

Matrix

See Javadoc of Matrix3f and Javadoc of Matrix4f

Definition

A matrix can represent a linear transformation of a vector: Y = MX. A 3×3 matrix can represent 3D rotation and scale. A 4×4 homogeneous matrix can additionally represent translation as part of an affine transform.

There are a few special matrices:

zero matrix is the Matrix with all zero entries.

0 0 0
0 0 0
0 0 0

The Identity Matrix is the matrix with 1 on the diagonal entries and 0 for all other entries.

1 0 0
0 1 0
0 0 1

A Matrix is invertible if there is a matrix M-1 where MM-1 = M-1M = I.

The transpose of a matrix M = [mij] is MT = [mji]. This causes the rows of M to become the columns of MT.

1 1 1 1 2 3
2 2 2 ⇒ 1 2 3
3 3 3 1 2 3

A Matrix is symmetric if M = MT.

X A B
A X C
B C X

Where X, A, B, and C equal numbers

jME includes two types of Matrix classes: Matrix3f and Matrix4f. Matrix3f is a 3x3 matrix and is the most commonly used (able to handle scaling and rotating), while Matrix4f is a 4x4 matrix that can also handle translation.

Transformations

Multiplying a Vector with a Matrix allows the Vector to be transformed. Either rotating, scaling or translating that Vector.

Scaling

If a diagonal Matrix, defined by D = [dij] and dij = 0 for i != j, has scale factors on the diagonal, it is a scaling matrix. A factor greater than 1 enlarges that component; a factor between 0 and 1 shrinks it. Negative factors also reflect the corresponding axis.

Rotation

A 3D rotation matrix is orthogonal (R⁻¹ = Rᵀ) and has determinant +1. Given a unit rotation axis u = (uₓ, uᵧ, u𝓏) and angle θ, Rodrigues' formula is R = I + sin(θ) S + (1 − cos(θ)) S², where:

0 −u𝓏 uᵧ
u𝓏 0 −uₓ
−uᵧ uₓ 0

The sign convention corresponds to the cross product S v = u × v.

Translation

Translation requires a 4x4 matrix, where the Vector (x,y,z) is mapped to (x,y,z,1) for multiplication. The Translation Matrix is then defined as:

M T
0 0 0 1

Here M is the 3×3 linear part, T is the translation column, and the bottom row is (0, 0, 0, 1).

jME Class

Both Matrix3f and Matrix4f store their values as floats and are publicly available as (m00, m01, m02, …, mNN) where N is either 2 or 3.

Most methods are straight forward, and I will leave documentation to the Javadoc.