Transformations are a standard construct in the 3D world for representing
the position, rotation, and sizing of a given entity. In the SketchUp
world, Components and Groups 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.
The * method is used to do matrix multiplication using the Transform.
Arguments:
Returns:
point = Geom::Point3d.new 10,20,30 point2 = Geom::Point3d.new 2,2,2 t = Geom::Transformation.new point point3 = t * point2 UI.messagebox point3
The axes method creates a Transformation that goes from world coordinates to an arbitrary coordinate system defined by an origin and three axis vectors.
Arguments:
Returns:
t = Geom::Transformation.axes origin, xaxis, yaxis, zaxis UI.messagebox t
The clone method is used to create a copy of a transformation.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point t2 = t.clone UI.messagebox t2
The identity? method is used to determine if a transformation is the identity transform.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point status = t.identity? UI.messagebox status
The interpolate method is used to create a new transformation that is the
result of interpolating between two other transformations.
Parameter is a percent (between 0 and 1) that identifies whether to favor
transformation1 or transformation2.
Arguments:
Returns:
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 t3 = Geom::Transformation.interpolate t1, t2, 25 UI.messagebox t3
The inverse method is used to retrieve the inverse of a transformation.
Returns:
transformation2 = transformation1.inverse
The invert! method sets the transformation to its inverse.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point t2 = t.invert! UI.messagebox t2
The new method is used to create a new transformation.
You can use this method or one of the more specific methods for creating
specific kinds of Transformations.
Geom::Transformation.new with no
arguments creates a new identify
Transformation.
Geom::Transformation.new(pt) creates a Transformation
that translates the origin to pt.
Geom::Transformation.new(vec) creates a
Transformation that translates by vector
vec.
Geom::Transformation.new(transform) creates a Transformation that is
a copy of another Transformation. This is equivalent to
transform.clone.
Geom::Transformation.new(array) creates a Transformation
from a 16 element Array.
Geom::Transformation.new(scale) creates a
Transformation that does uniform scaling.
Geom::Transformation.new(origin, zaxis) 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.
Geom::Transformation.new(pt, xaxis, yaxis) creates a Transformation given
a new origin, x axis and y axis.
Geom::Transformation.new(pt, axis, angle) creates a Transformation
that rotates by angle (given in radians) about a line defined by pt and
axis.
Geom::Transformation.new(xaxis, yaxis, zaxis, origin) creates a
Transformation from 3 axes and an origin.
Arguments:
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point if (t) UI.messagebox else UI.messagebox "Failure" end
The origin method retrieves the origin of a rigid transformation.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point point2 = t.origin UI.messagebox point2
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.
Arguments:
Returns:
transformation = Geom::Transformation.rotation point, vector, angle
The scaling method is used to create a Transformation that does scaling.
Arguments:
Returns:
t = Geom::Transformation.scaling 10 UI.messagebox t
The set! method is used to set this transformation to match another one.
The argument is anything that can be converted into a Transformation.
Arguments:
Returns:
transformation1 = transformation1.set! transformation2
The to_a method retrieves a 16 element array which contains the values that define the Transformation.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point a = t.to_a UI.messagebox a
The translation method is used to create a transformation that does translation.
Arguments:
Returns:
vector = Geom::Vector3d.new 0,1,0 t = Geom::Transformation.translation vector UI.messagebox t
The xaxis method retrieves the x axis of a rigid transformation.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point x = t.xaxis UI.messagebox x
The yaxis method retrieves the y axis of a rigid transformation.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point y = t.yaxis UI.messagebox y
The yaxis method retrieves the z axis of a rigid transformation.
Returns:
point = Geom::Point3d.new 10,20,30 t = Geom::Transformation.new point z = t.zaxis UI.messagebox z