3D-Graphics

We create the 3D graphic images described in Lay's textbook examples 2.7.7 and 2.7.8.

Cell[GraphicsData[PostScript, %!<br />%%Creator: Mathematica<br />%%AspectRatio: 1 <br />Mat ... IfMT00?oo<br />fMWI8OoIfMT00001], ImageRangeCache -> {{{0., 287.}, {287., 0.}} -> {4, 0, 0, 0}}]

Lay Example 2.7.7
A Box in 3-Space

Data points and adjacency matrix

Let S be the box of example 2.7.8.

In[1]:=

<<LinearAlgebra`MatrixManipulation`

In[2]:=

pts = {{3, 1, 5}, {5, 1, 5}, {5, 0, 5}, {3, 0, 5},          {3, 1, 4}, {5, 1, 4}, {5, 0, 4}, {3, 0, 4}} ; 

ones = Table[1, {k, 8}] ; 

vertices = Append[Transpose[pts], ones] ;

%//MatrixForm

adj = ({{0, 1, 0, 1, 1, 0, 0, 0}, {1, 0, 1, 0, 0, 1, 0, 0}, {0, 1, 0, 1, 0, 0, 1, 0}, {1, 0, ... {0, 1, 0, 0, 1, 0, 1, 0}, {0, 0, 1, 0, 0, 1, 0, 1}, {0, 0, 0, 1, 1, 0, 1, 0}}) ; adj//MatrixForm

Out[5]//MatrixForm=

( {{3, 5, 5, 3, 3, 5, 5, 3}, {1, 1, 0, 0, 1, 1, 0, 0}, {5, 5, 5, 5, 4, 4, 4, 4}, {1, 1, 1, 1, 1, 1, 1, 1}} )

Out[6]//MatrixForm=

( {{0, 1, 0, 1, 1, 0, 0, 0}, {1, 0, 1, 0, 0, 1, 0, 0}, {0, 1, 0, 1, 0, 0, 1, 0}, {1, ... , 0, 1}, {0, 1, 0, 0, 1, 0, 1, 0}, {0, 0, 1, 0, 0, 1, 0, 1}, {0, 0, 0, 1, 1, 0, 1, 0}} )

RenderData

The procedure RenderData takes an adjacency matrix and a list of points and plots the associated figure in a small screen.

RenderData is from the file "Case2.nb" available in the Case Studies section of the web site supporting Lay's textbook "Linear Algebra, Third Edition."
It is modified slightly to accomodate the data of these examples.

In[7]:=

n = 8 ;

viewWindow = {{2, 10}, {0, 5}} ; 

RenderData[adjacency_, data_, opts___] := (ptlist = {} ; For[i = 1, i≤n, i ++, ... tlist[[i]]]]] ; Show[Graphics[g, opts], PlotRange->viewWindow, AspectRatio1])

The Box without Perspective

Since we have not implemented perspective at this stage, we simply project the 3d point with coordinates (x,y,z) to the 2d point with coordinatres (x,y).
We are looking down onto the xy-plane from straight above it.

In[10]:=

planarData = vertices[[{1, 2}, All]] ;

%//MatrixForm

viewWindow = {{3, 5}, {0, 2}} ; 

RenderData[adj, planarData, DefaultColorCobalt] ;

Out[11]//MatrixForm=

( {{3, 5, 5, 3, 3, 5, 5, 3}, {1, 1, 0, 0, 1, 1, 0, 0}} )

[Graphics:HTMLFiles/2_3d_graphics_18.gif]

Rotated and Translated Box,
Still without Perspective

In[14]:=

φ = π/6 ;

rot = ({{Cos[φ], 0, -Sin[φ], 0}, {0, 1, 0, 0}, {Sin[φ], 0, Cos[φ], 0}, {0, 0, 0, 1}}) ; 

translate = ({{1, 0, 0, -6}, {0, 1, 0, 4}, {0, 0, 1, 5}, {0, 0, 0, 1}}) ; 

composite = translate . rot ;

composite//MatrixForm

compositeData = composite . vertices//N ;

%//MatrixForm

Out[18]//MatrixForm=

( {{3^(1/2)/2, 0, -1/2, -6}, {0, 1, 0, 4}, {1/2, 0, 3^(1/2)/2, 5}, {0, 0, 0, 1}} )

Out[20]//MatrixForm=

( {{-5.90192, -4.16987, -4.16987, -5.90192, -5.40192, -3.66987, -3.66987, -5.40192}, ... 11.8301, 10.8301, 9.9641, 10.9641, 10.9641, 9.9641}, {1., 1., 1., 1., 1., 1., 1., 1.}} )

Perspective transformations are still not available, so we simply project the 3d point with coordinates (x,y,z) to the 2d point with coordinatres (x,y).
We are looking down onto the xy-plane from straight above it, and the box has been rotated about the y-axis.

In[21]:=

compositePlanarData = compositeData[[{1, 2}, All]] ;

%//MatrixForm

viewWindow = {{-6, -3}, {4, 7}} ; 

RenderData[adj, compositePlanarData, DefaultColorTerreVerte] ;

Out[22]//MatrixForm=

( {{-5.90192, -4.16987, -4.16987, -5.90192, -5.40192, -3.66987, -3.66987, -5.40192}, {5., 5., 4., 4., 5., 5., 4., 4.}} )

[Graphics:HTMLFiles/2_3d_graphics_33.gif]

Lay Example 2.7.8
Viewing with Perspective

In[25]:=

perspective = ({{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 0, 0}, {0, 0, -1/10, 1}}) ; 

perspectiveVertices = perspective . vertices ;

%//MatrixForm

perspectivePlanarData = Table[perspectiveVertices[[i, j]]/perspectiveVertices[[4, j]], {i, 2}, {j, 8}]//N ;

%//MatrixForm

viewWindow = {{4.9, 10.1}, {-.1, 5.1}} ; 

RenderData[adj, perspectivePlanarData, DefaultColorFirebrick] ;

Out[27]//MatrixForm=

( {{3, 5, 5, 3, 3, 5, 5, 3}, {1, 1, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0}, {1/2, 1/2, 1/2, 1/2, 3/5, 3/5, 3/5, 3/5}} )

Out[29]//MatrixForm=

( {{6., 10., 10., 6., 5., 8.33333, 8.33333, 5.}, {2., 2., 0., 0., 1.66667, 1.66667, 0., 0.}} )

[Graphics:HTMLFiles/2_3d_graphics_43.gif]

The larger face is closer to you.


Created by Mathematica  (February 6, 2005) Valid XHTML 1.1!