geom.transform
drafting: Q = geom.transform (P, T)
drafting: Q = geom.transform (P, OP, VAL)
drafting: Q = geom.transform (P, OP, VAL, CENTRE)
Apply a planar transformation to a set of points.
Q = geom.transform (P, T) applies the 3-by-3
homogeneous matrix T to every row of the -by-2 matrix P
and returns the result in the same shape. T acts on column vectors
[x; y; 1], which is the usual convention, so transformations compose
by ordinary matrix multiplication with the last-applied factor on the left.
Q = geom.transform (P, OP, VAL) builds the
matrix from a named operation instead. OP is one of:
'translate' — VAL is a 1-by-2 offset
[dx, dy].
'rotate' — VAL is an angle in degrees,
counter-clockwise positive. Degrees rather than radians because this is a
drafting package and drawings are dimensioned in degrees.
'scale' — VAL is a scalar factor, or a 1-by-2 pair
[sx, sy] for an anisotropic scaling.
'mirror' — VAL is 'x' or 'y', naming
the axis to reflect about. Mirroring about 'x' negates the
coordinate, so the point [1, 2] becomes [1, -2].
Q = geom.transform (P, OP, VAL, CENTRE)
performs the operation about the point CENTRE rather than the origin.
It applies to 'rotate', 'scale' and 'mirror'; a
translation is unaffected by any centre, so supplying one is an error rather
than a silently ignored argument.
Unlike most of this namespace, geom.transform accepts any point set,
not only a polygon: two points making up a single edge are valid input.
See also: geom.bbox, geom.offset
Source Code: geom.transform
The four named operations, each shown against the original. A centre may be given so the operation happens about a point rather than the origin.
P = [0, 0; 30, 0; 30, 10; 10, 10; 10, 20; 0, 20];
D = draw.Drawing ().polyline (P, true);
D.Colour = 'red';
D = D.polyline (geom.transform (P, 'translate', [45, 0]), true);
D.Colour = 'blue';
D = D.polyline (geom.transform (P, 'rotate', 90, [15, 10]), true);
D.Colour = 'green';
D = D.polyline (geom.transform (P, 'scale', 0.5, [15, 10]), true);
D.Colour = 'magenta';
D = D.polyline (geom.transform (P, 'mirror', 'y'), true);
plot (D);
title ('translate, rotate about a point, scale, mirror');
A 3-by-3 homogeneous matrix does anything the named operations do and composes by ordinary multiplication, last-applied on the left.
P = [0, 0; 20, 0; 20, 10]; T = [1, 0, 50; 0, 1, 0; 0, 0, 1] * [0, -1, 0; 1, 0, 0; 0, 0, 1]; geom.transform (P, T)
ans = 50 0 50 20 40 20