Transformations Using Mathematica's Built - In Functions and Graphics

Based on Mathematical Concepts from “Transformations and Projections in Computer Graphics,” 2006, by David  Salomon.

Examples:

Rotate a 2D graphic by 15 degrees counterclockwise:

Clear[graf1,graf2,lst,ang,anglelabel]
graf1=Graphics[GeometricTransformation[{Hue[0.535],Rectangle[]},RotationTransform[15Degree]],Axes->True,AxesLabel->{"","+y"},Frame->True,Background->LightCyan,ImageSize->500];
lst=Table[{Cos[ang],Sin[ang]},{ang,0,15Degree,15Degree}];
graf2=Graphics[Arrow[lst]];
anglelabel=Graphics[Text["15 Degrees",{.87,.07}]];
Show[graf1,graf2,anglelabel]

Translate a  2D rectangle by 0.65 in x, and 0.40 in y: Show a before and after position for the rectangle.

Graphics[{{Opacity[.35],Gray,Rectangle[]},GeometricTransformation[{Opacity[.85],Orange,Rectangle[]},TranslationTransform[{0.65,0.40}]]},AspectRatio->1,Axes->True,Frame->True,FrameLabel->{X,Y},Background->LightYellow,ImageSize->500]

Using Scale: Streach the 2D rectangle in the +x direction by 1/2 unit. Show the rectangle before the scaling and the scaled addition in the same plot.

Graphics[{{Blue,Opacity[.1],Rectangle[]},Scale[{Opacity[.1],Red,Rectangle[]},{1+1/2,1},{0,0}]},PlotRange->{0,1.5},Axes->True,AxesLabel->{"+x","+y"},Background->LightBrown,AspectRatio->1,ImageSize->500]

Apply a 30° shearing along the x axis to a rectangle. Show the rectangle before and after the shearing in the same plot.

pic1=Graphics[{Blue,Opacity[.1],Rectangle[]},AspectRatio->1];
pic2=Graphics[GeometricTransformation[{Red,Opacity[.1],Rectangle[]},ShearingTransform[30Degree,{1,0},{0,1}]]];
Show[pic1,pic2,Frame->True,FrameLabel->{X,Y},ImageSize->500,Background->LightGray]

Rotate the 3D cuboid at standard position, 30 degrees CCW about the x axis. Show a before and after position for the cuboid:

Graphics3D[{{Opacity[.2],Cuboid[],Blue},Rotate[{Opacity[.6],Glow[Red],Cuboid[]},30Degree,{1,0,0}]},Axes->True,AxesLabel->{"x","y","z"},Background->LightRed,ImageSize->500,ViewPoint->{0.8,0.6,0.5}]

Rotate the cuboid at standard position, 45 degrees CCW about the y axis. Show a before and after position for the cuboid:

Graphics3D[{{Opacity[.2],Cuboid[],Blue},Rotate[{Opacity[.7],Green,Cuboid[]},45Degree,{0,1,0}]},Axes->True,AxesLabel->{"x","y","z"},Background->LightGreen,ImageSize->500,ViewPoint->Back]

Rotate the Cuboid at standard position, 60 degrees CCW about the z axis. Show a before and after position for the cuboid:

Graphics3D[{{Opacity[.2],Cuboid[],Blue},Rotate[{Opacity[.7],Lighter[Cyan],Cuboid[]},60Degree,{0,0,1}]},Axes->True,AxesLabel->{"x","y","z"},Background->LightBlue,ImageSize->500,ViewPoint->{0.8,0.8,1.0}]

Rotate the Cuboid at standard position, -60 degrees CW about the z axis. Show a before and after position for the cuboid.

Graphics3D[{{Opacity[.2],Cuboid[],Blue},Rotate[{Opacity[.4],Hue[.655],Cuboid[]},-60Degree,{0,0,1}]},Axes->True,AxesLabel->{"x","y","z"},Background->LightGray,ImageSize->500]

Rotate the Cuboid 165.12905554773627 Degrees CCW about the axis {0.4870584738481486`, -0.8436100229619508`, 0.22604462437945558`}:

Graphics3D[{{Opacity[.2],Cuboid[],Blue},Rotate[Cuboid[],165.12905554773627`Degree,{0.4870584738481486`,-0.8436100229619508`,0.22604462437945558`}]},Axes->True,AxesLabel->{"x","y","z"},Background->LightYellow,ImageSize->500]

Notebook Note:  Right-Hand Coordinate System used. CW=Clockwise and CCW=Counterclockwise=Anticlockwise.

Translate the cuboid by {0.5,0.5,0.5} in x,y,z respectively. Show a before and after position for the cuboid:

Graphics3D[{Orange,Cuboid[{0.6,0.5,0.4}],Blue,Opacity[.2],Cuboid[]},Axes->True,AxesLabel->{"x","y","z"},Background->Lighter[Lighter[Lighter[Orange]]],ImageSize->500]

Using Scale: Streach the one unit cuboid in the +x direction by 1/2 unit. Show the cuboid before the scaling and the scaled addition in the same plot.

Graphics3D[{{Blue,Opacity[.1],Cuboid[]},Scale[{Opacity[.1],Red,Cuboid[]},{1+1/2,1,1},{0,0,0}]},Axes->True,AxesLabel->{"x","y","z"},Background->LightMagenta,ImageSize->500]

Using Scale on a 3D graphic: Shrink the one unit cuboid by 1/2 unit in x,y,z respectively. Show the cuboid before and after the scaling down in the same plot.

Graphics3D[{{Blue,Opacity[.1],Cuboid[]},Scale[{Opacity[.1],Red,Cuboid[]},{1/2,1/2,1/2},{0,0,0}]},Axes->True,AxesLabel->{"x","y","z"},Background->LightPurple,ImageSize->500]

Shearing a 3D graphic, plot 1 of 2:  Show the cuboid before the shearing and the sheared cuboid image in the same plot.

cube={Cuboid[],Opacity[1]};
Graphics3D[{{Opacity[.1],Blue,cube},GeometricTransformation[{Opacity[.1],Red,cube},ShearingTransform[45Degree,{1,0,0},{0,0,1},{0,0,1}]]},Axes->True,AxesLabel->{"x","y","z"},Background->LightPurple,ImageSize->500]

Shearing a 3D graphic, plot 2 of 2:  For clarity, show only the sheared cuboid in this plot.

cube={Cuboid[],Opacity[1]};
Graphics3D[{GeometricTransformation[{Opacity[.1],Red,cube},ShearingTransform[45Degree,{1,0,0},{0,0,1},{0,0,1}]]},Axes->True,AxesLabel->{"x","y","z"},Background->LightPurple,ImageSize->500]

An example using Mathematica's Magnification function:

Table[Style[Graphics3D[{Lighter[Green,.1],Cuboid[]},Lighting->"Neutral",ImageSize->100],Magnification->magPowers],{magPowers,{0.5,1.0,2.0,3.0,4.0}}]

Mathematica 6.0.1.  10-28-2008 and typos, 11-08-2008.