Next: , Previous: Pens, Up: Programming


4.4 Transforms

Asymptote makes extensive use of affine transforms. A pair (x,y) is transformed by the transform t=(t.x,t.y,t.xx,t.xy,t.yx,t.yy) to (x',y'), where

x' = t.x + t.xx * x + t.xy * y
y' = t.y + t.yx * x + t.yy * y
Transforms can be applied to pairs, guides, paths, pens, transforms, frames, and pictures by multiplication (via the binary operator *) on the left (see circle for an example). Transforms can be composed with one another and inverted with the function transform inverse(transform); they can also be raised to any integer power with the ^ operator.

The built-in transforms are:

identity();
the identity transform;
shift(pair z);
translates by the pair z;
xscale(real x);
scales by x in the x direction;
yscale(real y);
scales by y in the y direction;
scale(real s);
scale by s in both x and y directions;
slant(real s);
maps (x,y) –> (x+s*y,y);
rotate(real angle, pair z=(0,0));
rotates by angle in degrees about z;
reflect(pair a, pair b);
reflects about the line a--b.

The implicit initializer for transforms is identity().