Graphics Reference
In-Depth Information
Figure 1.9.
Turtle crawling on cube.
This project is more advanced and requires familiarity with vectors. It also needs the
formula for the intersection of two segments discussed in Section 6.5. To display a turtle crawl-
ing on a cube we use a parallel projection of a three-dimensional cube into the plane. In this
way, the path of the turtle can be described via linear combinations of planar vectors without
involving any knowledge of transformations from R 3 to R 2 . See Figure 1.9(a) for what one
should see. Note that walking in a straight line preserves the angle the path makes with an edge
as the edge is crossed. Ignore the case where a path meets a vertex of the cube. One can let the
turtle disappear there.
The key idea is that, at any time, the turtle is in a face of the cube which one can identify
with a fixed square. The parallel projection then maps this square onto a parallelogram. See
Figure 1.9(b) where we map the square A with vertices a , b , c , and d onto the parallelogram
A ¢ with vertices a ¢, b ¢, c ¢, and d ¢, respectively. If p is an arbitrary point of A , write p in the form
a + s ab + t ad .
The parallel projection will then map p to
a ¢ + s a ¢ b ¢ + t a ¢ d ¢ .
Therefore, the basic steps are:
(1)
Pick points a i in the plane onto which the vertices of the cube (one may as well use
the standard unit cube [0,1] ¥ [0,1] ¥ [0,1]) get mapped.
(2)
Keep track of the face the turtle is on along with the identification of its vertices with
the given vertices in the plane.
(3)
When moving forward a certain distance d from a point p , check if this entails cross-
ing an edge. If yes, then move only to the point on the edge and move the remaining
distance in the new face in the next step. Let q be the end point of the current segment
through which we moved.
(4)
Find the segment p ¢ q ¢ which is the image of the segment pq and draw it.
(5)
Repeat steps (3) and (4) until one has moved forward the distance d. If we crossed an
edge, then we may have to update the face we are on.
Search WWH ::




Custom Search