Next: Frames and pictures, Previous: Pens, Up: Programming
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 * yThis is equivalent to the
PostScript
transformation
[t.xx t.yx t.xy t.yy t.x t.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 t)
; they can also be raised to any
integer power with the ^
operator.
The built-in transforms are:
transform identity();
transform shift(pair z);
z
;
transform shift(real x, real y);
(x,y)
;
transform xscale(real x);
x
in the x direction;
transform yscale(real y);
y
in the y direction;
transform scale(real s);
s
in both x and y directions;
transform slant(real s);
(x,y)
–> (x+s*y,y)
;
transform rotate(real angle, pair z=(0,0));
angle
in degrees about z
;
transform reflect(pair a, pair b);
a--b
.
The implicit initializer for transforms is identity()
.
The routines shift(transform t)
and shiftless(transform t)
return the transforms (t.x,t.y,0,0,0,0)
and
(0,0,t.xx,t.xy,t.yx,t.yy)
respectively.