|
SketchUp Ruby API Reference |
The transformation class serves two purposes. First, the transformation class allows you to initially place geometry in a 3d space, such as when placing a component instance within the draw area. Second, and foremost, the transformation class can be used to apply transformations on geometry, such as a move (called a translation), rotate, or scale of geometry (just as you might move, rotate, and scale geometry within the SketchUp user interface). Use of the transformation class require a knowledge of geometrical transformations in 3 dimensions which is covered extensively on the Internet.
Parent: Object
Methods: axes, interpolate, new, rotation, scaling, translation, *, clone, identity?, inverse, invert!, origin, set!, to_a, xaxis, yaxis, zaxis
Example Code:transformationtests.rb
The axes method is used to create a Transformation that goes from world coordinates to an arbitrary coordinate system defined by an origin and three axis vectors.
transformation = Geom::Transformation.axes origin, xaxis, yaxis, zaxis
origin - a Point3d object representing the origin (0,0,0 point of the arbitrary coordinate system)
xaxis - a Vector3d object representing the direction of the x axis.
yaxis - a Vector3d object representing the direction of the y axis.
zaxis - a Vector3d object representing the direction of the z axis.
transformation - a new Transformation object
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
trans = Geom::Transformation.axes origin, x, y, z
UI.messagebox trans
The interpolate method is used to create a new transformation that is the result of interpolating between two other transformations.
transformation3 = Geom::Transformation.interpolate transformation1, transformation2, parameter
transformation1 - a Transformation object
transformation2 - a Transformation object
parameter - a value between 0 and 1 (see comments)
transformation3 - the new Transformation object
Parameter is a percent (between 0 and 1) that identifies whether to favor transformation1 or transformation2.
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 new method is used to create a new transformation.
transformation = Geom::Transformation.new
transformation = Geom::Transformation.new point
transformation = Geom::Transformation.new vector
transformation = Geom::Transformation.new transformation
transformation = Geom::Transformation.new array
transformation = Geom::Transformation.new scale
transformation = Geom::Transformation.new origin, zaxis
transformation = Geom::Transformation.new point, xaxis, yaxis
transformation = Geom::Transformation.newpoint, axis, angle
transformation = Geom::Transformation.new xaxis, yaxis, zaxis, origin
point - a Point3d object
vector - a Vector3d object
transformation - a Transformation object
array - an Array object
scale - a single numeric values used to set a global scale factor for the transform
origin - a Point3d object representing the origin (0,0,0 point of the arbitrary coordinate system)
xaxis - a Vector3d object representing the direction of the x axis.
yaxis - a Vector3d object representing the direction of the y axis.
zaxis - a Vector3d object representing the direction of the z axis.
tranformation - a new Transformation object
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) create 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.
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
if (t)
UI.messagebox
else
UI.messagebox "Failure"|
end
The rotation method is used to create a Transformation that does rotation about an axis.
transformation = Geom::Transformation.rotation point, vector, angle
point - a Point3d object
vector - a Vector3d object
angle - a numeric value, expressed in radians, that specifies the angle to rotate about the axis set by the second parameter
transformation - a new Transformation object
The axis is defined by a point and a vector. The angle is given in radians.
point = Geom::Point3d.new 0,0,0
vector = Geom::Vector3d.new 0,1,0
angle = 25
t = Geom::Transformation.rotation point, vector, angle
UI.messagebox t
The scaling method is used to create a Transformation that does scaling.
transformation = Geom::Transformation.scaling scale
transformation = Geom::Transformation.scaling point, scale transformation = Geom::Transformation.scaling xscale, yscale, zscale
transformation = Geom::Transformation.scaling point, xscale, yscale, zscale
scale - a single numeric values used to set a global scale factor for the transform
xscale - a numeric value specifying the scale factor in the x direction for the transform
yscale - a numeric value specifying the scale factor in the y direction for the transform
zscale - a numeric value specifying the scale factor in the z direction for the transform
point - a Point3d object
transformation - a new Transformation object
Create a Transformation that does scaling.
With one argument, it does a uniform scale about the origin.
With two arguments, it does a uniform scale about an arbitrary point.
With three arguments, it does a non-uniform scale about the origin.
With four arguments it does a non-uniform scale about an arbitrary point
t = Geom::Transformation.scaling 10
UI.messagebox t
The translation method is used to create a transformation that does translation.
transformation = Geom::Transformation.translation vector
vector - a Vector3d object
transformation - a new Transformation object
vector = Geom::Vector3d.new 0,1,0
t = Geom::Transformation.translation vector
UI.messagebox t
The * method is used to do matrix multiplication using the Transform.
point2 = transformation * point1
vector2 = transformation * vector1
transformation2 = transformation * transformation1
point1 - a Point3d object
vector1 - a Vector3d object
transformation1 - a Transformation object
point2 - a new Point3d object
vector2 - a new Vector3d object
transformation2 - a new Transformation object
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 clone method is used to create a copy of a transformation.
transformation2 = transformation1.clone
transformation2 - a new Transformation object (clone of transformation1)
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.
status = transformation.identify?
status - true if the transformation is the identity transform, false if it is not the identity transform.
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
status = t.identity?
UI.messagebox status
The inverse method is used to retrieve the inverse of a transformation.
transformation2 = transformation1.inverse
transformation2 - the Transformation object at its inverse
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
t2 = t.inverse
UI.messagebox t2
The invert! method sets the transformation to its inverse.
transformation = transformation.invert!
transformation - the Transformation object at its inverse.
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
t2 = t.invert!
UI.messagebox t2
The origin method retrieves the origin of a rigid transformation.
point = transformation.origin
point - a Point3d object representing the origin of the transformation
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
point2 = t.origin
UI.messagebox point2
The set! method is used to set this transformation to match another one
transformation1 = transformation1.set! transformation2
transformation2 - a Transformation object to match
transformation1 - a Transformation object matching transformation2
The argument is anything that can be converted into a Transformation. b
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 = t1.set! t2
UI.messagebox t3
The to_a method retrieves a 16 element array which contains the values that define the Transformation.
array = transformation.to_a
array - an Array element containing the values that define the transformation
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
a = t.to_a
UI.messagebox a
The xaxis method retrieves the x axis of a rigid transformation.
point = transformation.xaxis
point - a Point3d object containing the xaxis value
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.
point = transformation.yaxis.
point - a Point3d object containing the yaxis value
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
y = t.yaxis
UI.messagebox y
The zaxis method retrieves the z axis of a rigid transformation.
point = transformation.zaxis
point - a Point3d object containing the zaxis value
point = Geom::Point3d.new 10,20,30
t = Geom::Transformation.new point
z = t.zaxis
UI.messagebox z