Geometry::AffineTransform - Affine Transformation to map 2D coordinates to other 2D coordinates
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, ...);
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 method calls:
my $t = Geometry::AffineTransform->new(); $t->scale(...)->translate(...)->rotate(...); ($x, $y) = Geometry::AffineTransform->new()->rotate(..)->transform($x, $y);
Constructor, returns a new instance configured with an identity transform.
You can optionally supply any of the six specifiable parts of the transformation matrix. The six values in the first two columns are the specifiable values:
[ m11 m21 0 ] [ m21 m22 0 ] [ tx ty 1 ]
The constructor lets you 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 ]
In other words, invoking the constructor without arguments is equivalent to this:
my $t = Geometry::AffineTransform->new( m11 => 1, m12 => 0, m21 => 0, m22 => 1, tx => 0, ty => 0 );
Returns a clone of the instance.
Inverts the state of the transformation.
my $inverted_clone = $t->clone()->invert();
Transform one or more coordinate pairs according to the current state.
This method expects an even number of positional parameters, each pair representing the x and y coordinates of a point.
Returns the transformed list of coordinates in the same form as the input list.
my @output = $t->transform(2, 4, 10, 20);
Combine the receiver's state with that of another transformation instance.
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.
Returns $self
.
Adds a scaling transformation.
This method expects positional parameters.
Returns $self
.
Adds a translation transformation, i.e. the transformation shifts the input coordinates by a constant amount.
This method expects positional parameters.
Returns $self
.
Adds a rotation transformation.
This method expects positional parameters.
The rotation angle in degrees. With no other transformation active, positive values rotate counterclockwise.
Returns $self
.
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();
http://download.oracle.com/javase/1.4.2/docs/api/java/awt/geom/AffineTransform.html
Marc Liyanage <liyanage@cpan.org>
Copyright 2008 Marc Liyanage.
Distributed under the Artistic License 2.