package OCADml

  1. Overview
  2. Docs

Module OCADml.Affine3Source

Affine transformation matrices for transforming 3d vectors (V3.t), and 3d shapes.

A 3d affine transformation matrix.

Sourcetype row = float * float * float * float
Sourcetype t = Gg.m4
Sourceval id : t

The identity matrix.

Basic Matrix Operations

Sourceval mul : t -> t -> t

mul a b

Multiply the matrices a and b.

Sourceval add : t -> t -> t

add a b

Element by element addition of the matrices a and b.

Sourceval sub : t -> t -> t

sub a b

Element by element subtraction of the matrix b from a.

Sourceval emul : t -> t -> t

emul a b

Element by element multiplication of the matrices a and b.

Sourceval ediv : t -> t -> t

ediv a b

Element by element division of the matrix a by b.

Sourceval smul : t -> float -> t

smul t s

Multiply each element of the matrix t by the scalar s.

Sourceval sdiv : t -> float -> t

sdiv t s

Divide each element of the matrix t by the scalar s.

Sourceval sadd : t -> float -> t

sadd t s

Add the scalar s to each element of the matrix t.

Sourceval ssub : t -> float -> t

ssub t s

Subtract the scalar s to from each element of the matrix t.

Sourceval transpose : t -> t

transpose t

Transpose the rows and columns of t.

Sourceval map : (float -> float) -> t -> t

map f t

Apply the function f to all elements of t.

Sourceval trace : t -> float

trace t

Sum the elements on the main diagonal (upper left to lower right) of t.

Sourceval get : t -> int -> int -> float

get t r c

Get the element at row and column of t. Equivalent to t.(r).(c). Raises Invalid_argument if access is out of bounds.

Sourceval compose : t -> t -> t

compose a b

Compose the affine transformations a and b. Equivalent to mul b a, which when applied, will perform the transformation a, then the transformation b.

Sourceval (%>) : t -> t -> t

a %> b

Alias to compose.

Sourceval (%) : t -> t -> t

a % b

Mathematical composition of affine transformations a and b, equivalent to mul a b.

Construction

Sourceval v : float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> float -> t

v e00 e01 e02 e03 e10 e11 e12 e13 e20 e21 e22 e23 e30 e31 e32 e33

Create a 2d affine matrix from elements in row major order.

Construction by Rows

Sourceval of_rows : row -> row -> row -> t

of_rows rows

Create an affine transformation matrix from three rows. The last row is set to 0., 0., 0., 1..

Sourceval of_row_matrix_exn : float array array -> t

of_row_matrix_exn m

Convert the float matrix m into a t if it is the correct shape (4 x 4), otherwise raise Invalid_argument.

Sourceval of_row_matrix : float array array -> (t, string) result

of_row_matrix m

Convert the float matrix m into a t if it is the correct shape (4 x 4).

Element Accessors

Sourceval e00 : t -> float
Sourceval e01 : t -> float
Sourceval e02 : t -> float
Sourceval e03 : t -> float
Sourceval e10 : t -> float
Sourceval e11 : t -> float
Sourceval e12 : t -> float
Sourceval e13 : t -> float
Sourceval e20 : t -> float
Sourceval e21 : t -> float
Sourceval e22 : t -> float
Sourceval e23 : t -> float
Sourceval e30 : t -> float
Sourceval e31 : t -> float
Sourceval e32 : t -> float
Sourceval e33 : t -> float

Transforms

Sourceval scale : V3.t -> t

scale v

Create an affine transformation matrix from the xyz scaling vector v.

Sourceval xscale : float -> t

xscale x

Create a 2d affine transformation matrix that applies x-axis scaling.

Sourceval yscale : float -> t

yscale y

Create a 2d affine transformation matrix that applies y-axis scaling.

Sourceval zscale : float -> t

zscale z

Create a 2d affine transformation matrix that applies z-axis scaling.

Sourceval translate : V3.t -> t

translate v

Create an affine transformation matrix from the xyz translation vector v.

Sourceval xtrans : float -> t

xtrans x

Create an affine transformation matrix that applies a translation of x distance along the x-axis.

Sourceval ytrans : float -> t

ytrans y

Create an affine transformation matrix that applies a translation of y distance along the y-axis.

Sourceval ztrans : float -> t

ztrans z

Create an affine transformation matrix that applies a translation of z distance along the z-axis.

Sourceval mirror : V3.t -> t

mirror ax

Create an affine transformation matrix that applies a reflection across the axis ax.

Sourceval xrot : ?about:V3.t -> float -> t

xrot ?about r

Create an affine transformation matrix that applies a x-axis rotation of r radians around the origin (or the point about if provided).

Sourceval yrot : ?about:V3.t -> float -> t

yrot ?about r

Create an affine transformation matrix that applies a y-axis rotation of r radians around the origin (or the point about if provided).

Sourceval zrot : ?about:V3.t -> float -> t

zrot ?about r

Create an affine transformation matrix that applies a z-axis rotation of r radians around the origin (or the point about if provided).

Sourceval rotate : ?about:V3.t -> V3.t -> t

rotate ?about r

Create an affine transformation matrix that applies the euler (zyx) rotation represented by r radians around the origin (or the point about if provided).

Sourceval axis_rotate : ?about:V3.t -> V3.t -> float -> t

axis_rotate ?about ax r

Create an affine transfomation matrix that applies a rotation of r radians around the axis ax through the origin (or the point about if provided).

Sourceval align : V3.t -> V3.t -> t

align a b

Compute an affine transformation matrix that would bring the vector a into alignment with b.

Sourceval skew : ?xy:float -> ?xz:float -> ?yx:float -> ?yz:float -> ?zx:float -> ?zy:float -> unit -> t

skew ?xy ?xz ?yx ?yz ?zx ?zy ()

Create an affine transformation matrix that applies a skew transformation with the given skew factor multipliers. Factors default to 0. if not provided.

  • xy: skew along the x-axis as you get farther from the y-axis
  • xz: skew along the x-axis as you get farther from the z-axis
  • yx: skew along the y-axis as you get farther from the x-axis
  • yz: skew along the y-axis as you get farther from the z-axis
  • zx: skew along the z-axis as you get farther from the x-axis
  • zy: skew along the z-axis as you get farther from the y-axis
Sourceval skew_xy : float -> float -> t

skew_xy xa ya

Create an affine transformation matrix that applies a skew transformation along the xy plane.

  • xa: skew angle (in radians) in the direction of the x-axis
  • ya: skew angle (in radians) in the direction of the y-axis
Sourceval skew_xz : float -> float -> t

skew_xz xa za

Create and affine transformation matrix that applies a skew transformation along the xz plane.

  • xa: skew angle (in radians) in the direction of the x-axis
  • za: skew angle (in radians) in the direction of the z-axis
Sourceval skew_yz : float -> float -> t

skew_yz ya za

Create and affine transformation matrix that applies a skew transformation along the yz plane.

  • ya: skew angle (in radians) in the direction of the y-axis
  • za: skew angle (in radians) in the direction of the z-axis
Sourceval transform : t -> V3.t -> V3.t

transform t v

Apply the affine transformation matrix t to the vector v.

Output

Sourceval to_string : t -> string

to_string t

Convert the matrix t to a simple string representation compatible with OpenSCAD multmatrix.

Conversions

Sourceval project : t -> Affine2.t

project t

Project t down into a 2d affine transformation matrix (z axis components dropped).

Sourceval of_quaternion : ?trans:V3.t -> Quaternion.t -> Affine3.t

of_quaternion q

Create an affine transformation matrix equivalent to the quaternion q.