Learning Center
Plans & pricing Sign in
Sign Out



									    159.235 Graphics & Graphical
          Lecture 20 - 3D Shapes & Polygons

159.235                 Graphics              1
            Polygons -Outline
•   What are polygons?
•   Types
•   Convexity/concavity
•   Triangles
•   Storage of vertices and edges
•   Rendering wire-frames as lines and points

159.235               Graphics                  2
           Polygonal Surfaces
• Polygon surfaces are a simple form of
  representation used in most applications
• Used in all real-time displays as fast to process
• Other descriptions such as Splines might be used
  in some applications but are generally reduced to
  polygons for processing.
• Polygon surfaces readily integrated with scan-line

159.235                Graphics                    3
     Scan Conversion of Polygons
• Fill the polygon with colour.
• Incorporate in a scan conversion algorithm.
• We may not be drawing actual pixels due to
  anti-aliasing - jargon is that we tile the
  polygon with pixel ‘fragments’.
                                  Scan line

159.235              Graphics                   4
          Common Types of Polygon
                                      •   Concave
                                      •   Convex
                                      •   Triangles
                                      •   Trapezoids
                                      •   Quadrilaterals
                         Hole         •   Self-intersecting
                                      •   Multiple loops
                                      •   Holes

159.235                    Graphics                     5
  Convexity/Concavity Definition
• A polygon is convex if: for all edges, all other
  vertices lie on the same side of the edge
• Otherwise it is concave.
• Concave polygons often difficult to process
  (algorithms get stuck or miss bits)

          Convex             Concave

159.235               Graphics                 6
              Triangles Always Convex
•   Mathematically, uses simple linear equations.
•   Three points guaranteed co-planar by definition!
•   Any polygon can be decomposed into triangles
•   Triangles can approximate arbitrary shapes
•   For any orientation on screen, a scan line will
    intersect only a single segment (scan).

    159.235              Graphics                7
Polygon decomposition into Triangles

 Convex polygons easy to decompose but if not convex may
 have to add extra vertices to avoid overlaps or intersection
  159.235                     Graphics                          8
       Arbitrary shapes with triangles

Any 2D shape, or 3D surface, can be approximated with locally
linear polygons. To improve just increase the number of edges
   159.235                    Graphics                          9
 Quadrilaterals are simple too and
   often mixed with triangles

159.235         Graphics         10
          Java Swing and Java 3D
• Swing has various 2D • Java 3D is a Sun
  shape classes that      Microsystems (currently
  allow us to implement   free) graphics library that
  various geometries      builds on the 2D stuff from
• Point3d and Vector3d • Supports some very
  objects are a           sophisticated 3D rendering
  convenience           • Start by building our own
                          3D simple renderer

159.235               Graphics                  11
          Polygon Representation
• Could store all vertices •        Store into the vertices
                                   Index all polygonvertex
Polygonal Geometry.
  explicitly - for each            table for each
  polygon                          polygon
                                    • Inefficient
      E3                            • Cannot manipulate vertex
• Makes it hard to edit     •      Need to search for
  the vertices (multiple
                    E1             adjacent polygons
  copies)       P1          •      Do end up drawing
• Easier to store a table V2       edges twice
  of verticesV3             •      Tradeoffs!

159.235                 Graphics                            12
Common Polygonal Data Structures

159.235       Graphics       13
Drawing a Wire-frame 3d Polygon
• Break down into              • Draw the projected
  vertices and edges             line (edge)
• For each edge                • Repeat for each
  determine the two              polygon under given
  vertices                       projection
• Project the vertices
  from world space or
  model coordinates to
  screen coordinates
159.235                  Graphics                      14
              Filling, or ‘tiling’ a triangle.
•   Calculate bounding box for triangle.
•   Loop through pixels in box
•   Test for points lying inside the triangle
•   Draw pixel fragment if inside box
•   Lets us colour in the shape (Java 2D or Swing
    will do this part for us)                 Bounding box

    159.235                 Graphics                    15
              Polygons - Summary
• Various sorts of Polygons
• Convexity often an important property
• Triangles often useful simplest polygonal form
• Can store polygons (or triangles) in various
  ways - tradeoffs depending upon algorithm
• Render wire-frame by decomposing into
  points/lines - need transform to screen
    159.235           Graphics                16

To top