.. title: CG Class 24, Thur 2019-11-21
.. slug: class24
.. date: 2019-11-21
.. tags: class
.. category:
.. link:
.. description:
.. type: text
.. has_math: true

.. sectnum::
.. contents:: Table of contents


Week 13 slides ctd
------------------

#. `13_4 Display issues <https://wrf.ecse.rpi.edu/Teaching/graphics/SEVENTH_EDITION/PPT/WEEK13/Angel_UNM_14_13_4.ppt>`_.

   We've seen some of this.


Chapter 14
----------

#. Curves are the next chapter of Angel.  WebGL does this worse than full OpenGL.  Here is a summary.
   Big questions:

   #. What math to use?

   #. How should the designer design a curve?

   #. My notes on `Bezier curves <https://wrf.ecse.rpi.edu/p/77-sorsa92-bezier.pdf>`_.

#. Partial summary:

   #. To represent curves, use parametric (not explicit or implicit) equations.

   #. Use connected strings or segments of low-degree curves, not one hi-degree curve.

   #. If the adjacent segments match tangents and curvatures at their common joint, then the joint is invisible.   

   #. That requires at least cubic equations.

   #. Higher degree equations are rarely used because they have bad properties such as:

      #. less local control.   Changing one control point of a hi-degree curve changes the whole curve.   Parts of the curve distant from that point may move a lot.   This makes designing a desired curve impossible.

      #. numerical instability.   Small changes in coefficients cause large changes in the curve, even if computations are exact.

      #. roundoff error.  Computations are not exact.

   #. See my note on `Hi Degree Polynomials <http://wrf.ecse.rpi.edu/pmwiki/Research/HiDegreePolynomials>`_.
      
   #. One 2D cartesian parametric cubic curve segment has 8 d.f. in 2D (12 in 3D).

      :math:`x(t) = \sum_{i=0}^3 a_i t^i`,  

      :math:`y(t) = \sum_{i=0}^3 b_i t^i`, for :math:`0\le t\le1`.

   #. Requiring the graphic designer to enter those coefficients would be
      unpopular, so other APIs are common.

   #. Most common is the *Bezier* formulation, where the segment is
      specified by 4 control points, which also total 8 d.f.: P0, P1, P2, and
      P3.

   #. The generated curve starts at P0, goes near P1 and P2, and ends at P3.  

   #. The curve stays inside the control polygon, the convex hull
      of the control points.  A flatter control polygon means a
      flatter curve.  Designers like this.

   #. A choice not taken would be to have the generated curve also go thru P2
      and P3.  That's called a Catmull-Rom-Oberhauser curve.  However that
      would force the curve to go outside the control polygon by a
      nonintuitive amount.  That is considered undesirable.

   #. Instead of 4 control points, a parametric cubic curve can also be specified by a
      starting point and tangent, and an ending point and tangent.  That also
      has 8 d.f.  It's called a Hermite curve.

   #. The three methods (polynomial, Bezier, Hermite) are easily interconvertible.

   #. Remember that we're using connected strings or segments of cubic
      curves, and if the adjacent segments match tangents and curvatures at
      their common joint, then the joint is invisible.

   #. Matching tangents (called :math:`G^1` or geometric continuity) is sufficient, and is weaker than matching the 1st derivative (:math:`C^1` or parametric continuity), since the 1st derivative has a direction (tangent) and a length.   Most people do :math:`C^1` because it's easier and good enough.  However :math:`G^1` gives you another degree of freedom to use in your design.

   #. Similarly, matching the radius of curvature (:math:`G^2` or geometric continuity) is weaker than matching the 2nd derivative (:math:`C^2` or parametric continuity), but most people do parametric continuity.

   #. Parametric continuity reduces each successive segment from 8 d.f. down to 2 d.f.

   #. This is called a B-spline.

   #. From a sequence of control points we generate a B-spline curve that is
      piecewise cubic and goes near, but probably not thru, any control point
      (except perhaps the ends).

   #. Moving one control point moves the adjacent few spline pieces.  That is
      called *local control*.  Designers like it.

   #. One spline segment can be replaced by two spline segments that,
      together, exactly draw the same curve.  However they, together, have
      more control points for the graphic designer to move individually.  So
      now the designer can edit smaller pieces of the total spline.

   #. Extending this from 2D to 3D curves is obvious.

   #. Extending to homogeneous coordinates is obvious.  Increasing a control
      point's weight attracts the nearby part of the spline.  This is called
      a *rational* spline.

   #. Making two control points coincide means that the curvature will not be
      continuous at the adjacent joint.  

      Making *three* control points coincide means that the *tangent*
      will not be continuous at the adjacent joint.

      Making *four* control points coincide means that the *curve* will
      not be continuous at the adjacent joint.

      Doing this is called making the curve (actually the knot sequence)
      *Non-uniform*.  (The knots are the values of the parameter for the joints.)

   #. Putting all this together gives a non-uniform rational B-spline, or a *NURBS*.

   #. A B-spline *surface* is a grid of patches, each a bi-cubic parametric polynomial.   

   #. Each patch is controlled by a 4x4 grid of control points.

   #. When adjacent patches match tangents and curvatures, the joint edge is invisible.  

   #. The surface math is an obvious extension of the curve math.

      #. :math:`x(u,v) = \sum_{i=0}^3\sum_{j=0}^3 a_{ij} u^i v^j`

      #. :math:`y, z` are similar.

      #. One patch has 48 d.f. for Cartesian points, or 64 d.f. for homogeneous points, although most of those are used to establish
         continuity with adjacent patches.

#. My extra enrichment info on `Splines <//wrf.ecse.rpi.edu/pmwiki/Research/Splines>`_.

#. The program I showed earlier is robotArm is  `Chapter 9 <https://wrf.ecse.rpi.edu/Teaching/graphics/SEVENTH_EDITION/CODE/Code%20new/09/>`_.

#. To run program figure there, you may first need to fix an error in figure.html.  Change *InitShaders* to *initShaders*.

   Many of the textbook programs have errors that prevent them from running.   You can see them in the console log.


Additive manufacturing (3D printing) and curves
-----------------------------------------------

#. This section contains material that is too new for most (all?) textbooks.

#. However I see that a big part of my job is to identify stuff like this for you.

#. Nevertheless, I don't know everything here.  If someone in class is more knowledgeable, please speak up.   

#. I learned some of this attending the `International Meshing Roundtable <https://imr.sandia.gov/>`_ in Buffalo in Oct.

#. One reason for designing with curved surfaces like NURBS is that machine tools like lathes make curves.

#. Also, rotating things like turbines rotate in curves.

#. However, NURBS have always had some problems.  E.g., exactly intersecting two surfaces is infeasible.   You had to approximate the intersection curve separately on the two surfaces.   Those two approximate curves were slightly different, and so the object wasn't completely watertight.

#. Also, some desirable operations, like offset surfaces, were always impossible to do exactly.

#. Now, additive manufacturing changes the game.

#. It's not easier to manufacture curved surfaces.

#. In fact, designing with flat faces, like triangles, is easier.

#. So, designers may now design objects with millions of triangles.

#. How do we handle objects that really want curves, like rotating objects?  Use lots of small triangles.   

