Collection of static utilities

Static methods

staticlargestEig2x2(m1:Float, m12:Float, m2:Float):Vec3

"Compute largest eigenvalue and associated eigenvector of a symmetric 2x2 matrix. Solves characteristic equation. Inputs: three elements of matrix (upper-left, diag, lower-right) Outputs: largest (in magnitude) eigenvector/value" -- Trimesh2

staticldltdc(A:Array<Array<Float>>, rdiag:Array<Float>):Bool

"LDL^T decomposition of a symmetric positive definite matrix (and some other symmetric matrices, but fragile since we don't do pivoting). Like Cholesky, but no square roots, which is important for small N. Reads diagonal and upper triangle of matrix A. On output, lower triangle of A holds LD, while rdiag holds D^-1. Algorithm from Golub and van Loan." -- Trimesh2

staticldltsl(A:Array<Array<Float>>, rdiag:Array<Float>, b:Array<Float>, x:Array<Float>):Void

"Solve Ax=b after ldltdc. x is allowed to be the same as b." -- Trimesh

staticinlinematIden():Array<Float>

Returns a 4x4 identiy matrix (row-major, flat)

Returns:

the identity matrix

staticinlinematMult(A:Array<Float>, B:Array<Float>):Array<Float>

Multiply two 4x4 matrices (row-major, flat)

Parameters:

A

first matrix

B

second matrix

Returns:

the matrix product

staticinlinematProj(f:Float, v:Vec3):Vec3

Project a 3D point onto 2D plane with pinhole camera model situated at (0,0,0) pointing toward +z

Parameters:

f

focal length

v

the vector

Returns:

a 2D point (with zeroed z component)

staticinlinematRotx(a:Float):Array<Float>

Returns a 4x4 matrix for rotating around x axis (row-major, flat)

Parameters:

a

the angle in radians

Returns:

the rotation matrix

staticinlinematRoty(a:Float):Array<Float>

Returns a 4x4 matrix for rotating around y axis (row-major, flat)

Parameters:

a

the angle in radians

Returns:

the rotation matrix

staticinlinematRotz(a:Float):Array<Float>

Returns a 4x4 matrix for rotating around z axis (row-major, flat)

Parameters:

a

the angle in radians

Returns:

the rotation matrix

staticinlinematScal(x:Float, y:Float, z:Float):Array<Float>

Returns a 4x4 scaling matrix (row-major, flattend)

Parameters:

x

scale along x axis

y

scale along x axis

z

scale along x axis

Returns:

the scaling matrix

staticinlinematTrfm(A:Array<Float>, v:Vec3):Vec3

Transform a 3D vector using a 4x4 matrix (row-major, flat)

Parameters:

A

the transformation matrix

v

the vector

Returns:

new vector after transformation

staticinlinematTrsl(x:Float, y:Float, z:Float):Array<Float>

Returns a 4x4 translation matrix (row-major, flat)

Parameters:

x

translation along x axis

y

translation along x axis

z

translation along x axis

Returns:

the translation matrix

staticinlinemin(a:Int, b:Int):Int

MIN() for integers

Parameters:

a

first integer

b

second integer

Returns:

the lesser of the inputs

staticinlinenextMod3(i:Int):Int

i + 1 modulo 3. "This way of computing it tends to be faster than using %" -- Trimesh2

staticinlineprevMod3(i:Int):Int

i - 1 modulo 3. "This way of computing it tends to be faster than using %" -- Trimesh2

staticinlinerndInt(x:Float):Int

Round float to integer

Parameters:

x

the float to be rounded

Returns:

closest integer

staticinlinesq(x:Float):Float

Square a float (x^2)

Parameters:

x

the float

Returns:

the square

staticinlinetrinorm(v0:Vec3, v1:Vec3, v2:Vec3):Vec3

"Area-weighted triangle face normal" -- RTSC

staticinlineuniformHemisphereSampler():Vec3

Uniform random sampler on unit hemisphere (+z)

Returns:

a random point that lies on the hemisphere

staticwriteFile(filename:String, content:String):Void

Save a string to a file on disk

Parameters:

filename

path to the file

content

content to be written