123456789_123456789_123456789_123456789_123456789_

Class: Geom::Transformation

Relationships
Inherits: Object

Overview

Transformations are a standard construct in the 3D world for representing the position, rotation, and sizing of a given entity. In the SketchUp world, ::Sketchup::ComponentInstance and ::Sketchup::Group have a .transformation method that reports their current state and various methods (.move!, transformation=, etc.) that allow them to be manipulated.

Use of the transformation class requires a knowledge of geometrical transformations in 3 dimensions which is covered extensively on the internet.

Version:

  • SketchUp 6.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.newTransformation .new(point) ⇒ Transformation .new(vector) ⇒ Transformation .new(transform) ⇒ Transformation .new(array) ⇒ Transformation .new(scale) ⇒ Transformation .new(origin, zaxis) ⇒ Transformation .new(origin, xaxis, yaxis) ⇒ Transformation .new(pt, axis, angle) ⇒ Transformation .new(xaxis, yaxis, zaxis, origin) ⇒ Transformation

You can use this method or one of the more specific methods for creating specific kinds of Transformations.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point)

Overloads:

  • .newTransformation
  • .new(point) ⇒ Transformation

    Translates the origin to point.

    Parameters:

  • .new(vector) ⇒ Transformation

    Parameters:

  • .new(transform) ⇒ Transformation

    Creates a transformation that is a copy of another transformation. This is equivalent to #clone.

    Parameters:

    • transform (Transformation)
  • .new(array) ⇒ Transformation

    Parameters:

    • Creates (Array<Float>)

      a Transformation from a 16 element ::Array.

  • .new(scale) ⇒ Transformation
    Note:

    Versions prior to SU2018 would produce transformations which didn’t always work right in SketchUp. See .scaling for more info.

    Creates a transformation that does uniform scaling.

    Parameters:

    • scale (Float)
  • .new(origin, zaxis) ⇒ Transformation

    Creates a Transformation where origin is the new origin, and zaxis is the z axis. The x and y axes are determined using an arbitrary axis rule.

    Parameters:

  • .new(origin, xaxis, yaxis) ⇒ Transformation

    Creates a Transformation given a new origin, x axis and y axis.

    Parameters:

  • .new(pt, axis, angle) ⇒ Transformation

    Creates a Transformation that rotates by angle (given in radians) about a line defined by pt and axis.

    Parameters:

  • .new(xaxis, yaxis, zaxis, origin) ⇒ Transformation

    Parameters:

Version:

  • SketchUp 6.0

Class Method Details

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

The .axes method creates a transformation that goes from world coordinates to an arbitrary coordinate system defined by an origin and three axis vectors.

Examples:

# Creates a transformation that "flips" the axes from XYZ to XZY. Something
# one often need for importers/exporters when dealing with applications
# that threat Y as "up".
tr = Geom::Transformation.axes(ORIGIN, X_AXIS, Z_AXIS, Y_AXIS.reverse)

Overloads:

Raises:

  • (ArgumentError)

    if any of the vectors are zero length.

Version:

  • SketchUp 6.0

.interpolate(transform1, transform2, weight) ⇒ Transformation

The .interpolate method is used to create a new transformation that is the result of interpolating between two other transformations.

Parameter is a weight (between ‘0.0` and 1.0) that identifies whether to favor transformation1 or transformation2.

Examples:

origin = Geom::Point3d.new(0, 0, 0)
x = Geom::Vector3d.new(0, 1, 0)
y = Geom::Vector3d.new(1, 0, 0)
z = Geom::Vector3d.new(0, 0, 1)
point = Geom::Point3d.new(10, 20, 30)
t1 = Geom::Transformation.new(point)
t2 = Geom::Transformation.axes(origin, x, y, z)
# This produce a transformation that is a mix of 75% t1 and 25% t2.
t3 = Geom::Transformation.interpolate(t1, t2, 0.25)

Parameters:

  • transform1 (Transformation)
  • transform2 (Transformation)
  • weight (Float)

    A value between 0.0 and 1.0 (see comments).

Version:

  • SketchUp 6.0

.rotation(point, vector, angle) ⇒ Transformation

The .rotation method is used to create a transformation that does rotation about an axis.

The axis is defined by a point and a vector. The angle is given in radians.

Examples:

point = Geom::Point3d.new(10, 20, 0)
vector = Geom::Vector3d.new(0, 0, 1)
angle = 45.degrees # Return 45 degrees in radians.
transformation = Geom::Transformation.rotation(point, vector, angle)

Parameters:

Version:

  • SketchUp 6.0

.scaling(scale) ⇒ Transformation .scaling(xscale, yscale, zscale) ⇒ Transformation .scaling(point, scale) ⇒ Transformation .scaling(point, xscale, yscale, zscale) ⇒ Transformation

The .scaling method is used to create a transformation that does scaling.

Examples:

point = Geom::Point3d.new(20, 30, 0)
scale = 10
tr = Geom::Transformation.scaling(point, scale)

Overloads:

  • .scaling(scale) ⇒ Transformation
    Note:

    This has been fixed in SketchUp 2018 but in previous versions it might yield an unexpected transformation. It sets the 16th value to the scaling factor. Something not all extensions reading the transformation expects. Consider using scaling(xscale, yscale, zscale) instead.

    With one argument, it does a uniform scale about the origin.

    Parameters:

    • scale (Float)

      The global scale factor for the transform.

  • .scaling(xscale, yscale, zscale) ⇒ Transformation

    With three arguments, it does a non-uniform scale about the origin.

    Parameters:

    • xscale (Float)

      The scale factor in the x direction for the transform.

    • yscale (Float)

      The scale factor in the y direction for the transform.

    • zscale (Float)

      The scale factor in the z direction for the transform.

  • .scaling(point, scale) ⇒ Transformation

    With two arguments, it does a uniform scale about an arbitrary point.

    Parameters:

    • point (Geom::Point3d)
    • scale (Float)

      The global scale factor for the transform.

  • .scaling(point, xscale, yscale, zscale) ⇒ Transformation

    With four arguments it does a non-uniform scale about an arbitrary point.

    Parameters:

    • point (Geom::Point3d)
    • xscale (Float)

      The scale factor in the x direction for the transform.

    • yscale (Float)

      The scale factor in the y direction for the transform.

    • zscale (Float)

      The scale factor in the z direction for the transform.

Version:

  • SketchUp 6.0

.translation(vector) ⇒ Transformation .translation(point) ⇒ Transformation

The .translation method is used to create a transformation that does translation.

Examples:

vector = Geom::Vector3d.new(0, 1, 0)
tr = Geom::Transformation.translation(vector)

Overloads:

  • .translation(vector) ⇒ Transformation

    Parameters:

  • .translation(point) ⇒ Transformation

    Parameters:

Version:

  • SketchUp 6.0

Instance Attribute Details

#identity?Boolean (readonly)

Note:

As of SketchUp 2018, this now looks at the data to determine if the transformation is identity. Prior to SU2018, this only looks at the flag to see if the transform has not been modified. If the transform has been changed, this will return false even if it is really the identity.

The #identity? method is used to determine if a transformation is the IDENTITY transform.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point)
# Returns false.
status = tr.identity?
tr = Geom::Transformation.new(ORIGIN)
# Returns false.
status = tr.identity?
tr = Geom::Transformation.new
# Returns true.
status = tr.identity?
# Returns true.
status = IDENTITY.identity?

Returns:

  • (Boolean)

    true if the transformation is the identity

Version:

  • SketchUp 6.0

Instance Method Details

#*(point) ⇒ Geom::Point3d #*(vector) ⇒ Geom::Vector3d #*(transformation) ⇒ Transformation #*(point) ⇒ Array(Float, Float, Float) #*(plane) ⇒ Array(Float, Float, Float, Float) #*(plane) ⇒ Array(Float, Float, Float, Float)

The #* method is used to do matrix multiplication using the transform.

Examples:

point1 = Geom::Point3d.new(10, 20, 30)
point2 = Geom::Point3d.new(2, 2, 2)
tr = Geom::Transformation.new(point1)
# Returns Point3d(12, 22, 32)
point3 = tr * point2

Overloads:

  • #*(point) ⇒ Geom::Point3d

    Parameters:

  • #*(vector) ⇒ Geom::Vector3d

    Parameters:

  • #*(transformation) ⇒ Transformation

    Parameters:

    • transformation (Transformation)
  • #*(point) ⇒ Array(Float, Float, Float)

    Parameters:

    • point (Array(Float, Float, Float))
  • #*(plane) ⇒ Array(Float, Float, Float, Float)

    Parameters:

    Returns:

    • (Array(Float, Float, Float, Float))

      transformed plane

  • #*(plane) ⇒ Array(Float, Float, Float, Float)

    Parameters:

    • plane (Array(Float, Float, Float, Float))

    Returns:

    • (Array(Float, Float, Float, Float))

      transformed plane

Version:

  • SketchUp 6.0

#cloneTransformation

The #clone method is used to create a copy of a transformation.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr1 = Geom::Transformation.new(point)
tr2 = tr1.clone

Version:

  • SketchUp 6.0

#inverseTransformation

The #inverse method is used to retrieve the inverse of a transformation.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr1 = Geom::Transformation.new(point)
tr2 = tr1.inverse

Version:

  • SketchUp 6.0

#invert!Transformation

The #invert! method sets the transformation to its inverse.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point)
tr.invert!

Version:

  • SketchUp 6.0

#originGeom::Point3d

The #origin method retrieves the origin of a rigid transformation.

Examples:

point1 = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point1)
point2 = tr.origin

Returns:

Version:

  • SketchUp 6.0

#set!(transformation) ⇒ Transformation #set!(point) ⇒ Transformation #set!(vector) ⇒ Transformation #set!(matrix) ⇒ Transformation #set!(scale) ⇒ Transformation

The #set! method is used to set this transformation to match another one.

The argument is anything that can be converted into a transformation.

Examples:

point1 = Geom::Point3d.new(10, 20, 30)
tr1 = Geom::Transformation.new(point)
point2 = Geom::Point3d.new(60, 40, 70)
tr1.set!(point2)

Overloads:

  • #set!(transformation) ⇒ Transformation

    Parameters:

    • transformation (Transformation)
  • #set!(point) ⇒ Transformation

    Parameters:

  • #set!(vector) ⇒ Transformation

    Parameters:

  • #set!(matrix) ⇒ Transformation

    Parameters:

  • #set!(scale) ⇒ Transformation

    Parameters:

    • scale (Float)

Version:

  • SketchUp 6.0

#to_aArray<Float>

The #to_a method retrieves a 16 element array which contains the values that define the transformation.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point)
# This splits the 16 items into a string of 4x4 elements for easier reading.
str4x4 = tr.to_a.each_slice(4).inject { |str, row| "#{str}\r\n#{row}" }

Version:

  • SketchUp 6.0

#xaxisGeom::Vector3d

The #xaxis method retrieves the x axis of a rigid transformation.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point)
x = tr.xaxis

Version:

  • SketchUp 6.0

#yaxisGeom::Vector3d

The #yaxis method retrieves the y axis of a rigid transformation.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point)
x = tr.yaxis

Version:

  • SketchUp 6.0

#zaxisGeom::Vector3d

The #zaxis method retrieves the z axis of a rigid transformation.

Examples:

point = Geom::Point3d.new(10, 20, 30)
tr = Geom::Transformation.new(point)
x = tr.zaxis

Version:

  • SketchUp 6.0