Visualizing Linear Transformations

Quick review of how to use Mathematica: Click on a block of code (anywhere in the block) and then press Enter (not Return). Then go on to the next block. Some blocks have no visible effect; others have dramatic effects.

Utility Functions

Here is a general user interface construct for deforming stuff in 2D or 3D. The given matrix must be 2x2 or 3x3, and it must contain a t, for this deformer to be useful.

deformedPoints[points_, matrix_] := points.Transpose[matrix];
deformer[axes_, curvesToDeform_, pointsToDeform_, matrix_] := 
 Manipulate[
If[Length[matrix] == 2, Graphics, Graphics3D][{
Line[axes],
PointSize[Large],
Point[Map[Function[point, deformedPoints[point, matrix]], pointsToDeform]],
AbsoluteThickness[2],
Line[Map[Function[curve, deformedPoints[curve, matrix]], curvesToDeform]]}],
{t, 0, 1}];

Here we build some graphics as lists of curves. A curve is a list of points (to be joined by straight lines).

circlePoints[{a_, b_}, r_, n_] := Table[{r Cos[t] + a, r Sin[t] + b}, {t, 0, 2 Pi, 2 Pi / n}];
circle2D = circlePoints[{0, 0}, 1, 100];
box2D = {{{1, 1}, {-1, 1}, {-1, -1}, {1, -1}, {1, 1}}, {{1, 0}, {0, 0}}, {{0, 1}, {0, 0}}};
rock2D = Append[box2D, circle2D];
axes2D[b_] :=  Join[
{{{b, 0}, {-b, 0}}, {{0, b}, {0, -b}}}, 
Table[{{k, 0.1}, {k, -0.1}}, {k, -b, b, 1}], 
Table[{{0.1, k}, {-0.1, k}}, {k, -b, b, 1}]];

Basic Transformations in 2D

Here we define a 2x2 matrix and visualize it as a linear transformation of the plane. Try it out. In words, describe what it does.

matrix = {{1, 0}, {0, 0}};
MatrixForm[matrix]
deformer[axes2D[2], rock2D, {}, {{1, 0}, {0, 1 - t}}]

What does this transformation do? Again, describe it in words.

matrix = {{1, 0}, {0, -1}};
MatrixForm[matrix]
deformer[axes2D[2], rock2D, {}, {{1, 0}, {0, 1 - 2t}}]

Now try this one. Then type in a new value for k and describe that. Try various values of k, including a k between 0 and 1. (Right now, only positive values work.)

k = 3;
matrix = {{k, 0}, {0, k}};
MatrixForm[matrix]
deformer[axes2D[k + 1], rock2D, {}, MatrixPower[matrix, t]]

Here is different transformation. Try it out. What is it doing? Try various angles. What happens if you change the angle to a negative angle?

angle = Pi / 6;
matrix = {{Cos[angle], -Sin[angle]}, {Sin[angle], Cos[angle]}};
MatrixForm[matrix]
deformer[axes2D[2], rock2D, {}, {{Cos[t angle], -Sin[t angle]}, {Sin[t angle], Cos[t angle]}}]

Here is a more sophisticated version of an earlier example. Enter any nonzero vector y. What does the transformation do?

y = {1,1};
matrix = Outer[Times, y, y] / Dot[y, y];
MatrixForm[matrix]
deformer[axes2D[2], rock2D, {}, IdentityMatrix[2] + t( matrix - IdentityMatrix[2])]

Do Not Take the Interpolation Seriously

It is important to remember that a linear transformation describes only the net change between the starting configuration and the ending configuration; the "interpolation" or "animation" that you see in the examples above is an artifice created by me to help you understand what's going on intuitively. The following two-part example is intended to drive this point home. The two parts describe the same linear transformation, but with different interpolations. Neither interpolation is more "correct" than the other.

matrix = {{-1,0}, {0, -1}};
MatrixForm[matrix]
deformer[axes2D[2], rock2D, {}, {{Cos[t Pi], -Sin[t Pi]}, {Sin[t Pi], Cos[t Pi]}}]

matrix = {{-1,0}, {0, -1}};
MatrixForm[matrix]
deformer[axes2D[2], rock2D, {}, {{1 - 2 t, 0}, {0, 1 - 2 t}}]

Deformations In Structural Geology and Fluid Mechanics

In structural geology, the following kind of deformation is called simple shear. It describes how a rock deforms when it is trapped between two larger blocks of rock sliding past one another.

g = 1;
matrix = {{1, g}, {0, 1}};
MatrixForm[matrix]
deformer[axes2D[g + 2], rock2D, {}, MatrixPower[matrix, t]]

The following kind of deformation is called pure shear. It describes how a rock deforms when it gets pressed or pulled from two opposite directions, such as north and south.

k = 2;
matrix = {{k, 0}, {0, 1/k}};
MatrixForm[matrix]
deformer[axes2D[k + 1], rock2D, {}, MatrixPower[matrix, t]]

Transpression and transtension are combinations of simple shear and pure shear.

k = 2;
g = 1;
matrix = {{k, g}, {0, 1/k}};
MatrixForm[matrix]
deformer[axes2D[k + g + 1], rock2D, {}, MatrixPower[matrix, t]]

Visualizing 3D Linear Transformations

To visualize 3D linear transformations, let's first make some graphics to deform.

axes3D[b_] := Join[{{{b, 0, 0}, {-b, 0, 0}}, {{0, b, 0}, {0, -b, 0}}, {{0, 0, b}, {0, 0, -b}}}, Table[{{k, 0.1, 0}, {k, -0.1, 0}}, {k, -b, b, 1}], Table[{{0.1, k, 0}, {-0.1, k, 0}}, {k, -b, b, 1}]];
box3D = {{{1,1,1},{1,1,-1}},{{1,1,1},{1,-1,1}},{{1,-1,1},{1,-1,-1}},{{1,-1,-1},{1,1,-1}},{{1,1,1},{-1,1,1}},{{-1,-1,-1},{-1,-1,1}},{{-1,-1,-1},{-1,1,-1}},{{-1,-1,-1},{1,-1,-1}},{{-1,-1,1},{-1,1,1}},{{-1,-1,1},{1,-1,1}}, {{-1, 1, 1}, {-1, 1, -1}}, {{-1, 1, -1}, {1, 1, -1}}};

This is 3D simple shear. You can drag the 3D image with your mouse to rotate it.

g = 1;
matrix = {{1, g, 0}, {0, 1, 0}, {0, 0, 1}};
MatrixForm[matrix]
deformer[axes3D[g + 2], box3D, {}, MatrixPower[matrix, t]]

This is 3D pure shear.

k = 2;
matrix = {{2, 0, 0}, {0, 1/k, 0}, {0, 0, 1}};
MatrixForm[matrix]
deformer[axes3D[k + 1], box3D, {}, MatrixPower[matrix, t]]

This is transpression along the x-z-plane.

g = 1;
k = 2;
matrix = {{k, g, 0}, {0, 1/k, 0}, {0, 0, 1}}
deformer[axes3D[k + g + 1], box3D, {}, MatrixPower[matrix, t]]

This is a more complicated sort of deformation that is not possible in 2D: transpression along a non-vertical plane. Make sure you view it from several angles, to see what it's doing.

matrix = {{2, 1, 0}, {0, 1/2, 0}, {0, 1, 1}};
MatrixForm[matrix]
deformer[axes3D[3], box3D, {}, MatrixPower[matrix, t]]

3D Deformation Of A Sphere

Here are some fancier graphics.

cartesianFromSpherical[{rho_, phi_, theta_}] := {rho Sin[phi] Cos[theta], rho Sin[phi] Sin[theta], rho Cos[phi]};
sphereRectangles[{a_, b_, c_}, r_, n_] := Flatten[Table[{
cartesianFromSpherical[{r, phi, theta}], 
cartesianFromSpherical[{r, phi + 2 Pi / n, theta}], cartesianFromSpherical[{r, phi + 2 Pi / n, theta + 2 Pi / n}], cartesianFromSpherical[{r, phi, theta + 2 Pi / n}]}, {phi, 0, Pi, 2 Pi / n}, {theta, 0, 2 Pi, 2 Pi / n}], 1];
sphere3D = sphereRectangles[{0, 0, 0}, 1,20];
polygonalDeformer[axes_, polygonsToDeform_, matrix_] := Manipulate[Graphics3D[{
Line[axes],
Polygon[Map[Function[polygon, deformedPoints[polygon, matrix]], polygonsToDeform]]}],
{t, 0, 1}];

Here's the same deformation as the last one, with the fancier graphics.

matrix = {{2, 1, 0}, {0, 1/2, 0}, {0, 1, 1}};
MatrixForm[matrix]
polygonalDeformer[axes3D[3], sphere3D, MatrixPower[matrix, t]]