Inversion is another operation that can be performed on
Transforms. This makes it possible to reverse the effect of a
Transform, which may represent multiple transformations.
Point p;
Transform t;
t.shift(1, 2, 3);
t.scale(2, 3, 4);
t.rotate(45, 45, 30);
t.show("t:");
-| t:
1.22 0.707 1.41 0
0.238 2.59 -1.5 0
-3.15 1.45 2 0
-7.74 10.2 4.41 1
p *= t;
p.show("p:");
-| p: (-7.74, 10.2, 4.41)
Transform u;
u = t.inverse();
u.show("u:");
-| u:
0.306 0.0265 -0.197 2.85e-09
0.177 0.287 0.0906 -1.12e-09
0.354 -0.167 0.125 0
-1 -2 -3 1
p *= u;
p.show("p:");
-| p: (0, 0, 0)
u *= t;
u.show("u:");
-| u:
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
If inverse() is called with no argument, or with the argument
false, it returns a
Transform representing its inverse, and remains unchanged. If it
is called with the argument true, it is set to its inverse.
Complete reversal of the transformations applied to a Point, as
in the previous example, probably won't make much sense. However,
partial reversal is a valuable technique. For example, it is used in
rotate() for rotation about a line defined by two Points.
The following example merely demonstrates the basic principle; an
example that does something useful would be too complicated.
Transform t;
t.shift(3, 4, 5);
t.rotate(45);
t.scale(2, 2, 2);
Point p;
p *= t;
p.show("p:");
-| p: (6, 12.7279, 1.41421)
t.inverse(true);
p.rotate(90, 90);
p *= t;
p.show("p:");
-| p: (3.36396, -5.62132, -2.37868)