The affine transformation functions use their arguments to create a new
Transform t (local to the function) representing the
appropriate transformation. Then, *this is multiplied by t
and t is returned.
Returning t instead of *this makes it possible to put the
affine transformation function at the end of a chain of invocations of
Transform::operator*=():
Transform t0, t1, t2, t3;
...
t0 *= t1 *= t2 *= t3.scale(2, 3.5, 9);
t0, t1, and t2 are all multiplied by the
Transform with
matrix =
2 0 0 0
0 3.5 0 0
0 0 9 0
0 0 0 1
representing the scaling operation, not t3, which may
represent a combination of transformations.
Creates a
Transform trepresenting the scaling operation locally, multiplies*thisbyt, and returnst. ATransformrepresenting scaling only, when applied to aPoint p, will cause its x-coordinate to be multiplied by x, its y-coordinate to be multiplied by y, and its z-coordinate to be multiplied by z.Transform t;t.scale(x,y,z);⇒t.matrix= x 0 0 0 0 y 0 0 0 0 z 0 0 0 0 1Transform t; t.scale(12.5, 20, 1.3); t.show("t:"); -| t: 12.5 0 0 0 0 20 0 0 0 0 1.3 0 0 0 0 1
Creates a
Transform trepresenting the shearing operation locally, multiplies*thisbyt, and returnst.When applied to a
Point, shearing causes each coordinate to be modified according to the values of the other coordinates and the arguments toshear:Point p(x,y,z); Transform t; t.shear(a, b, c, d, e, f); p *= t;⇒ p = ((x + ay + bz), (y + cx + dz), (z + ex + fy))Transform t; t.shear(2, 3, 4, 5, 6, 7); t.show("t:"); -| t: 1 4 6 0 2 1 7 0 3 5 1 0 0 0 0 1
These functions create a
Transform trepresenting the shifting operation locally, multiplies*thisbyt, and returnst.The version with the argument
const Point&p passes the updated x, y, and z-coordinates of p (fromworld_coordinates) to the version with threerealarguments.When a
Transformrepresenting a single shifting operation only is applied to aPoint, the x, y, and z arguments are added to the corresponding coordinates of thePoint:Point p(x,y,z); Transform t; t.shift(a, b, c); p *= t;⇒ p = (x + a, y + b, z + c)
Multiplies the corresponding elements of
matrixby therealarguments, i.e.,matrix[3][0]is multiplied by x,matrix[3][1]is multiplied by y, andmatrix[3][2]is multiplied by z. Returns*this.Ordinary shifting is additive, so a special function is needed to multiply the elements of
matrixresponsible for shifting. The effect ofshift_times()is to modify aTransformrepresenting a shifting operation such that the direction of the shift is maintained, while changing the distance.If the
Transformrepresents other operations in addition to shifting, e.g., scaling and/or shearing, the effect ofshift_times()may be unpredictable.1Transform t; t.shift(1, 2, 3);⇒t.matrix= 1 0 0 0 0 1 0 0 0 0 1 0 1 2 3 1t.shift_times(2, 2, 2);⇒t.matrix= 1 0 0 0 0 1 0 0 0 0 1 0 2 4 6 1Rectangle r[4]; r[0].set(origin, 1, 1, 90); r[3] = r[2] = r[1] = r[0]; Transform t; t.shift(1.5, 1.5); r[0] *= t; r[0].draw(); t.shift_times(1.5, 1.5); r[1] *= t; r[1].draw(); t.shift_times(1.5, 1.5); r[2] *= t; r[2].draw(); t.shift_times(1.5, 1.5); r[3] *= t; r[3].draw();
![]()
Fig. 73.
Cuboid c(origin, 1, 1, 1); c.draw(); Transform t; t.rotate(30, 30, 30); t.shift(1, 0, 1); c *= t; c.draw(); t.shift_times(1.5, 0, 1.5); c *= t; c.draw(); t.shift_times(1.5, 0, 1.5); c *= t; c.draw(); t.shift_times(1.5, 0, 1.5); c *= t; c.draw(); t.shift_times(1.5, 0, 1.5); c *= t; c.draw();
![]()
Fig. 74.
Rotation around the main axes. Creates a
Transform trepresenting the rotation, multiplies*thisbyt, and returnst.
Rotation around an arbitrary axis. The
Pointarguments represent the end points of the axis, and angle is the angle of rotation. Since 180 degrees rotation is needed so often, 180 is the default for angle.
Rotation around an arbitrary axis.
Pathargument. ThePathp must be linear, i.e.,p.is_linear()must returntrue. See Path Reference; Querying.