[WPI] [cs4731] [Classes]

cs4731, D96/97 Class 15

Clipping

The primary advantage of the clipping algorithm shown in Class 12 is that it can be used to clip to any convex polygon. If the clipping polygon in Homework 3, Question 2 is rotated and scaled to make it a rhombus that just fits into the digital image, this is what results. Note that the clipping polygon was rendered, too, to make it look as if the initials are seen through a window.

Flood Fill Trick

One way to prevent flood fill from crashing your computer if something goes wrong (the starting point is outside the polygon, for example) is to save the border pixels in the digital image, outline the digital image in the fill color, render and fill the polygon with the fill color, and restore the original border pixels. If the border is made black, it appears as a frame around the image and the trick is not obvious. This image was made using the same algorithm as Homework 2, Question 2, except that the squares are larger.

Tweening

The selection of which points correspond in tweened images, as in Homework 3, influences the visual effect. In these two Quicktime movies, the same data are used, but the correspondence is different. Also, the first shows the effect of twening slightly outside the range (0 - 1). Note, these movies are large (~300K).

Data Structure

In order to make it possible to bind together object descriptions and properties, a new structure, the object, was introduced. See the notes in Class 18.

Extrusion and Lathing

The easiest way to form 3D objects from 2D polylines are the related proceses of extrusion and lathing.

In extrusion, a polygon is turned into six planar surfaces, marked 1-6 in this drawing. Polygon 1 is the original polygon. Polygon 2 is obtained by making a copy of polygon 1 shifted some distance away. And, the direction of Polygon 2 has to be reversed, as shown, so that its surface normal points out of the volume.

The other four Polygons, 3, 4, 5, and 6, are made by taking the points of the original polygon (Polygon 1) in pairs. The first two points are copied shifted away from the original. Then the four points are joined into a polyline to define Polygon 3. The same operation is applied the rest of the point pair in Polygon 1 to produce the new polygons Polygon 4, 5, and 6. Note that the directions of each of these polygons makes their normals point out of the volume. Each edge (connection between successive points) exists in two polygons. One way to tell if you got the directions correct is that the two edges between each point pair runs in opposite directions.

Lathing is similar to extrusion in that pairs of points are shifted to produce rectangular polygons. The difference is that the end caps (Polygons 1 and 2 above) are not put on. The "shift" is just produced by rotation about an axis, y in this case. In this drawing, Polygon 1 is the original polygon. It is rotated through an angle to produce Polygon 1', which is partially hidden. The points in Polygon 1 and 1' are used in pares to produce Polygons 2, 3, and 4. Note that Polygons 1 and 1' are not actually used in the final drawing. They are just used to draw Polygons 2 (partially hidden), 3, and 4. If this process is repeated until the points have rotated 360° around the y axis, a closed, cylindrically-symetric figure results.

When doing lathing, there are two things to note. First, any point on the polygon that is on the rotation axis needs to produce just one point per polygon, not two. Be careful that your algorithm doesn't duplicate axial points -- duplicated points are always a problem in computer graphics. Second, if any edge of the original polygon lies completely along the axis of rotation -- such as the left edge in Polygon 1, don't use it to produce another polygon. A polygon of zero width lying along the axis can confuse some rendering programs and divide the internal volume of the new polyhedron.

Extrusion and lathing can be used on all types of polygons, simple, complex, convex or concave.

 


 
WPI Home Page
[cs4731] [Classes]

Contents ©1997, Norman Wittels
Updated 19Apr97