Node: Affine Transformations for Points, Next: , Previous: Modifying Points, Up: Point Reference



Affine Transformations

Transform rotate (const real x, [const real y = 0, [const real z = 0]]) Function
Transform rotate (const Point& p0, const Point& p1, [const real angle = 180]) Function
Transform rotate (const Path& p, [const real angle = 180]) Function
Each of these functions calls the corresponding version of Transform::rotate(), and returns its return value, namely, a Transform representing the rotation only.

In the first version, taking three real arguments, the Point is rotated x degrees around the x-axis, y degrees around the y-axis, and z degrees around the z-axis in that order.

          Point p0(1, 0, 2);
          p0.rotate(90);
          p0.show("p0:")
          -| p0: (1, 2, 0)
          Point p1(-1, 1, 1);
          p1.rotate(-90, 90, 90);
          p1.show("pt1:");
          -| p1: (1, -1, -1)
          


[Figure 81. Not displayed.]

Fig. 81.

Please note that rotations are not commutative operations. Nor are they commutative with other transformations. So, if you want to rotate a Point about the x, y and z-axes in that order, you can do so with a single invocation of rotate(), as in the previous example. However, if you want to rotate a Point first about the y-axis and then about the x-axis, you must invoke rotate() twice.

          Point pt0(1, 1, 1);
          pt0.rotate(0, 45);
          pt0.rotate(45);
          pt0.show("pt0:");
          -| pt0: (0, 1.70711, 0.292893)
          

In the version taking two Point arguments p0 and p1, and a real argument angle, the Point is rotated angle degrees around the axis determined by p0 and p1, 180 degrees by default.

          Point P(2, 0, 0);
          Point A;
          Point B(2, 2, 2);
          P.rotate(A, B, 180);
          


[Figure 82. Not displayed.]

Fig. 82.

Transform scale (real x, [real y = 1, [real z = 1]]) Function
Calls transform.scale(x, y, z) and returns its return value, namely, a Transform representing the scaling operation only.

Scaling causes the x-coordinate of the Point to be multiplied by x, the y-coordinate of the Point to be multiplied by y, and the z-coordinate of the Point to be multiplied by z.

          Point p0(1, 0, 3);
          p0.scale(4);
          p0.show("p0:");
          -| p0: (4, 0, 3)
          Point p1(-2, -1, -2);
          p1.scale(-2, -3, -4);
          p1.show("p1:");
          -| p1: (4, 3, 8)
          


[Figure 83. Not displayed.]

Fig. 83.

Transform shear (real xy, [real xz = 0, [real yx = 0, [real yz = 0, [real zx = 0, [real zy = 0]]]]]) Function
Calls transform.shear() with the same arguments and returns its return value, namely, a Transform representing the shearing operation only.

Shearing modifies each coordinate of a Point proportionately to the values of the other two coordinates. Let x_0, y_0, and z_0 stand for the coordinates of a Point P before P.shear(\alpha, \beta, \gamma, \delta, \epsilon, \zeta ), and x_1, y_1, and z_1 for its coordinates afterwards.

          x_1 == x_0 + \alpha y + \beta z
          y_1 == y_0 + \gamma x + \delta z
          z_1 == z_0 + \epsilon x + \zeta y
          

[next figure] demonstrates the effect of shearing the four Points of a 3 * 3

Rectangle (i.e., a square) r in the x-y plane using only an xy argument, making it non-rectangular.

          Point P0;
          Point P1(3);
          Point P2(3, 3);
          Point P3(0, 3);
          Rectangle r(p0, p1, p2, p3);
          r.draw();
          r.shear(1.5);
          r.draw(black, "evenly");
          


[Figure 84. Not displayed.]

Fig. 84.

Transform shift (real x, [real y = 0, [real z = 0]]) Function
Transform shift (const Point& p) Function
Each of these functions calls the corresponding version of Transform::shift() on transform, and returns its return value, namely, a Transform representing the shifting operation only.

The Point is shifted x units in the direction of the positive x-axis, y units in the direction of the positive y-axis, and z units in the direction of the positive z-axis.

          p0(1, 2, 3);
          p0.shift(2, 3, 5);
          p0.show("p0:");
          -| p0: (3, 5, 8)
          

Transform shift_times (real x, [real y = 1, [real z = 1]]) Function
Transform shift_times (const Point& p) Function
Each of these functions calls the corresponding version of Transform::shift_times() on transform and returns its return value, namely the new value of transform.

shift_times() makes it possible to increase the magnitude of a shift applied to a Point, while maintaining its direction. Please note that shift_times() will only have an effect if it's called after a call to shift() and before transform is reset. This is performed by reset_transform(), which is called in apply_transform(), and can also be called directly. See Transform Reference; Resetting, and Point Reference; Applying Transformations.

          Point P;
          P.drawdot();
          P.shift(1, 1, 1);
          P.drawdot();
          P.shift_times(2, 2, 2);
          P.drawdot();
          P.shift_times(2, 2, 2);
          P.drawdot();
          P.shift_times(2, 2, 2);
          P.drawdot();
          


[Figure 85. Not displayed.]

Fig. 85.