Skip to content

MatrixBuilder ​

Introduction ​

The vtkMatrixBuilder class provides a system to create a mat4 transformation matrix. All functions return the MatrixBuilder Object instance, allowing transformations to be chained. Note: Contrary to vtkMath, vtkMatrixBuilder uses column-major format.

Usage ​

js
let point = [2,5,12];
vtkMatrixBuilder.buildFromDegree().translate(1,0,2).rotateZ(45).apply(point);

The vtkMatrixBuilder class has two functions, vtkMatrixBuilder.buildFromDegree() and vtkMatrixbuilder.buildFromRadian(), predefining the angle format used for transformations and returning a MatrixBuilder instance. The matrix is initialized with the Identity Matrix.

Methods ​

apply ​

Multiplies the array by the MatrixBuilder's internal matrix, in sets of 3. Updates the array in place. If specified, offset starts at a given position in the array, and nbIterations will determine the number of iterations (sets of 3) to loop through. Assumes the typedArray is an array of multiples of 3, unless specifically handling with offset and iterations. Returns the instance for chaining.

ArgumentTypeRequiredDescription
typedArrayArray[Number] or TypedArrayYesThe Array value.
offsetNumberNo
nbIterationsNumberNo

getMatrix ​

Returns the internal mat4 matrix.

identity ​

Resets the MatrixBuilder to the Identity matrix.

invert ​

Inverts the MatrixBuilder matrix.

multiply ​

ArgumentTypeRequiredDescription
mat4x4mat4Yes

multiply3x3 ​

Multiply the current matrix with the provided 3x3 matrix.

ArgumentTypeRequiredDescription
mat3x3mat3Yescolumn-first matrix

new ​

ArgumentTypeRequiredDescription
useDegreeBooleanNo

rotate ​

Normalizes the axis of rotation then rotates the current matrix angle degrees/radians around the provided axis.

ArgumentTypeRequiredDescription
angleNumberYes
axisVector3Yes

rotateFromDirections ​

Multiplies the current matrix with a transformation matrix created by normalizing both direction vectors and rotating around the axis of the crossProduct by the angle from the dotProduct of the two directions.

ArgumentTypeRequiredDescription
originDirectionArray[Number]Yes
targetDirectionArray[Number]Yes

rotateX ​

Rotates angle degrees/radians around the X axis.

ArgumentTypeRequiredDescription
angleNumberYes

rotateY ​

Rotates angle degrees/radians around the Y axis.

ArgumentTypeRequiredDescription
angleNumberYes

rotateZ ​

Rotates angle degrees/radians around the Z axis.

ArgumentTypeRequiredDescription
angleNumberYes

scale ​

Scales the matrix by sx, sy, sz.

ArgumentTypeRequiredDescription
sxNumberYes
syNumberYes
szNumberYes

setMatrix ​

Copies the given mat4 into the builder. Useful if you already have a transformation matrix and want to transform it further. Returns the instance for chaining.

ArgumentTypeRequiredDescription
mat4x4mat4Yes

translate ​

Translates the matrix by x, y, z.

ArgumentTypeRequiredDescription
xNumberYesThe x coordinate.
yNumberYesThe y coordinate.
zNumberYesThe z coordinate.