[Molby Document Home] [Contents]

Class: | Transform
Parent: | Object

### Description

The class Transform represents a three-dimensional transform matrix.

### Public Class methods

Transform[*args] → (new) Transform

Create a new transform. Equivalent to Transform.new(args).

diagonal(Array)
diagonal(f1, f2 = nil, f3 = nil)

Returns a diagonal transform (the translational componets are all 0). In the first form, `array[0], array[1], array[2]` are for the x, y, z components, respectively. In the second form, `f1, f2, f3` are the x, y, z components. If `f3` is not given, the `f2` is used for the z components. If `f2` is not given, the `f1` is used for the y and z components.

from_columns(c1, c2, c3, c4)

Returns a new Transform built from four column vectors. The arguments `c1..c4` are vectors of (at least) three-dimension. This is equivalent to `Transform.new([c1, c2, c3, c4])`.

from_rows(r1, r2, r3)

Returns a new Transform built from three row vectors. The arguments `r1, r2, r3` are vectors of (at least) four-dimension.

identity → Transform

Returns an identity transform, `[[1,0,0], [0,1,0], [0,0,1], [0,0,0]]`.

inversion(center = [0,0,0]) → (new) Transform

Returns a transform corresponding to the inversion along the given center.

new
new(array)
new(matrix)

Returns a new Transform.

In the first form, an identity transform is returned.

In the second form, the array must be either of the following two forms: (1) [[a11 a21 a31] [a12 a22 a32] [a13 a23 a33] [a14 a24 a34]] (2) [a11 a21 a31 a12 a22 a32 a13 a23 a33 a14 a24 a34] where [a11..a33] denotes the rotation/reflexion part and [a14 a24 a34] denotes the translation part. All vectors in (1) are column vectors.

In the third form, a new transform is built from a 3x4 matrix. The argument `matrix` must respond to a method call `matrix[col, row]` where `row` is in `0..2` and `col` in `0..3`.

reflection(axis, center = [0,0,0]) → (new)Transform

Returns a transform corresponding to the reflection along the plane that is orthogonal to the axis and includes center.

rotation(vec, angle, center = [0,0,0]) → (new) Transform

Returns a transform corresponding to the rotation of angle (in degree) along the axis that is parallel to the given vec and includes center.

rotation_with_axis(ax, ay, cx = Vector3D[0,0,0])

Give the Transform that translates cx to origin and rotates ax->x and ay->y. Ax and ay will be normalized, and if ax and ay are not perpendicular, (ax.cross(ay)).cross(ax).normalize is used instead of ay.

translation(vec) → (new) Transform

Returns a Transform corresponding to translation along the given vector. Equivalent to `Transform[[1,0,0],[0,1,0],[0,0,1],vec]`.

zero → Transform

Returns a zero transform, `[[0,0,0], [0,0,0], [0,0,0], [0,0,0]]`.

### Public Instance methods

self * numeric → (new) Transform
self * Vector3D → (new) Vector3D
self * other_transform → (new) Transform

Perform the matrix multiplication. In the first form, a new matrix with scaled elements is returned. In the second, the transformed vector is returned. In the third form, the multiple of the two matrices is returned.

self + val → (new) Transform

Returns a new transform corresponding to the sum of the two transform matrix.

self - val → (new) Transform

Returns a new transform corresponding to the difference of the two transform matrix.

self / val → (new) Transform

Returns self * val.invert. If val is not a regular transform, an exception is raised.

self == val → bool

Returns `true` if and only if all the corresponding elements are equal. Usual caution about the comparison of floating-point numbers should be paid.

self[i, j] → Float

Get the element (`i`,`j`) of the transform matrix, i.e. column `i`, row `j`. Be careful about the order of the arguments. It follows convention of multi-dimensional arrays rather than mathematical notation.

self[i, j] = val

Set the element (`i`,`j`) of the transform matrix, i.e. column `i`, row `j`. Be careful about the order of the arguments. It follows convention of multi-dimensional arrays rather than mathematical notation.

column(index) → Vector3D

Returns the index-th (0..3) column vector.

determinant → Float

Returns the determinant of the transform.

eigenvalues → [[k1, k2, k3], v1, v2, v3]

Calculate the eigenvalues and eigenvectors. The matrix must be symmetric.

inspect → String

Convert a transform to a string like "Transform[[a11,a21,a31],[a12,a22,a32],[a13,a23,a33],[a14,a24,a34]]".

inverse → (new) Transform

Returns the inverse transform. If the matrix is not regular, an exception is raised.

to_a → Array

Convert a transform to an array of 12 float numbers.

to_rot → [axis, angle]

Decompose a rotation matrix to the axis and angle. Returns a list [axis, angle]

to_s → String

Alias for inspect

to_spiral → [axis, angle, center, pitch]

Decompose a rotation matrix to spiral components.

trace → Float

Returns the trace (sum of the diagonal elements) of the transform.

transpose → (new) Transform

Returns a new transform in which the rotation component is transposed from the original.