ModraUp Ruby API Documentation Ruby API Reference

Class: Geom::Transformation

Inherits:
Object
  • Object
show all

Overview

A column-major 4 × 4 matrix for translation, rotation, scaling, and composition by matrix multiplication.

Examples:

t = Geom::Transformation.translation(1, 0, 0)
t.origin.to_a  #=> [1.0, 0.0, 0.0]

Class Method Summary # collapse

Instance Method Summary # collapse

Class Method Details

Transformation.new ⇒ transformationTransformation.new(point) ⇒ transformationTransformation.new(vector) ⇒ transformationTransformation.new(transformation) ⇒ transformationTransformation.new(array16) ⇒ transformationTransformation.new(scale) ⇒ transformationTransformation.new(origin, zaxis) ⇒ transformationTransformation.new(origin, xaxis, yaxis) ⇒ transformationTransformation.new(origin, axis, angle) ⇒ transformationTransformation.new(xaxis, yaxis, zaxis, origin) ⇒ transformation

With no arguments, constructs the identity. A point or vector specifies translation, a single number specifies uniform scaling, and an existing transformation is copied. An array of 16 numbers supplies a column-major matrix. With an origin and zaxis, the arbitrary-axis rule supplies X and Y. With three arguments, a numeric third argument specifies rotation about an axis in radians. Otherwise the arguments specify an origin and X and Y axes. Four arguments specify the X, Y, and Z axes followed by the origin. Axes specify directions only. To include scale in a matrix, use the 16-element array.

Parameters:

  • point (Geom::Point3d, Geom::Vector3d, Geom::Transformation, Array<Numeric>, Numeric)

Returns:

  • (Geom::Transformation)

Raises:

  • [ArgumentError] The axis vector has a length of zero

Examples:

Geom::Transformation.new.identity?

Translation

Geom::Transformation.new(Geom::Point3d.new(1, 2, 3)).origin.to_a
#=> [1.0, 2.0, 3.0]

Non-unit axes only take direction.

t = Geom::Transformation.new([10, 0, 0], [0, 20, 0], [0, 0, 30], ORIGIN)
t.to_a[0]  #=> 1.0

Transformation.translation(point) ⇒ transformationTransformation.translation(vector) ⇒ transformationTransformation.translation(x, y, z) ⇒ transformation

Translation.

Parameters:

  • point (Geom::Point3d, Geom::Vector3d, Numeric)

Returns:

  • (Geom::Transformation)

Examples:

Geom::Transformation.translation(0, 10, 0).origin.to_a  #=> [0.0, 10.0, 0.0]

Vector

Geom::Transformation.translation(Geom::Vector3d.new(0, 0, 0)).identity?

Transformation.rotation(origin, axis, angle) ⇒ transformation

Rotates by angle radians around an axis passing through origin with direction axis.

Parameters:

  • origin (Geom::Point3d)
  • axis (Geom::Vector3d, Geom::Point3d)
  • angle (Numeric) radians

Returns:

  • (Geom::Transformation)

Examples:

Geom::Transformation.rotation(Geom::ORIGIN, [0, 0, 1], Math::PI)

Transformation.scaling(scale) ⇒ transformationTransformation.scaling(xscale, yscale, zscale) ⇒ transformationTransformation.scaling(origin, scale) ⇒ transformationTransformation.scaling(origin, xscale, yscale, zscale) ⇒ transformation

Uniform or axis-aligned scaling; scale about a point when an origin is specified.

Parameters:

  • scale (Numeric, Geom::Point3d)

Returns:

  • (Geom::Transformation)

Examples:

Geom::Transformation.scaling(Geom::ORIGIN, 2, 1, 1).to_a[0]  #=> 2.0

Transformation.axes(origin, xaxis, yaxis) ⇒ transformationTransformation.axes(origin, xaxis, yaxis, zaxis) ⇒ transformation

Construct a coordinate system transformation from the origin and axis vectors. Omitting zaxis uses X×Y. Axes are normalized to be orthogonal directions, with length not scaling (same as SketchUp Transformation.axes). For scaling, use a 16-element array to construct the matrix.

Parameters:

  • origin (Geom::Point3d)
  • xaxis (Geom::Vector3d)
  • yaxis (Geom::Vector3d)
  • zaxis (Geom::Vector3d)

Returns:

  • (Geom::Transformation)

Raises:

  • [ArgumentError] Any axis vector length is zero

Examples:

t = Geom::Transformation.axes(Geom::ORIGIN, Geom::X_AXIS, Geom::Y_AXIS)
t.zaxis.to_a  #=> [0.0, 0.0, 1.0]

Non-unit axes only take direction.

t = Geom::Transformation.axes(ORIGIN, [10, 0, 0], [0, 20, 0], [0, 0, 30])
t.to_a[0]  #=> 1.0

Transformation.interpolate(transformation1, transformation2, weight) ⇒ transformation

Linearly interpolate matrix elements between two transformations based on weight (0..1).

Parameters:

  • transformation1 (Geom::Transformation)
  • transformation2 (Geom::Transformation)
  • weight (Numeric)

Returns:

  • (Geom::Transformation)

Examples:

a = Geom::Transformation.translation(0, 0, 0)
b = Geom::Transformation.translation(10, 0, 0)
Geom::Transformation.interpolate(a, b, 0.5).origin.x  #=> 5.0

Instance Method Details

transformation.to_a ⇒ Array<Numeric>

16 numbers, in column-major order.

Returns:

  • (Array<Numeric>)

Examples:

Geom::Transformation.new.to_a.length  #=> 16

transformation.origin ⇒ Geom::Point3d

The translation component.

Returns:

  • (Geom::Point3d)

Examples:

Geom::Transformation.translation(1, 2, 3).origin.to_a  #=> [1.0, 2.0, 3.0]

transformation.xaxis ⇒ Geom::Vector3d

The X-axis of the rigid transformation (matrix first column, includes scaling).

Returns:

  • (Geom::Vector3d)

Examples:

Geom::Transformation.new.xaxis.to_a  #=> [1.0, 0.0, 0.0]

transformation.yaxis ⇒ Geom::Vector3d

The Y-axis of the rigid transformation (matrix second column, including scaling).

Returns:

  • (Geom::Vector3d)

Examples:

Geom::Transformation.new.yaxis.to_a  #=> [0.0, 1.0, 0.0]

transformation.zaxis ⇒ Geom::Vector3d

The Z-axis of the rigid transformation (matrix's third column, including scaling).

Returns:

  • (Geom::Vector3d)

Examples:

Geom::Transformation.new.zaxis.to_a  #=> [0.0, 0.0, 1.0]

transformation.rotx ⇒ Numeric

Euler angle rotation around the X-axis in degrees.

Dynamic Components loaded afterward will override this method.

Returns:

  • (Numeric)
Note: ModraUp extension. SketchUp's Geom::Transformation does not have rotx.

Examples:

Geom::Transformation.new.rotx  #=> 0.0

transformation.roty ⇒ Numeric

Euler angle rotation around the Y-axis in degrees.

Dynamic Components loaded afterward will override this method.

Returns:

  • (Numeric)
Note: ModraUp extension. SketchUp's Geom::Transformation does not have roty.

Examples:

Geom::Transformation.new.roty  #=> 0.0

transformation.rotz ⇒ Numeric

Euler angle rotation around the Z-axis, in degrees.

Dynamic Components loaded afterward will override this method.

Returns:

  • (Numeric)
Note: ModraUp extension. SketchUp's Geom::Transformation does not have rotz.

Examples:

Geom::Transformation.new.rotz  #=> 0.0

transformation.identity? ⇒ Boolean

Returns whether the transformation is an identity matrix.

Returns:

  • (Boolean)

Examples:

Geom::Transformation.new.identity?

transformation.inverse ⇒ Geom::Transformation

Inverse transformation. Throws an error if not invertible.

Returns:

  • (Geom::Transformation)

Raises:

  • [ArgumentError] Not invertible

Examples:

t = Geom::Transformation.translation(1, 0, 0)
(t * t.inverse).identity?

transformation.invert! ⇒ self

Inverts the transformation in place. Raises an error if inversion is not possible.

Returns:

  • (Geom::Transformation)

Raises:

  • [ArgumentError] Not invertible

Examples:

t = Geom::Transformation.translation(1, 0, 0)
t.invert!
t.origin.x  #=> -1.0

transformation.clone ⇒ Geom::Transformation

Clones a transformation.

Returns:

  • (Geom::Transformation)

Examples:

a = Geom::Transformation.translation(1, 0, 0)
b = a.clone
b.origin.to_a  #=> [1.0, 0.0, 0.0]

transformation.set!(other) ⇒ self

Overwrite itself with another transformation, point (translation), vector (translation), 16-element array, or uniform scale factor.

Parameters:

  • other (Geom::Transformation, Geom::Point3d, Geom::Vector3d, Array<Numeric>, Numeric)

Returns:

  • (Geom::Transformation)

Examples:

t = Geom::Transformation.new
t.set!(Geom::Point3d.new(4, 5, 6))
t.origin.to_a  #=> [4.0, 5.0, 6.0]

transformation * other ⇒ Geom::Transformation, Geom::Point3d, Geom::Vector3d, Array<Numeric>

Multiply by another transformation, point, vector, [x, y, z], or plane (quadruple [a, b, c, d] / [point, normal]).

Parameters:

  • other (Geom::Transformation, Geom::Point3d, Geom::Vector3d, Array<Numeric>)

Returns:

  • (Geom::Transformation, Geom::Point3d, Geom::Vector3d, Array<Numeric>)

Raises:

  • [ArgumentError] The matrix is non-invertible when transforming the plane.

Examples:

t = Geom::Transformation.translation(1, 0, 0)
(t * Geom::ORIGIN).to_a  #=> [1.0, 0.0, 0.0]