NAME

Geometry::AffineTransform - Affine Transformation to map 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 method 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.

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
);

clone

Returns a clone of the instance.

invert

Inverts the state of the transformation.

my $inverted_clone = $t->clone()->invert();

transform

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);

concatenate

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.

scale

Adds a scaling transformation.

This method expects positional parameters.

sx

The scaling factor for the x dimension.

sy

The scaling factor for the y dimension.

Returns $self.

translate

Adds a translation transformation, i.e. the transformation shifts the input coordinates by a constant amount.

This method expects positional parameters.

tx

The offset for the x dimension.

ty

The offset for the y dimension.

Returns $self.

rotate

Adds a rotation transformation.

This method expects positional parameters.

angle

The rotation angle in degrees. With no other transformation active, positive values rotate counterclockwise.

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/library/mac/DOCUMENTATION/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html#//apple_ref/doc/uid/TP30001066-CH204-CJBECIAD

Sun Java java.awt.geom.AffineTransform

http://download.oracle.com/javase/1.4.2/docs/api/java/awt/geom/AffineTransform.html

Wikipedia - Matrix Multiplication

http://en.wikipedia.org/wiki/Matrix_(mathematics)#Matrix_multiplication.2C_linear_equations_and_linear_transformations

AUTHOR

Marc Liyanage <liyanage@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2008 Marc Liyanage.

Distributed under the Artistic License 2.