.
Curved Surfaces 18.november.1997 GFX

by Hin Jang
revised on 16.january.1999

A non-planar surface can be represented by a set of parametric curves. The cubic polynomials are of the form

   x(t)  =  axt3 + bxt2 + cxt + dx
   y(t)  =  ayt3 + byt2 + cyt + dy
   z(t)  =  azt3 + bzt2 + czt + dz

   0 <= t <= 1

or, as a vector equation,
   p(t)  =  at3 + bt2 + ct + d

As a product of two matrices
   p(t)  =  T . C

where

   T  =  [t3  t2  t  1]

         |  ax  ay  az  |
   C  =  |  bx  by  bz  |
         |  cx  cy  cz  |  
         |  dx  dy  dz  |

The coefficient matrix can be written as C = M . G, where M is a 4X4 basis matrix, and G is a four-element geometry vector. As such,
   p(t)  =  T  .  M  .  G

                       | m11  m12  m13  m14 | | G1 |
         = [t3 t2 t 1] | m21  m22  m23  m24 | | G2 |
                       | m31  m32  m33  m34 | | G3 |
                       | m41  m42  m43  m44 | | G4 |

G1 and G2 are the endpoints of the curve. G3 is the tangent vector at G1 and G4 is the tangent vector at G2. The strategy to calculate the basis matrix first substitutes parameter values t = 0 and t = 1 into the x component of the curve to give x(0) = G1 = [0 0 0 1]M . G and x(1) = G2 = [1 1 1 1]M . G. At these endpoints, their respective derivatives are x'(0) = G3 = [0 0 1 0]M . G and x'(1) = G4 = [3 2 1 0]M . G. In matrix form,

   | G1 |           | 0  0  0  1 |
   | G2 |  =  G  =  | 1  1  1  1 | M  .  G
   | G3 |           | 0  0  1  0 |
   | G4 |           | 3  2  1  0 |

Since G = M-1M . G, then
                        -1
         | 0  0  0  1 |          |  2  -2   1   1 |
   M  =  | 1  1  1  1 |      =   | -3   3  -2  -1 |
         | 0  0  1  0 |          |  0   0   1   0 |
         | 3  2  1  0 |          |  1   0   0   0 |

The elements of matrix product B = T . M are called blending functions because they blend the contributions of the control points (ie. the geometry vector) that define the curve. The cubic curve p(t) can now be written as

   p(t)  =  T  .  M  .  G

         =  B  .  G

         =  (2t3 - 3t2 + 1)G1  +  (-2t3 + 3t2)G2  +  (t3 - 2t2 + t)G3  +  (t3 - t2)G4

Suppose the points of G vary by small amounts and the path on which these values change is parameterised on t. And consider further that F(s) = S . M . G. Then,

                                             | G1(t) |
   F(s, t)  =  S  .  M  .  G(t)  =  S  .  M  | G2(t) |
                                             | G3(t) |
                                             | G4(t) |

For the fixed value t0, F(s, t0) is a curve. For another fixed value, say t1, then F(s, t1) is also a curve. The set of all such curves defines a surface. If Gi(t) are cubic,
   Gi(t)  =  T  .  M  .  Gi

Transposing the equation Gi(t) = T . M . Gi gives Gi(t) = GiT . MT . TT, which leads to the following general form of the surface [4].
   x(s, t)  =  S  .  M  .  Gx  .  MT  .  TT
   y(s, t)  =  S  .  M  .  Gy  .  MT  .  TT
   z(s, t)  =  S  .  M  .  Gz  .  MT  .  TT

A popular representation of a parametric surface was developed independently by French engineers de Casteljau and Bézier. Although evidence indicates that de Casteljau was first to make the discovery, Bézier had his findings published first. As such, the parametric entity carries his name: the Bézier surface. A fast method to render such a surface is adaptive forward differencing.

Surface Intersection
The ideal algorithm to find the intersection of two surfaces P(s, t) and Q(u, v) must be numercially reliable and capable of operating on general surface models [3]. Provided that each component of the start point on the intersection is found, the sequence of points along the curve is then evaluated. This process of tracing the curve results in decomposing the curve into segments, useable by whatever application that requires the intersection of the two surfaces. Krishnan and Manocha developed such an algorithm that employs a variety of matrix computations.

The intersection curve between the surfaces

   P(s,t)  =  (X(s,t), Y(s,t), Z(s,t))
   Q(u,v)  =  (X'(u,v), Y'(u,v), Z'(u,v))

is found by substituting the parameterisation of Q(u,v) into f(x,y,z) = 0, the implicit form of P(s,t), to yield the matrix polynomial M'(u,v) whose roots are the start points of the curve. The implicit representation of a surface is found by applying Cayley's Method, an algebraic device that yields the resultant of a set of polynomials, to surface patches [9]. The resultant is an expression involving the coefficients of a set of polynomials such that det(A) = 0, where A is the coefficient matrix, is a necessary and sufficient condition for the polynomials to have a common nontrivial root. Cayley made the observation that given two polynomials f(x) = ax 2 + bx + c and g(x) = a'x 2 + b'x + c' with a common root x = x0, the equation
   f(x)g(µ) - f(µ)g(x)  =  0

will be satisfied by that common root and any value of µ. The equation will always be satisfied for x = µ, so the expression contains (x - µ) as a factor. The resultant of f(x) and g(x), for example, is found by the setup
   f(x)g(µ) - f(µ)g(x)
  ---------------------
         (x - µ)


      (ax2 + bx + c)(a'µ2 + b'µ + c') - (aµ2 + bµ + c)(a'x2 + b'x + c')
   = ------------------------------------------------------------------
                                   (x - µ)

   = [(ab' - a'b)x + (ac' - a'c)]µ + [(ac' - a'c)x + (bc' - b'x)]

For a common root x = x0
   | (ab' - a'b)  (ac' - a'c) | | x |  =  0     or    Ax = 0
   | (ac' - a'c)  (bc' - b'c) | | 1 |

The resultant of the two nonhomogeneous polynomials is the determinant of A. If a curve is defined by parametric equations
   x(t)  =  a2t2 + a1t + a0
   y(t)  =  b2t2 + b1t + b0

the resultant of these pair of equations is the implicit form of the parametric curve.

Hidden Surface Removal
The visible region of a surface P(s, t), from a given viewpoint, is bounded by silhouettes and visibility curves [6]. The normal vector along a silhouette is orthogonal to the viewing direction. The extent of a surface boundary is a visibility curve if its projection intersects some closed region R. In the diagram below, the figure on the left is the surface and the figure on the right identifies the endpoints of the two visibility curves. The curve <A', B'> is shown offset for clarity.

   +-----------+                     +-----------+
   |           |                     |          A| A'
   |      +---------------+          |      +----+ +--------+
   |      |               |          |      |      |        |
   |      |               |          |      |      |        |
   |      +---------+     |          |      +----+ +--+     |
   |           |    |     |          |          B| B' |     |
   |           +----+     |          |           +----+     |
   |                      |          |                      |
   |                      |          |                      |
   +----------------------+          +----------------------+

Once the patch is partitioned based on silhouettes and visibility curves, each region can be treated as a polygon and rendered accordingly. The computation of the visibility curves involves 1) finding all intersections of the projected boundary curves and 2) tracing each visibility curve [6].

The solution to the intersection between two boundary curves f and g parameterised by u and v respectively, is

   Xf(u)     Xg(v)             Yf(u)     Yg(v)
   -----  =  -----     and     -----  =  -----
   Wf(u)     Wg(v)             Wf(u)     Wg(v)

Eliminating u from these equations is achieved by a method similar to Cayley's Method the yield a matrix polynomial M'(v). The eigenvalues of M'(v) form all intersection points. A boundary curve is self-intersecting if there exists parameter values u and v such that
   (X(u)W(v) - X(v)W(u))            Y(u)W(v) - Y(v)W(u))
   ---------------------  =  0      --------------------  =  0
          (u - v)                         (u - v)

Applying Cayley's Method eliminates u from these equations to yield a (2n - 2) x (2n - 2) matrix polynomial M'(v) of degree n - 1. The eigenvalues of this matrix of size 2(n - 1) 2 form all intersection points. The intersection between two silhouette curves and the intersection between a boundary curve and a silhouette require the use of the Bentley - Ottmann algorithm.

Rendering of Parametric Surfaces
Surfaces can be represented by a control mesh of points rather than a family of cubic polynomials. Algorithms to render these subdivision surfaces have been the subject of research for many years. A method that is fast, uses little memory and is easy to parallelise subdivides the control mesh into triangle pairs and renders these patches separately [11].

A control mesh that is regularly tesselated can be stored in a two-dimensional, square array of extent 2 j at a subdivision level j. The connectivity of a vertex vi with its neighbours and shared edges can be obtained easily by their respective locations in the array. Subdividing the surface from one level to the next results in quadruple the amount of triangles. The process of subdividing the surface begins with obtaining the first row of vertices of the refined mesh (level j + 1) by splitting the vertical and diagonal edges between the second and first row of vertices of the unrefined mesh (level j). Splitting the horizontal edges and updating the vertices of the second row of the unrefined mesh gives rise to the second row of the refined mesh. The third row is obtained by splitting the vertical and diagonal edges connecting the second and third rows of the unrefined mesh. With the top three rows initialised as such, the algorithm proceeds to subdivide, recursively, the remaining rows at level j. If the extent of subdivision is known, however, the algorithm can be unrolled to form an iterative solution.


   Subdivide(level, last)
   {
      if (level != last) {
          split horizontal edges and update vertices
          Subdivide(level+1, last)
          split vertical and horizontal edges
          Subdivide(level+1, last)
      } else {
          calculate vertex locations and normals
          RenderTriangles()
      }
   }

For a control mesh that is not regularly tesselated, the location of new vertices in the refined mesh is found by the weighted average of vertices in the unrefined mesh [5]. A given control mesh M is defined by 1) a simplicial complex K specifying the connectivity of vertices, edges and faces, and 2) a set of vertex positions V, specifying the shape of the mesh. Subdivision carries mesh M r = ( K r, V r ) into a refined mesh M r+1 = ( K r+1, V r+1 ). The vertices of V r+1 are affine combinations of the vertices of V r according to the following subdivision rules [8].
              a(n)vr + v1r + ... + vnr
   vr+1  =  ----------------------------
                      a(n) + n


               3vr + 3vir + vi-1r + vi+1r
   vir+1  =  ------------------------------ ,   i = 1, ... n
                         8

and
             n(1 - þ(n))
   a(n)  =  --------------
               þ(n)

where

             5       (3 + 2cos(2 pi / n))2
   þ(n)  =  ---  -  -----------------------
             8                64

The affine combination of four vertices, for example
     A                   B
       +---------------+
        \             / \
         \           /   \
          \         /     \
           \       m       \
            \     /         \
             \   /           \
              \ /             \
               +--------------+
             C                  D

yields a new vertex at location
          A + 3B + 3C + D
   m  =  -----------------
                 8

Once all triangles of the refined mesh are formed, the algorithm determines an optimal pairing of triangles. The criterion on which triangles form a pair is based on a greedy algorithm that inserts each triangle into one of four sets. Triangles with zero or one neighbour have the highest priority (0). Triangles with three neighbours have lowest priority (3). The algorithm selects a triangle from the highest nonempty set and pairs it with a neighbour of highest priority. The pair is rendered and removed from the set. The remaining triangles are then promoted to a higher priority set. Rendering of the entire surface is complete when all sets are empty.
   set      neighbours

    0        0 or 1

    1        2, one of them in set 0 or 1

    2        2, both of them in set 3

    3        3



[1] Bézier, P., Procédé de définition numérique des courbes et surfaces non mathématiques. Automatisme, XIII(5):189-196, 1968

[2] Bézier, P., Mathematical and Practical Possibilities of UNISURF. In R. Barnhill and R. Riesenfeld, editors, Computer Aided Geometric Design, Academic Press, 127-152, 1974

[3] Bézier, P., Essay de définition numérique des courbes et des surfaces expérimentales. Ph.D. dissertation, University of Paris VI, France, 1977

[4] Foley, J.D., A. van Dam, S.K. Feiner, and J.F. Hughes, Computer Graphics Principles and Practice, Second Edition, Addison-Wesley, Reading, 478-529, 1990

[5] Hoppe, H., T. DeRose, T. Duchamp, M. Halstead, H. Jin, J. McDonald, J. Schweitzer, and W. Stuetzle, "Piecewise Smooth Surface Reconstruction," Computer Graphics, SIGGRAPH 1994 Proceedings, 28(4):295-302

[6] Krishnan, S., and D. Manocha, An Efficient Surface Intersection Algorithm based on Lower Dimensional Formulation, TR94-062, Department of Computer Science, University of North Carolina, 1994

[7] Krishnan, S., and D. Manocha, Hidden Surface Removal Algorithms for Curved Surfaces, TR94-063, Department of Computer Science, University of North Carolina, 1994

[8] Loop, C., Smooth Subdivision Surfaces Based on Triangles, Master's thesis, Department of Mathematics, University of Utah, August 1987

[9] Manocha, D., and J. Demmel, "Algorithms for Intersecting Parametric and Algebraic Curves I: Simple Intersections," ACM Transactions on Graphics, 13(1):73-100, January 1994

[10] Pulli, K., and M. Lounsbery, Hierarchical Editing and Rendering of Subdivision Surfaces, TR-97-04-07, Department of Computer Science and Engineering, University of Washington, April 1997

[11] Pulli, K., and M. Segal, Fast Rendering of Subdivision Surfaces, TR-96-03-02, Department of Computer Science and Engineering, University of Washington, 1996

[12] Sederberg, T.W., D.C. Anderson, and R.N. Goldman, "Implicit Representation of Parametric Curves and Surfaces," Computer Vision, Graphics and Image Processing, 28(1):72-84, October 1984


.
Constructive Solid Geometry 28.september.1997 GFX

by Hin Jang

Applying a series of Boolean operators on a set of primitives yields a complex solid. Constructive solid geometry (CSG) is the means by which such solids are formed. Each primitive, of which the block, cone, cylinder, sphere and right angular wedge are typical, is defined by a combination of finite half-spaces. Composite CSG primitives may also be subject to the Boolean operators of union, intersection and difference. The union of two primitives yields an object that encloses the space occupied by the primitives. Intersection yields an object that encloses the common space of the primitives. Difference yields an object that is the first primitive minus the space where the second intersected the first. The CSG model is stored in a tree with operators at the internal nodes and primitives at the leaves. As such, the shape of the object and the process of building the object is implicitly described in a single data structure.

Kumar et al developed a system to efficiently and accurately display a complex CSG model [6]. At the pre-process phase, the system performs a depth first traversal to compute the boundary representation of the model, a description in terms of Bézier surfaces. These surfaces are trimmed along their intersection. The representation of the trimming curves c0, ... , cn consist of

Given the trimmed surfaces, they are tesselated into triangles and rendered accordingly to yield the CSG model. The tesselation phase requires a piecewise linear representation of each trimming curve ci as a function of viewing parameters. This implies dynamic tesselation, and therefore, a multiresolution representation of trimming curves. More points between the endpoints are generated in the following manner The rendering algorithm for trimmed surfaces is then

   Render()
   {
      create a set of rectangular domain cells D from the
        uniform tesselation of the surface
      for (each trimming curve ci) {
         compute the required tesselation for ci
         tesselate ci into straight line segments
         traverse the piecewise linear curve segments to mark
           all domain cells crossed by the curve.  exact
           intersections are not required.
      }
      triangulate each unmarked cell that lies in the trimmed
        region by adding a diagonal
      DrawTriangles()
      there exists a region between the trimming curve and the
        polygonal chain that represents the boundary of unmarked
        cells.  triangulate this region.
      DrawTriangles()
      }
   }  



[1] Dekkers, D., K. van Overveld, and R. Golsteijn, Combining CSG Modeling with Soft Blending Using Lipschitz-based Implicit Surfaces, October 29, 1996

[2] DeRose, T., M. Lounsbery and J. Warren, Multiresolution Analysis for Surfaces of Arbitrary Topology Type, TR-93-10-05, Department of Computer Science, University of Washington, 1993

[3] Hoffmann, C.M., J.E. Hopcroft, and M.S. Karasick, Robust Set Operations on Polyhedral Solids, TR-87-875, Department of Computer Science, Cornell University, October 1987

[4] Hubbard, P.M., Constructive Solid Geometry for Triangulated Polyhedra, CS-90-07, Department of Computer Science, Brown University, September 1, 1990

[5] Krishnan, S., and D. Manocha, An Efficient Surface Intersection Algorithm based on Lower Dimensional Formulation, TR94-062, Department of Computer Science, University of North Carolina, 1994

[6] Kumar, S., S. Krishnan, D. Manocha, and A. Narkhede, Representation and Fast Display of Complex CSG Models, TR95-019, Department of Computer Science, University of North Carolina, 1995

[7] Mazzetti, M., and L Ciminiera, "Computing CSG Tree Boundaries as Algebraic Expressions," ACM Proceedings on the Second Symposium on Solid Modeling, 155-162, 1993

[8] Stewart, A.J., "Local Robustness and its Application to Polyhedral Intersection," International Journal of Computation Geometry and Applications, 4(1):87-118, 1994

[9] Zhu, X., S. Fang, B.D. Brüderlin, "Obtaining Robust Boolean Set Operations for Manifold Solids by Avoiding and Eliminating Redundancy," ACM Proceedings on the Second Symposium on Solid Modeling, 147-154, 1993


.
Invertible Object Rotation 30.september.1997 GFX

by Hin Jang

Rotation in three-dimensions can be expressed as a composition of three rotations about the three coordinate axes by rotational angle t, polar angle p and azimuth angle s. The overall rotation R can be rewritten in terms of three rotations about only two of the original axes if the tranformation is parametrised under the Euler angles a, b, and c


   R(a, b, c)  =  R3(a)R2(b)R3(c)  =  Q3Q2Q1

Rotation of an object, in the same domain, is also possible using three shears [2]. Decomposing Q3, Q2 and Q1 gives rise to the following shear products
   Q1 = S13S12S11

        | 1   -tan(c/2)   0 | |  1       0     0 | | 1   -tan(c/2)   0 |
      = | 0       1       0 | | sin(c)   1     0 | | 0       1       0 |
        | 0       0       1 | |  0       0     1 | | 0       0       1 |

   Q2 = S23S22S21

        | 1    0  -tan(b/2) | |   1      0     0 | | 1    0   tan(b/2) |
      = | 0    1      0     | |   0      1     0 | | 0    1      0     |
        | 0    0      1     | | -sin(b)  0     1 | | 0    0      1     |

   Q3 = S33S32S31

        | 1   -tan(a/2)   0 | |  1       0     0 | | 1   -tan(a/2)   0 |
      = | 0       1       0 | | sin(a)   1     0 | | 0       1       0 |
        | 0       0       1 | |  0       0     1 | | 0       0       1 |
and thus

   Q = Q3Q2Q1 = S33S32S31  S23S22S21  S13S12S11

The nine matrices differ from the identity matrix by the element on row u and column v. This element specifies the rate of shearing along axis u and across axis v. The general form of a shear along axis 1 is a triangular matrix with unit diagonal
       | 1  d  e |     | 1  0  0 | | 1  d  e |
   S = | 0  1  f |  =  | 0  1  f | | 0  1  0 |  =  STSL
       | 0  0  1 |     | 0  0  1 | | 0  0  1 |
where ST shifts image lines parallel to axis 1 along the axis and SL shifts these lines sideways along axis 2. Rearranging the factors of Q gives rise to a product of three shears [2]. As such,

   Q = S3S2S1

where
   S1  =
          |                         cos(a - c)tan(b/2)    |
          |  1    -tan(a + c)/2    -------------------    |
          |                             cos(a + c)        |
          |                                               |
          |  0          1             -sin(c)tan(b/2)     |
          |                                               |
          |  0          0                    1            |


   S2  =
          |      1                   0               0    |
          |                                               |
          | -sin(a + c)              1               0    |
          |                                               |
          |                  -sin(a - c)sin(b)            |
          |  cos(c)sin(b)   -------------------      1    |
          |                     cos(a + c)                |


   S3  =
          |  1         -tan(a + c)/2       cos(a)tan(b/2) |
          |                                               |
          |  0               1             sin(c)tan(b/2) |
          |                                               |
          |  0               0                    1       |



[1] Paeth, A., "A Fast Algorithm for General Raster Rotation," Graphics Gems, A. Glassner, ed., Academic Press, New York, 179-195, 1990

[2] Toffoli, T., and J. Quick, "Three-Dimensional Rotations by Three Shears," Graphical Models and Image Processing, 59(2):89-95, March 1997