Transform::Canvas - Perl extension for performing Coordinate transformation operations from the cartesion to the traditional drawing-model canvas coordinate systems.
VERSION 0.14 15 Febuary, 2009
use Transform::Canvas; # create a mapping transform for data from #x=-100,y=-100,x=100,y=100 to x=10,y=10,x=100,y=100 $t = Transform::Canvas->new(canvas=>[10,10,100,100],data=>[-100,-100,100,100]); # create a arrays of x and y values $r_x = [-100,-10, 0, 20, 40, 60, 80, 100]; $r_y = [-100,-10, 0, 20, 40, 60, 80, 100]; #map the two arrays into the canvas data space ($pr_x,$pr_y) = $t->map($r_x,$r_y);
Transform::Canvas is a module which automates reference-frame transformations beween two cartesian coordinate systems. it is specifically intended to be used as a facilitator for coordinate-system transformation procedures between the traditional, right-hand-rule coordinate system used in mathematics graphing and the visual-arts coordinate system with a y-axis pointing down.
The module allows for arbitrary 2-D transform mappings.
Module constructor.
#there are two ways to invoke this module #one-step constructo $t = Transform::Canvas->new (canvas => [x0 y0 x1 y1], data=>[x0 y0 x1 y1]) # or two-step connstructor $t-> Transform::Canvas->new (); $t->prepareMap (canvas => [x0 y0 x1 y1], data=>[x0 y0 x1 y1])
generate the conversion object through which all data points will be passed. NB: svg drawings use the painter's model and use a coordinate system which starts at the top, left corner of the document and has x-axis increasing to the right and y-axis increasing down.
In certain drawings, the y-axis is inverted compared to mathematical representation systems which prefer y to increase in the upwards direction.
canvas (target): x0 = paper-space minimum x value y0 = paper-space maximum x value x1 = paper-space minimum y value y1 = paper-space maximum y value data (source): x0 = data-space minimum x value y0 = data--space maximum x value x1 = data-space minimum y value y1 = data-space maximum y value
Prepare the transformation space for the conversions; Currently only handles linear transformations, but this is a perfect candidate for non-spacial, non-cartesian transforms...
set and/or return the canvas x min value
set and/or return the canvas x max value
set and/or return return the canvas y min value
set and/or return the canvas y max value
set and/or return the data space x min value
set and/or return the data space x max value
set and/or return the data space y min value
set and/or return the data space y max value.
Map an array or a value from the (x,y) data axes to the (x,y) canvas axes
Map an array or a value of the x data axis to the x canvas axis
Map an array or a value of the y data axis to the y canvas axis
Find th of an array
my $x = $t->Max([1,2,3,4,5]);
This utility needed a home and this seems like a convenient place to stick it
SVG SVG::Parser SVG::DOM SVG::Element SVG::Graph SVG::Extension
Ronan Oger, <ronan@cpan.com>
Copyright (C) 2004-2009 by Ronan Oger
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.
To install Transform::Canvas, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Transform::Canvas
CPAN shell
perl -MCPAN -e shell install Transform::Canvas
For more information on module installation, please visit the detailed CPAN module installation guide.