NAME
Geometry::AffineTransform - Maps 2D coordinates to other 2D coordinates
SYNOPSIS
use Geometry::AffineTransform;
my $t = Geometry::AffineTransform->new();
$t->translate($delta_x, $delta_y);
$t->rotate($degrees);
my $t2 = Geometry::AffineTransform->new()->scale(3.1, 2.3);
$t->concatenate($t2);
my ($x1, $y1, $x2, $y2, ...) = $t->transform($x1, $y1, $x2, $y2, ...);
DESCRIPTION
Geometry::AffineTransform instances represent 2D affine transformations that map 2D coordinates to other 2D coordinates. The references in "SEE ALSO" provide more information about affine transformations.
You create a new instance with "new", configure it to perform the desired transformation with a combination of "scale", "rotate" and "translate" and then perform the actual transformation on one or more x/y coordinate pairs with "transform".
The state of a newly created instance represents the identity transform, that is, it transforms all input coordinates to the same output coordinates.
Most methods return the instance so that you can chain several calls:
my $t = Geometry::AffineTransform->new();
$t->scale(...)->translate(...)->rotate(...);
($x, $y) = Geometry::AffineTransform->new()->rotate(..)->transform($x, $y);
METHODS
new
Constructor, returns a new instance configured with an identity transform.
Parameters
You can optionally supply any of the six specifiable parts of the transformation matrix if you want an initial state different from the identity transform:
[ m11 m21 0 ]
[ m21 m22 0 ]
[ tx ty 1 ]
The six values in the first two colums are the specifiable values. You can initialize them with key/value parameters:
my $t = Geometry::AffineTransform->new(tx => 10, ty => 15);
By default, the identity transform represented by this matrix is used:
[ 1 0 0 ]
[ 0 1 0 ]
[ 0 0 1 ]
transform
Transform one or more coordinate pairs according to the current state.
Parameters
This method expects an even number of positional parameters, each pair representing the x and y coordinates of a point.
Result
Returns the transformed list of coordinates in the same form as the input list.
concatenate
Combine the receiver's state with that of another transformation instance.
Parameters
This method expects a list of one or more Geometry::AffineTransform
instances and combines the transformation of each one with the receiver's in the given order.
Result
Returns $self
.
scale
Adds a scaling transformation.
Parameters
This method expects positional parameters.
- sx
-
The scaling factor for the x dimension.
- sy
-
The scaling factor for the y dimension.
Result
Returns $self
.
scale
Adds a translation transformation, i.e. the transformation shifts the input coordinates by a constant amount.
Parameters
This method expects positional parameters.
- tx
-
The offset for the x dimension.
- ty
-
The offset for the y dimension.
Result
Returns $self
.
rotate
Adds a rotation transformation.
Parameters
This method expects positional parameters.
- angle
-
The rotation angle in degrees. With no other transformation active, positive values rotate counterclockwise.
Result
Returns $self
.
matrix
Returns the current value of the 3 x 3 transformation matrix, including the third, fixed column, as a 9-element list:
my ($m11, $m12, undef,
$m21, $m22, undef,
$tx, $ty, undef) = $t->matrix();
SEE ALSO
- Apple Quartz 2D Programming Guide - The Math Behind the Matrices
-
http://developer.apple.com/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/chapter_6_section_7.html
- Sun Java java.awt.geom.AffineTransform
-
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/geom/AffineTransform.html
- Wikipedia - Matrix Multiplication
-
http://en.wikipedia.org/wiki/Matrix_(mathematics)#Matrix_multiplication
COPYRIGHT AND LICENSE
Copyright 2008 Marc Liyanage.