home *** CD-ROM | disk | FTP | other *** search
/ Avalon - 3D Objects & Resources / Avalon.iso / faqs / algorthm.sfq < prev    next >
Internet Message Format  |  1995-01-01  |  50KB

  1. Path: bloom-beacon.mit.edu!hookup!nntp.cs.ubc.ca!scipio.cyberstore.ca!math.ohio-state.edu!howland.reston.ans.net!pipex!uunet!news.ingr.com!baggins.dazixco.ingr.com!destin!jdstone
  2. From: jdstone@destin.dazixco.ingr.com (Jon Stone)
  3. Newsgroups: comp.graphics.algorithms,comp.answers,news.answers
  4. Subject: comp.graphics.algorithms Frequently Asked Questions (FAQ)
  5. Supersedes: <graphics_779018404@baggins.dazixco.ingr.com>
  6. Followup-To: comp.graphics.algorithms
  7. Date: 9 Oct 1994 10:00:06 GMT
  8. Organization: Intergraph Corp., Boulder CO
  9. Lines: 1369
  10. Approved: news-answers-request@MIT.EDU
  11. Expires: 22 Nov 1994 10:00:03 GMT
  12. Message-ID: <graphics_781696803@baggins.dazixco.ingr.com>
  13. Reply-To: jdstone@ingr.com
  14. NNTP-Posting-Host: destin.dazixco.ingr.com
  15. Summary: This posting contains a list of Frequently Asked
  16.      Questions (and their answers) about computer graphics
  17.      algorithms. It should be read by anyone who wishes to
  18.      post to the comp.graphics.algorithms newsgroup.
  19. Xref: bloom-beacon.mit.edu comp.graphics.algorithms:8978 comp.answers:7712 news.answers:27106
  20.  
  21. Archive-name:       graphics/algorithms-faq
  22. Version:           1.14
  23. Last-Modified:     September 29, 1994
  24. Posting-Frequency: monthly
  25.  
  26.  
  27.  
  28. Welcome to the FAQ for comp.graphics.algorithms!
  29.  
  30. Thanks to all who have contributed.  Corrections and contributions
  31. always welcome.
  32.  
  33. Changed items are marked with a |.
  34. New items are marked with a +.
  35. Items needing input are marked with a ?.
  36.  
  37. All ftp    references are of the form ftp://node/path
  38. All Mosaic references are of the form http://node/path
  39.  
  40. ----------------------------------------------------------------------
  41. Table of Contents
  42. ----------------------------------------------------------------------
  43.  
  44.    0) Charter of comp.graphics.algorithms
  45. |  1) Are the postings to comp.graphics.algorithms archived?
  46.    2) What are some must have books on graphics algorithms?
  47.    3) Are there any online references?
  48.    4) Where is all the source?
  49.    5) How do I rotate a 2D point?
  50.    6) How do I rotate a 3D point?
  51.    7) How do I find the distance from a point to a line?
  52.    8) How do I find intersections of 2 2D line segments?
  53.    9) How do I find the intersection of a line and a plane?
  54.   10) How do I rotate a bitmap?
  55.   11) How do I display a 24 bit image in 8 bits?
  56.   12) How do I fill the area an arbitrary shape?
  57.   13) How do I find the 'edges' in a bitmap?
  58. ? 14) How do I enlarge/sharpen/fuzz a bitmap?
  59.   15) How do I map a texture on to a shape?
  60.   16) How do I find the area/orientation of a polygon?
  61.   17) How do I find if a point lies within a polygon?
  62. ? 18) How do I find the intersection of two convex polygons?
  63.   19) How do I detect a 'corner' in a collection of points?
  64.   20) How do I generate a circle through three points?
  65.   21) How do I generate a bezier curve that is parallel to another bezier?
  66.   22) How do I split a bezier at a specific value for t?
  67.   23) How do I find a t value at a specific point on a bezier?
  68.   24) How do I fit a bezier curve to a circle?
  69.   25) What is ARCBALL?
  70.   26) Where can I find ARCBALL source?
  71.   27) How do I clip a polygon against a rectangle?
  72.   28) How do I clip a polygon against another polygon?
  73. ? 29) Where can I get source for Weiler/Atherton clipping?
  74. ? 30) How do I generate a spline to approximate (insert curve here)?
  75. ? 31) Where do I get source to display (raster font format)?
  76. ? 32) What is morphing/how is it done?
  77. ? 33) How do I draw an anti-aliased line/polygon/ellipse?
  78.   34) How do I determine the intersection between a ray and a polygon?
  79.   35) How do I determine the intersection between a ray and a sphere?
  80.   36) How do I determine the intersection between a ray and a bezier surface?
  81.   37) How do I ray trace caustics?
  82.   38) How do I quickly draw a filled triangle?
  83.   39) Where can I get source for Voronoi/Delaunay triangulation?
  84.   40) Where do I get source for convex hull?
  85.   41) What is the marching cubes algorithm?
  86. ? 42) What is the status of the patent on the "marching cubes" algorithm?
  87.   43) How do I do a hidden surface test (backface culling) with 3d points?
  88.   44) How do I do a hidden surface test (backface culling) with 2d points?
  89.   45) Where can I find graph layout algorithms?
  90. ? 46) Where can I find algorithms for 2D collision detection?
  91.   47) Where can I find algorithms for 3D collision detection?
  92.   48) 3D Noise functions and turbulence in Solid texturing.
  93.   49) How do I perform basic viewing in 3d?
  94. ? 50) How can you contribute to this FAQ?
  95.   51) Contributors.  Who made this all possible.
  96.  
  97. ----------------------------------------------------------------------
  98.  
  99. Subject: 0) Charter of comp.graphics.algorithms
  100.  
  101.     Comp.graphics.algorithms is an unmoderated newsgroup intended
  102.     as a forum for the discussion of the algorithms used in the
  103.     process of generating computer graphics.  These algorithms may
  104.     be recently proposed in published journals or papers, old or
  105.     previously known algorithms, or hacks used incidental to the
  106.     process of computer graphics.  The scope of these algorithms
  107.     may range from an efficient way to multiply matrices, all the
  108.     way to a global illumination method incorporating ray tracing,
  109.     radiosity, infinite spectrum modeling, and perhaps even
  110.     mirrored balls and lime jello.
  111.  
  112.     It is hoped that this group will serve as a forum for programmers
  113.     and researchers to exchange ideas and ask questions on recent
  114.     papers or current research related to computer graphics.
  115.  
  116.     comp.graphics.algorithms is not:
  117.  
  118.      - for requests for gifs, or other pictures
  119.      - for requests for image translator software (i.e. gif <--> jpg)
  120.  
  121. ----------------------------------------------------------------------
  122.  
  123. Subject: 1) Are the postings to comp.graphics.algorithms archived?
  124.  
  125. |   Yes.  The "official" archive is stored at:
  126. |
  127. |     http://www.cis.ohio-state/hypertext/faq/usenet/graphics/algorithms-faq/faq.html
  128. |     ftp://rtfm.mit.edu/pub/usenet-by-group/news.answers/graphics/algorithms-faq
  129. |
  130. |   Also available at:
  131. |
  132. |     ftp://wuarchive.wustl.edu/graphics/graphics/mail-lists/comp.graphics.algorithms
  133.  
  134.     It is archived in the same manner that all other newsgroups are
  135.     being archived there, namely there is an Index file with all the
  136.     subjects, and all the articles are being kept in a hierarchy based
  137.     on the year and month they are posted.
  138.  
  139. |   FYI, all usenet FAQ's are available with Mosaic via
  140. |
  141. |   http://www.cis.ohio-state/hypertext/faq/usenet/top.html
  142.  
  143.  
  144. ----------------------------------------------------------------------
  145.  
  146. Subject: 2) What are some must have books on graphics algorithms?
  147.  
  148.     The keywords in brackets are used to refer to the books in later
  149.     questions.  They generally refer to the first author except where
  150.     it is necessary to resolve ambiguity or in the case of the Gems.
  151.  
  152.  
  153.     Basic computer graphics, rendering algorithms,
  154.     ----------------------------------------------
  155.  
  156.     [Foley]
  157.     Computer Graphics: Principles and Practice (2nd Ed.),
  158.     J.D. Foley, A. van Dam, S.K. Feiner, J.F. Hughes, Addison-Wesley
  159.     1990, ISBN 0-201-12110-7
  160.  
  161.     [Rogers:Procedural]
  162.     Procedural Elements for Computer Graphics,
  163.     David F. Rogers, McGraw Hill 1985, ISBN 0-07-053534-5
  164.  
  165.     [Rogers:Mathematical]
  166.     Mathematical Elements for Computer Graphics 2nd Ed.,
  167.     David F. Rogers and J. Alan Adams, McGraw Hill 1990, ISBN
  168.     0-07-053530-2
  169.  
  170.     [Watt:3D]
  171.     _3D Computer Graphics, 2nd Edition_,
  172.     Alan Watt, Addison-Wesley 1993, ISBN 0-201-63186-5
  173.  
  174.     [Glassner:RayTracing]
  175.     An Introduction to Ray Tracing,
  176.     Andrew Glassner (ed.), Academic Press 1989, ISBN 0-12-286160-4
  177.  
  178.     [Gems I]
  179.     Graphics Gems,
  180.     Andrew Glassner (ed.), Academic Press 1990, ISBN 0-12-286165-5
  181.  
  182.     [Gems II]
  183.     Graphics Gems II,
  184.     James Arvo (ed.), Academic Press 1991, ISBN 0-12-64480-0
  185.  
  186.     [Gems III]
  187.     Graphics Gems III,
  188.     David Kirk (ed.), Academic Press 1992, ISBN 0-12-409670-0 (with
  189.     IBM disk) or 0-12-409671-9 (with Mac disk)
  190.  
  191.     [Gems IV]
  192.     Graphics Gems IV,
  193.     Paul S. Heckbert (ed.), Academic Press 1994, ISBN 0-12-336155-9
  194.     (with IBM disk) or 0-12-336156-7 (with Mac disk)
  195.  
  196.     [Watt:Animation]
  197.     Advanced Animation and Rendering Techniques,
  198.     Alan Watt, Mark Watt, Addison-Wesley 1992, ISBN 0-201-54412-1
  199.  
  200.     [Bartels]
  201.     An Introduction to Splines for Use in Computer Graphics and
  202.         Geometric Modeling,
  203.     Richard H. Bartels, John C. Beatty, Brian A. Barsky, 1987, ISBN
  204.     0-934613-27-3
  205.  
  206.     [Farin]
  207.     Curves and Surfaces for Computer Aided Geometric Design:
  208.     A Practical Guide, 3rd Edition, Gerald E. Farin, Academic Press
  209.     1993. ISBN 0-12-249052-5
  210.  
  211.     [Prusinkiewicz]
  212.     The Algorithmic Beauty of Plants,
  213.     Przemyslaw W. Prusinkiewicz, Aristid Lindenmayer, Springer-Verlag,
  214.     1990, ISBN 0-387-97297-8, ISBN 3-540-97297-8
  215.  
  216.     [Oliver]
  217.     Tricks of the Graphics Gurus,
  218.     Dick Oliver, et al. (2) 3.5 PC disks included, $39.95 SAMS Publishing
  219.  
  220.     [Hearn]
  221.     Introduction to computer graphics,
  222.     Hearn & Baker
  223.  
  224.  
  225.     For image processing,
  226.     ---------------------
  227.  
  228.     [Barnsley]
  229.     Fractal Image Compression,
  230.     Michael F. Barnsley and Lyman P. Hurd, AK Peters, Ltd, 1993 ISBN
  231.     1-56881-000-8
  232.  
  233.     [Jain]
  234.     Fundamentals of Image Processing,
  235.     Anil K. Jain, Prentice-Hall 1989, ISBN 0-13-336165-9
  236.  
  237.     [Castleman]
  238.     Digital Image Processing,
  239.     Kenneth R. Castleman, Prentice-Hall 1979, ISBN 0-13-212365-7
  240.  
  241.     [Pratt]
  242.     Digital Image Processing, Second Edition,
  243.     William K. Pratt, Wiley-Interscience 1991, ISBN 0-471-85766-1
  244.  
  245.     [Gonzalez]
  246.     Digital Image Processing (2nd Ed.),
  247.     Rafael C. Gonzalez, Paul Wintz, Addison-Wesley 1987, ISBN
  248.     0-201-11026-1
  249.  
  250.     [Russ]
  251.     The Image Processing Handbook,
  252.     John C. Russ, CRC Press 1992, ISBN 0-8493-4233-3
  253.  
  254.     [Wolberg]
  255.     Digital Image Warping,
  256.     George Wolberg, IEEE Computer Society Press Monograph 1990, ISBN
  257.     0-8186-8944-7
  258.  
  259.  
  260.     Computational geometry,
  261.     ----------------------
  262.  
  263.     [Bowyer]
  264.     A Programmer's Geometry,
  265.     Adrian Bowyer, John Woodwark, Butterworths 1983, ISBN
  266.     0-408-01242-0 Pbk
  267.  
  268.     [O' Rourke]
  269.     Computational Geometry in C,
  270.     Joseph O'Rourke, Cambridge University Press 1994, ISBN
  271.     0-521-44592-2 Pbk, ISBN 0-521-44034-3 Hdbk
  272.  
  273.     [Mortenson]
  274.     Geometric Modeling,
  275.     Michael E. Mortenson, Wiley 1985, ISBN 0-471-88279-8
  276.  
  277.     [Preparata]
  278.     Computational Geometry: An Introduction,
  279.     Franco P. Preparata, Michael Ian Shamos, Springer-Verlag 1985,
  280.     ISBN 0-387-96131-3
  281.  
  282.  
  283. ----------------------------------------------------------------------
  284.  
  285. Subject: 3) Are there any online references?
  286.  
  287.     The computational geometry community maintains its own
  288.     bibliography of publications in or closely related to that
  289.     subject.  Every four months, additions and corrections are
  290.     solicited from users, after which the database is updated and
  291.     released anew.  As of September 1993, it contained 5356 bib-tex
  292.     entries.  It can be retrieved from
  293.  
  294.     ftp://cs.usask.ca/pub/geometry/geombib.tar.Z - bibliography proper
  295.  
  296.     ftp://cs.usask.ca/pub/geometry/geom.ps.Z     - PostScript format
  297.  
  298.     ftp://cs.usask.ca/pub/geometry/o-cgc19.ps.Z     - overview published
  299.         in '93 in SIGACT News and the Internat. J. Comput.  Geom. Appl.
  300.  
  301.     ftp://cs.usask.ca/pub/geometry/ftp-hints     - detailed retrieval info
  302.  
  303.     Announcing the ACM SIGGRAPH Online Bibliography Project, by
  304.     Stephen Spencer (biblio@siggraph.org)
  305.  
  306.     The database is available for anonymous FTP from the
  307.     ftp://siggraph.org/publications/bibliography directory.  Please
  308.     download and examine the file READ_ME in that directory for more
  309.     specific information concerning the database.
  310.  
  311.     'netlib' is a useful source for algorithms, member inquiries for
  312.     SIAM, and bibliographic searches.  For information, send mail to
  313.     netlib@ornl.gov, with "send index" in the body of the mail
  314.     message.
  315.  
  316.     You can also find free sources for numerical computation in C via
  317.     ftp://usc.edu/pub/C-numanal.  In particular, grab
  318.     numcomp-free-c.gz in that directory. 
  319.  
  320.     Check out Nick Fotis's computer graphics resources FAQ -- it's
  321.     packed with pointers to all sorts of great computer graphics
  322.     stuff.  This FAQ is posted biweekly to comp.graphics.
  323.  
  324.  
  325. ----------------------------------------------------------------------
  326.  
  327. Subject: 4) Where is all the source?
  328.  
  329.     Graphics Gems source code.
  330.     ftp://princeton.edu:pub/Graphics/GraphicsGems
  331.  
  332.     General 'stuff'
  333.     ftp://wuarchive.wustl.edu/graphics/graphics
  334.  
  335.  
  336. ----------------------------------------------------------------------
  337.  
  338. Subject: 5) How do I rotate a 2D point?
  339.  
  340.     In 2-D, the 2x2 matrix is very simple.  If you want to rotate a
  341.     column vector v by t degrees using matrix M, use
  342.  
  343.         M = {{cos t, -sin t}, {sin t, cos t}} in M*v.
  344.  
  345.     If you have a row vector, use the transpose of M (turn rows into
  346.     columns and vice versa).  If you want to combine rotations, in 2-D
  347.     you can just add their angles, but in higher dimensions you must
  348.     multiply their matrices.
  349.  
  350.  
  351. ----------------------------------------------------------------------
  352.  
  353. Subject: 6) How do I rotate a 3D point?
  354.  
  355.     Assuming you want to rotate vectors around the origin of your
  356.     coordinate system. (If you want to rotate around some other point,
  357.     subtract its coordinates from the point you are rotating, do the
  358.     rotation, and then add back what you subtracted.) In 3-D, you need
  359.     not only an angle, but also an axis. (In higher dimensions it gets
  360.     much worse, very quickly.)  Actually, you need 3 independent
  361.     numbers, and these come in a variety of flavors.  The flavor I
  362.     recommend is unit quaternions: 4 numbers that square and add up to
  363.     +1.  You can write these as [(x,y,z),w], with 4 real numbers, or
  364.     [v,w], with v, a 3-D vector pointing along the axis. The concept
  365.     of an axis is unique to 3-D. It is a line through the origin
  366.     containing all the points which do not move during the rotation.
  367.     So we know if we are turning forwards or back, we use a vector
  368.     pointing out along the line. Suppose you want to use unit vector u
  369.     as your axis, and rotate by 2t degrees.  (Yes, that's twice t.)
  370.     Make a quaternion [u sin t, cos t]. You can use the quaternion --
  371.     call it q -- directly on a vector v with quaternion
  372.     multiplication, q v q^-1, or just convert the quaternion to a 3x3
  373.     matrix M. If the components of q are {(x,y,z),w], then you want
  374.     the matrix
  375.  
  376.         M = {{1-2(yy+zz),  2(xy-wz),  2(xz+wy)},
  377.              {  2(xy+wz),1-2(xx+zz),  2(yz-wx)},
  378.              {  2(xz-wy),  2(yz+wx),1-2(xx+yy)}}.
  379.  
  380.     Rotations, translations, and much more are explained in all basic
  381.     computer graphics texts.  Quaternions are covered briefly in
  382.     [Foley], and more extensively in several Graphics Gems, and the
  383.     SIGGRAPH 85 proceedings.
  384.  
  385.  
  386. ----------------------------------------------------------------------
  387.  
  388. Subject: 7) How do I find the distance from a point to a line?
  389.  
  390.  
  391.     Let the point be C (XC,YC) and the line be AB (XA,YA) to (XB,YB).
  392.     The length of the line segment AB is L:
  393.  
  394.         L=((XB-XA)**2+(YB-YA)**2)**0.5
  395.  
  396.     and
  397.             (YA-YC)(YA-YB)-(XA-XC)(XB-XA)
  398.         r = -----------------------------
  399.                         L**2
  400.  
  401.             (YA-YC)(XB-XA)-(XA-XC)(YB-YA)
  402.         s = -----------------------------
  403.                         L**2
  404.  
  405.     Let I be the point of perpendicular projection of C onto AB, the
  406.  
  407.         XI=XA+r(XB-XA)
  408.         YI=YA+r(YB-YA)
  409.  
  410.     Distance from A to I = r*L
  411.     Distance from C to I = s*L
  412.  
  413.     If r<0      I is on backward extension of AB
  414.     If r>1      I is on ahead extension of AB
  415.     If 0<=r<=1  I is on AB
  416.  
  417.     If s<0      C is left of AB (you can just check the numerator)
  418.     If s>0      C is right of AB
  419.     If s=0      C is on AB
  420.  
  421.  
  422. ----------------------------------------------------------------------
  423.  
  424. Subject: 8) How do I find intersections of 2 2D line segments?
  425.  
  426.     This problem can be extremely easy or extremely difficult depends
  427.     on your applications.  If all you want is the intersection point,
  428.     the following should work:
  429.  
  430.     Let A,B,C,D be 2-space position vectors.  Then the directed line
  431.     segments AB & CD are given by:
  432.  
  433.         AB=A+r(B-A), r in [0,1]
  434.         CD=C+s(D-C), s in [0,1]
  435.  
  436.     If AB & CD intersect, then
  437.  
  438.         A+r(B-A)=C+s(D-C), or
  439.  
  440.         XA+r(XB-XA)=XC+s(XD-XC)
  441.         YA+r(YB-YA)=YC+s(YD-YC)  for some r,s in [0,1]
  442.  
  443.     Solving the above for r and s yields
  444.  
  445.             (YA-YC)(XD-XC)-(XA-XC)(YD-YC)
  446.         r = -----------------------------  (eqn 1)
  447.             (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
  448.  
  449.             (YA-YC)(XB-XA)-(XA-XC)(YB-YA)
  450.         s = -----------------------------  (eqn 2)
  451.             (XB-XA)(YD-YC)-(YB-YA)(XD-XC)
  452.  
  453.     Let I be the position vector of the intersection point, then
  454.  
  455.         I=A+r(B-A) or
  456.  
  457.         XI=XA+r(XB-XA)
  458.         YI=YA+r(YB-YA)
  459.  
  460.     By examining the values of r & s, you can also determine some
  461.     other limiting conditions:
  462.  
  463.         If 0<=r<=1 & 0<=s<=1, intersection exists
  464.             r<0 or r>1 or s<0 or s>1 line segments do not intersect
  465.  
  466.         If the denominator in eqn 1 is zero, AB & CD are parallel
  467.         If the numerator in eqn 1 is also zero, AB & CD are coincident
  468.  
  469.     If the intersection point of the 2 lines are needed (lines in this
  470.     context mean infinite lines) regardless whether the two line
  471.     segments intersect, then
  472.  
  473.         If r>1, I is located on extension of AB
  474.         If r<0, I is located on extension of BA
  475.         If s>1, I is located on extension of CD
  476.         If s<0, I is located on extension of DC
  477.  
  478.     Also note that the denominators of eqn 1 & 2 are identical.
  479.  
  480.     References:
  481.  
  482.     [O'Rourke] pp. 249-51
  483.     [Gems III] pp. 199-202 "Faster Line Segment Intersection,"
  484.  
  485.  
  486. ----------------------------------------------------------------------
  487.  
  488. Subject: 9) How do I find the intersection of a line and a plane?
  489.  
  490.     If the plane is defined as:
  491.  
  492.         a*x + b*y + c*z + d = 0
  493.  
  494.     and the line is defined as:
  495.  
  496.         x = x1 + (x2 - x1)*t = x1 + i*t
  497.         y = y1 + (y2 - y1)*t = y1 + j*t
  498.         z = z1 + (z2 - z1)*t = z1 + k*t
  499.  
  500.     Then just substitute these into the plane equation. You end up
  501.     with:
  502.  
  503.         t = - (a*x1 + b*y1 + c*z1 + d)/(a*i + b*j + c*k)
  504.  
  505.     If the denominator is zero, then the vector (a,b,c) and the vector
  506.     (i,j,k) are perpendicular.  Note that (a,b,c) is the normal to the
  507.     plane and (i,j,k) is the direction of the line.  It follows that
  508.     the line is either parallel to the plane or contained in the
  509.     plane. In either case there is no unique intersection point.
  510.  
  511.  
  512. ----------------------------------------------------------------------
  513.  
  514. Subject: 10) How do I rotate a bitmap?
  515.  
  516.     The easiest way, according to the comp.graphics faq, is to take
  517.     the rotation transformation and invert it. Then you just iterate
  518.     over the destination image, apply this inverse transformation and
  519.     find which source pixel to copy there.
  520.  
  521.     A much nicer way comes from the observation that the rotation
  522.     matrix:
  523.  
  524.         R(T) = { { cos(T), -sin(T) }, { sin(T), cos(T) } }
  525.  
  526.     is formed my multiplying three matrices, namely:
  527.  
  528.         R(T) = M1(T) * M2(T) * M3(T)
  529.  
  530.     where
  531.  
  532.         M1(T) = { { 1, -tan(T/2) },
  533.                   { 0, 1         } }
  534.         M2(T) = { { 1,      0    },
  535.                   { sin(T), 1    } }
  536.         M3(T) = { { 1, -tan(T/2) },
  537.                   { 0,         1 } }
  538.  
  539.     Each transformation can be performed in a separate pass, and
  540.     because these transformations are either row-preserving or
  541.     column-preserving, anti-aliasing is quite easy.
  542.  
  543.     Reference:
  544.  
  545.     Paeth, A. W., "A Fast Algorithm for General Raster Rotation",
  546.     Proceedings Graphics Interface '89, Canadian Information
  547.     Processing Society, 1986, 77-81
  548.     [Note - e-mail copies of this paper are no longer available]
  549.  
  550.     [Gems I]
  551.  
  552.  
  553. ----------------------------------------------------------------------
  554.  
  555. Subject: 11) How do I display a 24 bit image in 8 bits?
  556.  
  557.     [Gems I] pp. 287-293, "A Simple Method for Color Quantization:
  558.     Octree Quantization"
  559.  
  560.     B. Kurz.  Optimal Color Quantization for Color Displays.
  561.     Proceedings of the IEEE Conference on Computer Vision and Pattern
  562.     Recognition, 1983, pp. 217-224.
  563.  
  564.     [Gems II] pp. 116-125, "Efficient Inverse Color Map Computation"
  565.  
  566.         This describes an efficient technique to
  567.         map actual colors to a reduced color map,
  568.         selected by some other technique described
  569.         in the other papers.
  570.  
  571.     [Gems II] pp. 126-133, "Efficient Statistical Computations for
  572.     Optimal Color Quantization"
  573.  
  574.     Xiaolin Wu.  Color Quantization by Dynamic Programming and
  575.     Principal Analysis.  ACM Transactions on Graphics, Vol. 11, No. 4,
  576.     October 1992, pp 348-372.
  577.  
  578.  
  579. ----------------------------------------------------------------------
  580.  
  581. Subject: 12) How do I fill the area of an arbitrary shape?
  582.  
  583.  
  584.     "A Fast Algorithm for the Restoration of Images Based on Chain
  585.         Codes Description and Its Applications", L.W. Chang & K.L. Leu,
  586.         Computer Vision, Graphics, and Image Processing, vol.50,
  587.         pp296-307 (1990)
  588.  
  589.     "An Introductory Course in Computer Graphics" by Richard Kingslake,
  590.         (2nd edition) published by Chartwell-Bratt ISBN 0-86238-284-X
  591.  
  592.     [Gems I]
  593.     [Foley]
  594.     [Hearn]
  595.  
  596.  
  597. ----------------------------------------------------------------------
  598.  
  599. Subject: 13) How do I find the 'edges' in a bitmap?
  600.  
  601.     A simple method is to put the bitmap through the filter:
  602.  
  603.         -1    -1    -1
  604.         -1     8    -1
  605.         -1    -1    -1
  606.  
  607.     This will highlight changes in contrast.  Then any part of the
  608.     picture where the absolute filtered value is higher than some
  609.     threshold is an "edge".
  610.  
  611.  
  612. ----------------------------------------------------------------------
  613.  
  614. Subject: 14) How do I enlarge/sharpen/fuzz a bitmap?
  615.  
  616.  
  617. ----------------------------------------------------------------------
  618.  
  619. Subject: 15) How do I map a texture on to a shape?
  620.  
  621.     Paul S. Heckbert, "Survey of Texture Mapping", IEEE Computer
  622.     Graphics and Applications V6, #11, Nov. 1986, pp 56-67 revised
  623.     from Graphics Interface '86 version
  624.  
  625.     Eric A. Bier and Kenneth R. Sloan, Jr., "Two-Part Texture
  626.     Mappings", IEEE Computer Graphics and Applications V6 #9, Sept.
  627.     1986, pp 40-53 (projection parameterizations)
  628.  
  629.  
  630. ----------------------------------------------------------------------
  631.  
  632. Subject: 16) How do I find the area/orientation of a polygon?
  633.  
  634.     Compute the signed area.  The orientation is counter-clockwise if
  635.     this area is positive.  There's a Gem on computing signed areas.
  636.  
  637.     A slightly faster method is based on the observation that it isn't
  638.     necessary to compute the area.  One can find the lowest, rightmost
  639.     point of the polygon, and then take the cross product of the edges
  640.     fore and aft of it.  Both methods are O(n) for n vertices, but it
  641.     does seem a waste to add up the total area when a single cross
  642.     product (of just the right edges) suffices.
  643.  
  644.     The reason that the lowest, rightmost point works is that the
  645.     internal angle at this vertex is necessarily convex, strictly less
  646.     than pi (even if there are several equally-lowest points).
  647.  
  648.     The key formula is this:
  649.  
  650.         If the coordinates of vertex v_i are x_i and y_i,
  651.         twice the area of a polygon is given by
  652.  
  653.         2 A( P ) = sum_{i=0}^{n-1} (x_i y_{i+1} - y_i x_{i+1}).
  654.  
  655.     Reference:
  656.  
  657.     [O' Rourke] pp. 18-27.
  658.  
  659.  
  660. ----------------------------------------------------------------------
  661.  
  662. Subject: 17) How do I find if a point lies within a polygon?
  663.  
  664.     A quick comment - the code in the Sedgewick book Algorithms is
  665.     wrong.
  666.  
  667.     The short answer, for the FAQ, could be:
  668.  
  669.     int pnpoly(int npol, float *xp, float *yp, float x, float y)
  670.     {
  671.       int i, j, c = 0;
  672.       for (i = 0, j = npol-1; i < npol; j = i++) {
  673.         if ((((yp[i]<=y) && (y<yp[j])) ||
  674.              ((yp[j]<=y) && (y<yp[i]))) &&
  675.             (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i]))
  676.           c = !c;
  677.       }
  678.       return c;
  679.     }
  680.  
  681.     This code is from Wm. Randolph Franklin, wrf@ecse.rpi.edu, a
  682.     professor at RPI, with some minor modifications for speed by me.
  683.     A good reference for this problem will be:
  684.  
  685.     References:
  686.  
  687.     [O'Rourke] pp. 233-238
  688.     [Gems IV]  pp. 23-45
  689.     [Glassner:RayTracing]
  690.  
  691.  
  692. ----------------------------------------------------------------------
  693.  
  694. Subject: 18) How do I find the intersection of two convex polygons?
  695.  
  696.     [O'Rourke] pp. 242-252
  697.  
  698.  
  699. ----------------------------------------------------------------------
  700.  
  701. Subject: 19) How do I detect a 'corner' in a collection of points?
  702.  
  703.     For the general solution to the problem get Ata Etemadi's software
  704.     package and associated  papers from one of the addresses below.
  705.     It's very fast and detects polygons too.
  706.  
  707.     ftp://peipa.essex.ac.uk/ipa/src/process
  708.     ftp://ftp.teleos.com/VISION-LIST-ARCHIVE/SHAREWARE
  709.  
  710.  
  711. ----------------------------------------------------------------------
  712.  
  713. Subject: 20) How do I generate a circle through three points?
  714.  
  715.     Let the three given points be a, b, c.  Use _0 and _1 to represent
  716.     x and y coordinates. The coordinates of the center p=(p_0,p_1) of
  717.     the circle determined by a, b, and c are:
  718.  
  719.             p_0 =
  720.                     ( b_1 a_0^2
  721.                     - c_1 a_0^2
  722.                     - b_1^2 a_1
  723.                     + c_1^2 a_1
  724.                     + b_0^2 c_1
  725.                     + a_1^2 b_1
  726.                     + c_0^2 a_1
  727.                     - c_1^2 b_1
  728.                     - c_0^2 b_1
  729.                     - b_0^2 a_1
  730.                     + b_1^2 c_1
  731.                     - a_1^2 c_1 )
  732.                 / D
  733.  
  734.             p_1 =
  735.                     ( a_0^2 c_0
  736.                     + a_1^2 c_0
  737.                     + b_0^2 a_0
  738.                     - b_0^2 c_0
  739.                     + b_1^2 a_0
  740.                     - b_1^2 c_0
  741.                     - a_0^2 b_0
  742.                     - a_1^2 b_0
  743.                     - c_0^2 a_0
  744.                     + c_0^2 b_0
  745.                     - c_1^2 a_0
  746.                     + c_1^2 b_0)
  747.                 / D
  748.  
  749.     where
  750.  
  751.             D = 2( a_1 c_0 + b_1 a_0 - b_1 c_0 -a_1 b_0 -c_1 a_0 + c_1 b_0 )
  752.  
  753.     The radius of the circle is then:
  754.  
  755.             r^2 = (a_0 - p_0)^2 + (a_1 - p_1)^2
  756.  
  757.     Reference:
  758.  
  759.     [O' Rourke] p. 201
  760.  
  761.  
  762. ----------------------------------------------------------------------
  763.  
  764. Subject: 21) How do I generate a bezier curve that is parallel to another bezier?
  765.  
  766.     You can't.  The only case where this is possible is when the
  767.     bezier can be represented by a straight line.  And then the
  768.     parallel 'bezier' can also be represented by a straight line.
  769.  
  770.  
  771. ----------------------------------------------------------------------
  772.  
  773. Subject: 22) How do I split a bezier at a specific value for t?
  774.  
  775.     A Bezier curve is a parametric polynomial function from the
  776.     interval [0..1] to a space, usually 2-D or 3-D.  Common Bezier
  777.     curves use cubic polynomials, so have the form
  778.  
  779.         f(t) = a3 t^3 + a2 t^2 + a1 t + a0,
  780.  
  781.     where the coefficients are points in 3-D. Blossoming converts this
  782.     polynomial to a more helpful form.  Let s = 1-t, and think of
  783.     tri-linear interpolation:
  784.  
  785.         F([s0,t0],[s1,t1],[s2,t2]) =
  786.             s0(s1(s2 c30 + t2 c21) + t1(s2 c21 + t2 c12)) +
  787.             t0(s1(s2 c21 + t2 c12) + t1(s2 c12 + t2 c03))
  788.             =
  789.             c30(s0 s1 s2) +
  790.             c21(s0 s1 t2 + s0 t1 s2 + t0 s1 s2) +
  791.             c12(s0 t1 t2 + t0 s1 t2 + t0 t1 s2) +
  792.             c03(t0 t1 t2).
  793.  
  794.     The data points c30, c21, c12, and c03 have been used in such a
  795.     way as to make the resulting function give the same value if any
  796.     two arguments, say [s0,t0] and [s2,t2], are swapped. When [1-t,t]
  797.     is used for all three arguments, the result is the cubic Bezier
  798.     curve with those data points controlling it:
  799.  
  800.           f(t) = F([1-t,t],[1-t,t],[1-t,t])
  801.                =  (1-t)^3 c30 +
  802.                  3(1-t)^2 t c21 +
  803.                  3(1-t) t^2 c12 +
  804.                  t^3 c03.
  805.  
  806.     Notice that
  807.            F([1,0],[1,0],[1,0]) = c30,
  808.            F([1,0],[1,0],[0,1]) = c21,
  809.            F([1,0],[0,1],[0,1]) = c12, _
  810.            F([0,1],[0,1],[0,1]) = c03.
  811.  
  812.     In other words, cij is obtained by giving F argument t's i of
  813.     which are 0 and j of which are 1. Since F is a linear polynomial
  814.     in each argument, we can find f(t) using a series of simple steps.
  815.     Begin with
  816.  
  817.         f000 = c30, f001 = c21, f011 = c12, f111 = c03.
  818.  
  819.     Then compute in succession:
  820.  
  821.         f00t = s f000 + t f001, f01t = s f001 + t f011,
  822.         f11t = s f011 + t f111,
  823.         f0tt = s f00t + t f01t, f1tt = s f01t + t f11t,
  824.         fttt = s f0tt + t f1tt.
  825.  
  826.     This is the de Casteljau algorithm for computing f(t) = fttt.
  827.  
  828.     It also has split the curve for the intervals [0..t] and [t..1].
  829.     The control points for the first interval are f000, f00t, f0tt,
  830.     fttt, while those for the second interval are fttt, f1tt, f11t,
  831.     f111.
  832.  
  833.     If you evaluate 3 F([1-t,t],[1-t,t],[-1,1]) you will get the
  834.     derivate of f at t. Similarly, 2*3 F([1-t,t],[-1,1],[-1,1]) gives
  835.     the second derivative of f at t, and finally using 1*2*3
  836.     F([-1,1],[-1,1],[-1,1]) gives the third derivative.
  837.  
  838.     This procedure is easily generalized to different degrees,
  839.     triangular patches, and B-spline curves.
  840.  
  841.  
  842. ----------------------------------------------------------------------
  843.  
  844. Subject: 23) How do I find a t value at a specific point on a bezier?
  845.  
  846.     In general, you'll need to find t closest to your search point.
  847.     There are a number of ways you can do this. Look at [Gems I, 607],
  848.     there's a chapter on finding the nearest point on the bezier
  849.     curve.  In my experience, digitizing the bezier curve is an
  850.     acceptable method. You can also try recursively subdividing the
  851.     curve, see if you point is in the convex hull of the control
  852.     points, and checking is the control points are close enough to a
  853.     linear line segment and find the nearest point on the line
  854.     segment, using linear interpolation and keeping track of the
  855.     subdivision level, you'll be able to find t.
  856.  
  857.  
  858. ----------------------------------------------------------------------
  859.  
  860. Subject: 24) How do I fit a bezier curve to a circle?
  861.  
  862.     Interestingly enough, bezier curves can approximate a circle but
  863.     not perfectly fit a circle.
  864.  
  865.     Michael Goldapp, "Approximation of circular arcs by cubic
  866.     polynomials" Computer Aided Geometric Design (#8 1991 pp.227-238)
  867.  
  868.     Tor Dokken and Morten Daehlen, "Good Approximations of circles by
  869.     curvature-continuous Bezier curves" Computer Aided Geometric
  870.     Design (#7 1990 pp. 33-41).
  871.  
  872.  
  873. ----------------------------------------------------------------------
  874.  
  875. Subject: 25) What is ARCBALL?
  876.  
  877.     Arcball is a general purpose 3-D rotation controller described by
  878.     Ken Shoemake in the Graphics Interface '92 Proceedings.  It
  879.     features good behavior, easy implementation, cheap execution, and
  880.     optional axis constraints. A Macintosh demo and electronic version
  881.     of the original paper (Microsoft Word format) may be obtained from
  882.     ftp::/ftp.cis.upenn.edu/pub/graphics.
  883.  
  884.  
  885. ----------------------------------------------------------------------
  886.  
  887. Subject: 26) Where can I find ARCBALL source?
  888.  
  889.     Complete source code appears in Graphics Gems IV pp. 175-192. A
  890.     fairly complete sketch of the code appeared in the original
  891.     article, in Graphics Interface 92 Proceedings, available from
  892.     Morgan Kaufmann.
  893.  
  894.  
  895. ----------------------------------------------------------------------
  896.  
  897. Subject: 27) How do I clip a polygon against a rectangle?
  898.  
  899.     This is the Sutherland-Hodgman algorithm, an old favorite that
  900.     should be covered in any textbook. Any of the references listed in
  901.     the FAQ should have it.  According to Vatti (q.v.)  "This
  902.     [algorithm] produces degenerate edges in certain concave / self
  903.     intersecting polygons that need to be removed as a special
  904.     extension to the main algorithm" (though this is not a problem if
  905.     all you are doing with the results is scan converting them.)
  906.  
  907.  
  908. ----------------------------------------------------------------------
  909.  
  910. Subject: 28) How do I clip a polygon against another polygon?
  911.  
  912.     People interested in some alpha state code, written in C++ with
  913.     templates (for example: g++) can contact Klamer Schutte,
  914.     klamer@mi.el.utwente.nl.  Or with Mosaic, at
  915.     http://ph.tn.tudelft.nl:2000/People/klamer/Klamer.html#clippoly.
  916.     Also from ftp://galaxy.ph.tn.tudelft.nl/pub/klamer/clippoly.tar.gz
  917.  
  918.  
  919. ----------------------------------------------------------------------
  920.  
  921. Subject: 29) Where can I get source for Weiler/Atherton clipping?
  922.  
  923.  
  924. ----------------------------------------------------------------------
  925.  
  926. Subject: 30) How do I generate a spline to approximate (insert curve here)?
  927.  
  928.  
  929. ----------------------------------------------------------------------
  930.  
  931. Subject: 31) Where do I get source to display (raster font format)?
  932.  
  933.  
  934. ----------------------------------------------------------------------
  935.  
  936. Subject: 32) What is morphing/how is it done?
  937.  
  938.  
  939. ----------------------------------------------------------------------
  940.  
  941. Subject: 33)How do I draw an anti-aliased line/polygon/ellipse?
  942.  
  943.  
  944. ----------------------------------------------------------------------
  945.  
  946. Subject: 34) How do I determine the intersection between a ray and a polygon
  947.  
  948.     First find the intersection between the ray and the plane in which
  949.     the polygon is situated. Then see if the point of intersection is
  950.     in the polygon.
  951.  
  952.     Reference:
  953.  
  954.     [Glassner:RayTracing]
  955.  
  956.  
  957. ----------------------------------------------------------------------
  958.  
  959. Subject: 35) How do I determine the intersection between a ray and a sphere
  960.  
  961.     Given a ray defined as:
  962.  
  963.         x = x1 + (x2 - x1)*t = x1 + i*t
  964.         y = y1 + (y2 - y1)*t = y1 + j*t
  965.         z = z1 + (z2 - z1)*t = z1 + k*t
  966.  
  967.     and a sphere defined as:
  968.  
  969.         (x - l)**2 + (y - m)**2 + (z - n)**2 = r**2
  970.  
  971.     Substituting in gives the quadratic equation:
  972.  
  973.         a*t**2 + b*t + c = 0
  974.  
  975.     where:
  976.  
  977.         a = i**2 + j**2 + k**2
  978.         b = 2*i*(x1 - l) + 2*j*(y1 - m) + 2*k*(x1 - n)
  979.         c = l**2 + m**2 + n**2 + x1**2 + y1**2 + z1**2
  980.             - 2*(l*x1 + m*y1 + n*z1) - r**2
  981.  
  982.     If the determinant of this equation is less than 0, the line does
  983.     not intersect the sphere. If it is zero, the line is tangential to
  984.     the sphere and if it is greater than zero it intersects at two
  985.     points. Solving the equation and substituting the values of t into
  986.     the ray equation will give you the points.
  987.  
  988.     Reference:
  989.  
  990.     [Glassner:RayTracing]
  991.  
  992.  
  993. ----------------------------------------------------------------------
  994.  
  995. Subject: 36) How do I determine the intersection between a ray and a bezier
  996.              surface?
  997.  
  998.     Joy I.K. and Bhetanabhotla M.N., "Ray tracing parametric surfaces
  999.     utilizing numeric techniques and ray coherence", Computer
  1000.     Graphics, 16, 1986, 279-286
  1001.  
  1002.     Joy and Bhetanabhotla is only one approach of three major method
  1003.     classes: tessellation, direct computation, and a hybrid of the
  1004.     two.  Tessellation is relatively easy (you intersect the polygons
  1005.     making up the tessellation) and has no numerical problems, but can
  1006.     be inaccurate; direct is cheap on memory, but very expensive
  1007.     computationally, and can (and usually does) suffer from precision
  1008.     problems within the root solver; hybrids try to blend the two.
  1009.  
  1010.     Reference:
  1011.  
  1012.     [Glassner:RayTracing]
  1013.  
  1014.  
  1015. ----------------------------------------------------------------------
  1016.  
  1017. Subject: 37) How do I ray trace caustics?
  1018.  
  1019.     There is a discussion in [Watt:Animation], but I don't know how
  1020.     good it is.
  1021.  
  1022.     It's hard to get right.
  1023.  
  1024.     One right (but incredibly expensive) answer is:
  1025.  
  1026.     @InProceedings{mitchell-1992-illumination,
  1027.       author         = "Don P. Mitchell and Pat Hanrahan",
  1028.       title          = "Illumination From Curved Reflectors",
  1029.       year           = "1992",
  1030.       month          = "July",
  1031.       volume         = "26",
  1032.       booktitle      = "Computer Graphics (SIGGRAPH '92 Proceedings)",
  1033.       pages          = "283--291",
  1034.       keywords       = "caustics, interval arithmetic, ray tracing",
  1035.       editor         = "Edwin E. Catmull",
  1036.     }
  1037.  
  1038.     A cheat:
  1039.  
  1040.     @Article{inakage-1986-caustics,
  1041.       author         = "Masa Inakage",
  1042.       title          = "Caustics and Specular Reflection Models for
  1043.                         Spherical Objects and Lenses ",
  1044.       pages          = "379--383",
  1045.       journal        = "The Visual Computer",
  1046.       volume         = "2",
  1047.       number         = "6",
  1048.       year           = "1986",
  1049.       keywords       = "ray tracing effects",
  1050.     }
  1051.  
  1052.     very specialized:
  1053.  
  1054.     @Article{yuan-1988-gemstone,
  1055.       author         = "Ying Yuan and Tosiyasu L. Kunii and Naota
  1056.                         Inamato and Lining Sun ",
  1057.       title          = "Gemstone Fire: Adaptive Dispersive Ray Tracing
  1058.                         of Polyhedrons ",
  1059.       year           = "1988",
  1060.       month          = "November",
  1061.       journal        = "The Visual Computer",
  1062.       volume         = "4",
  1063.       number         = "5",
  1064.       pages          = "259--70",
  1065.       keywords       = "caustics",
  1066.     }
  1067.  
  1068.  
  1069. ----------------------------------------------------------------------
  1070.  
  1071. Subject: 38) How do I quickly draw a filled triangle?
  1072.  
  1073.     The easiest way is to render each line separately into an edge
  1074.     buffer. This buffer is a structure which looks like this (in C):
  1075.  
  1076.         struct { int xmin, xmax; } edgebuffer[YDIM];
  1077.  
  1078.     There is one entry for each scan line on the screen, and each
  1079.     entry is to be interpreted as a horizontal line to be drawn from
  1080.     xmin to xmax.
  1081.  
  1082.     Since most people who ask this question are trying to write fast
  1083.     games on the PC, I'll tell you where to find code.  Look at:
  1084.  
  1085.         ftp::/ftp.uwp.edu/pub/msdos/demos/programming/source
  1086.  
  1087.  
  1088. ----------------------------------------------------------------------
  1089.  
  1090. Subject: 39) Where can I get source for Voronoi/Delaunay triangulation?
  1091.  
  1092.     Source code in C for general dimension convex hull and Delaunay
  1093.     triangulation (qhull) is now available from:
  1094.  
  1095.         ftp://geom.umn.edu/pub/software/qhull.tar.Z
  1096.         ftp://geom.umn.edu/pub/software/qhull.sit.hqx for Macintosh
  1097.  
  1098.     You can view the results in 3-d and 4-d with geomview from:
  1099.  
  1100.     ftp::/geom.umn.edu:/pub/software/geomview/geomview-sgi.tar.Z  - Iris
  1101.     ftp::/geom.umn.edu:/pub/software/geomview/geomview-next.tar.Z - Next
  1102.  
  1103.     Convex hull is an easy way to build convex polytopes (just list
  1104.     the vertices).  The algorithm also produces approximate convex
  1105.     hulls.  For example, we have produced the approximate convex hull
  1106.     of 12,000 points in R^6, randomly distributed in the unit cube.
  1107.  
  1108.     The distribution includes .ps files for:
  1109.  
  1110.         Barber, C.B., Dobkin, D.P., and Huhdanpaa, H., "The Quickhull
  1111.         Algorithm for Convex Hull," Technical Report GCG53, The
  1112.         Geometry Center, Univ. of Minnesota, July 1993.
  1113.  
  1114.     References:
  1115.  
  1116.     [O' Rourke] pp. 168-204
  1117.     Three-dimensional convex hull C code in Chapter 4 (p.130-60).
  1118.  
  1119.  
  1120. ----------------------------------------------------------------------
  1121.  
  1122. Subject: 40) Where do I get source for convex hull?
  1123.  
  1124.     See the previous question on Delaunay triangulation.  The two are
  1125.     the same because the Delaunay triangulation of a set of points is
  1126.     the convex hull of the points lifted to a paraboloid.
  1127.  
  1128.     References:
  1129.     [O' Rourke] pp. 70-112
  1130.     C code for Graham's algorithm on p.80-96.
  1131.     Three-dimensional convex hull discussed in Chapter 4 (p.113-67).
  1132.     C code for the incremental algorithm on p.130-60.
  1133.  
  1134.  
  1135. ----------------------------------------------------------------------
  1136.  
  1137. Subject: 41) What is the marching cubes algorithm?
  1138.  
  1139.     The marching cubes algorithm is used in volume rendering to
  1140.     construct an isosurface from a 3D field of values.
  1141.  
  1142.     The 2D analog would be to take an image, and for each pixel, set
  1143.     it to black if the value is below some threshold, and set it to
  1144.     white if it's above the threshold.  Then smooth the jagged black
  1145.     outlines by skinning them with lines.
  1146.  
  1147.     The marching cubes algorithm tests the corner of each cube (or
  1148.     voxel) in the scalar field as being either above or below a given
  1149.     threshold.  This yields a collection of boxes with classified
  1150.     corners.  Since there are eight corners with one of two states,
  1151.     there are 256 different possible combinations for each cube.
  1152.     Then, for each cube, you replace the cube with a surface that
  1153.     meets the classification of the cube.  For example, the following
  1154.     are some 2D examples showing the cubes and their associated
  1155.     surface.
  1156.  
  1157.         - ----- +       - ----- -       - ----- +       - ----- +
  1158.         |:::'   |       |:::::::|       |::::   |       |   ':::|
  1159.         |:'     |       |:::::::|       |::::   |       |.    ':|
  1160.         |       |       |       |       |::::   |       |::.    |
  1161.         + ----- +       + ----- +       - ----- +       + ----- -
  1162.  
  1163.     The result of the marching cubes algorithm is a smooth surface
  1164.     that approximates the isosurface that is constant along a given
  1165.     threshold. This is useful for displaying a volume of oil in a
  1166.     geological volume, for example.
  1167.  
  1168.  
  1169. ----------------------------------------------------------------------
  1170.  
  1171. Subject: 42) What is the status of the patent on the "marching cubes" algorithm?
  1172.  
  1173.  
  1174. ----------------------------------------------------------------------
  1175.  
  1176. Subject: 43) How do I do a hidden surface test (backface culling) with 3d points?
  1177.  
  1178.     Just define all points of all polygons in clockwise order.
  1179.  
  1180.             c = (x3*((z1*y2)-(y1*z2))+
  1181.                 (y3*((x1*z2)-(z1*x2))+
  1182.                 (z3*((y1*x2)-(x1*y2))+
  1183.  
  1184.     x1,y1,z1, x2,y2,z2, x3,y3,z3 = the first three points of the
  1185.     polygon.
  1186.  
  1187.     If c is positive the polygon is visible. If c is negative the
  1188.     polygon is invisible (or the other way).
  1189.  
  1190.  
  1191. ----------------------------------------------------------------------
  1192.  
  1193. Subject: 44) How do I do a hidden surface test (backface culling) with 2d points?
  1194.  
  1195.     c = (x1-x2)*(y3-y2)-(y1-y2)*(x3-x2)
  1196.  
  1197.     x1,y1, x2,y2, x3,y3 = the first three points of the polygon.
  1198.  
  1199.     If c is positive the polygon is visible. If c is negative the
  1200.     polygon is invisible (or the other way).
  1201.  
  1202.  
  1203. ----------------------------------------------------------------------
  1204.  
  1205. Subject: 45) Where can I find graph layout algorithms?
  1206.  
  1207.     See the paper by Eades and Tamassia, "Algorithms for Drawing
  1208.     Graphs: An Annotated Bibliography," Tech Rep CS-89-09, Dept.  of
  1209.     CS, Brown Univ, Feb. 1989.
  1210.  
  1211.     A revised version of the annotated bibliography on graph drawing
  1212.     algorithms by Giuseppe Di Battista, Peter Eades, and Roberto
  1213.     Tamassia is now available from
  1214.  
  1215.     ftp://wilma.cs.brown.edu/pub/papers/compgeo/gdbiblio.tex.Z and
  1216.     ftp://wilma.cs.brown.edu/pub/papers/compgeo/gdbiblio.ps.Z
  1217.  
  1218.  
  1219. ----------------------------------------------------------------------
  1220.  
  1221. Subject: 46) Where can I find algorithms for 2D collision detection?
  1222.  
  1223.  
  1224. ----------------------------------------------------------------------
  1225.  
  1226. Subject: 47) Where can I find algorithms for 3D collision detection?
  1227.  
  1228.     Check out "proxima", from Purdue, which is a C++ library for 3D
  1229.     collision detection for arbitrary polyhedra.  It's a nice system;
  1230.     the algorithms are sophisticated, but the code is of modest size.
  1231.  
  1232.     There's a copy in ftp://shasta.stanford.edu/pub/nagle/proxima; it
  1233.     may not be the latest version.
  1234.  
  1235.  
  1236. ----------------------------------------------------------------------
  1237.  
  1238. Subject: 48) 3D Noise functions and turbulence in Solid texturing.
  1239.  
  1240.     See:
  1241.         ftp://gondwana.ecr.mu.oz.au/pub/siggraph92_C23.shar
  1242.         ftp://ftp.cis.ohio-state.edu/siggraph92/siggraph92_C23.shar
  1243.  
  1244.     In it there are implementations of Perlin's noise and turbulence
  1245.     functions, (By the man himself) as well as Lewis' sparse
  1246.     convolution noise function (by D. Peachey) There is also some of
  1247.     other stuff in there (Musgrave's Earth texture functions, and some
  1248.     stuff on animating gases by Ebert).
  1249.  
  1250.  
  1251. ----------------------------------------------------------------------
  1252.  
  1253. Subject: 49) How do I perform basic viewing in 3d?
  1254.  
  1255.     We describe the shape and position of objects using numbers,
  1256.     usually (x,y,z) coordinates. For example, the corners of a cube
  1257.     might be {(0,0,0), (1,0,0), (1,1,0), (0,1,0), (0,0,1), (1,0,1),
  1258.     (1,1,1), (0,1,1)}. A deep understanding of what we are saying with
  1259.     these numbers requires mathematical study, but I will try to keep
  1260.     this simple. At the least, we must understand that we have
  1261.     designated some point in space as the origin--coordinates
  1262.     (0,0,0)--and marked off lines in 3 mutually perpendicular
  1263.     directions using equally spaced units to give us (x,y,z) values.
  1264.     It might be helpful to know if we are using 1 to mean 1 foot, 1
  1265.     meter, or 1 parsec; the numbers alone do not tell us.
  1266.  
  1267.     A picture on a screen is two steps removed from the 3D world it
  1268.     depicts. First, it is a 2D projection; and second, it is a finite
  1269.     resolution approximation to the infinitely precise projection. I
  1270.     will ignore the approximation (sampling) for now. To know what the
  1271.     projection looks like, we need to know where our viewpoint is, and
  1272.     where the plane of the projection is, both in the 3D world. Think
  1273.     of it as looking out a window into a scene. As artists discovered
  1274.     some 500 years ago, each point in the world appears to be at a
  1275.     point on the window. If you move your head or look out a different
  1276.     window, everything changes. When the mathematicians understood
  1277.     what the artists were doing, they invented perspective geometry.
  1278.  
  1279.     If your viewpoint is at the origin--(0,0,0)--and the window sits
  1280.     parallel to the x-y plane but at z=1, projection is no more than
  1281.     (x,y,z) in the world appears at (x/z,y/z,1) on the plane. Distant
  1282.     points will have large z values, causing them to shrink in the
  1283.     picture. That's perspective.
  1284.  
  1285.     The trick is to take an arbitrary viewpoint and plane, and
  1286.     transform the world so we have the simple viewing situation.
  1287.     There are two steps: move the viewpoint to the origin, then move
  1288.     the viewplane to the z=1 plane. If the viewpoint is at (vx,vy,vz),
  1289.     transform every point by the translation (x,y,z) -->
  1290.     (x-vx,y-vy,z-vz). This includes the viewpoint and the viewplane.
  1291.     Now we need to rotate so that the z axis points straight at the
  1292.     viewplane, then scale so it is 1 unit away.
  1293.  
  1294.     After all this, we may find ourselves looking out upside- down. It
  1295.     is traditional to specify some direction in the world or viewplane
  1296.     as "up", and rotate so the positive y axis points that way (as
  1297.     nearly as possible if it's a world vector). Finally, we have acted
  1298.     so far as if the window was the entire plane instead of a limited
  1299.     portal. A final shift and scale transforms coordinates in the
  1300.     plane to coordinates on the screen, so that a rectangular region
  1301.     of interest (our "window") in the plane fills a rectangular region
  1302.     of the screen (our "canvas" if you like).
  1303.  
  1304.     I have left out details of how you define and perform the rotation
  1305.     of the viewplane, but I'm sure someone else will be happy to
  1306.     supply those if there is demand. It requires knowing how to
  1307.     describe a plane, and how to rotate vectors to line up. Neither is
  1308.     difficult, but this is already using a lot of net space. One
  1309.     further practical difficulty is the need to clip away parts of the
  1310.     world behind us, so -(x,y,z) doesn't pop up at (x/z,y/z,1).
  1311.     (Notice the mathematics of projection alone would allow that!) But
  1312.     all the viewing transformations can be done using translation,
  1313.     rotation, scale, and a final perspective divide. If a 4x4
  1314.     homogeneous matrix is used, it can represent everything needed,
  1315.     which saves a lot of work.
  1316.  
  1317.  
  1318. ----------------------------------------------------------------------
  1319.  
  1320. Subject: 50) How can you contribute to this FAQ?
  1321.  
  1322.     Send email to jdstone@ingr.com with your suggestions, possible
  1323.     topics, corrections, or pointers to information.  Remember, I am
  1324.     not an expert on many of these topics.  I'm the editor.
  1325.  
  1326.     Here are some possible topics that may interest many of our
  1327.     readers.
  1328.  
  1329.     Clipping...
  1330.     Splines
  1331.     Nurbs
  1332.     Image Warping/Transformation/Filtering
  1333.     Anti-aliasing
  1334.     Volume Rendering
  1335.     Morphing (synonymous with generalized Warping)
  1336.     MPEG
  1337.     JPEG
  1338.     Z-buffer/A-buffer/etc.
  1339.     interpolation (linear, spline, fft, etc.)
  1340.     Modeling tricks  (fractal mountains, trees, seashells)
  1341.  
  1342.     Surfaces
  1343.     Ray Tracing
  1344.     Reflection/Refraction
  1345.  
  1346.     1) Computing the minimum bounding boxes of various geometric
  1347.        elements such as circular arcs, parabolas, clothoids, splines,
  1348.        etc.  What is the most efficient way to do them for the
  1349.        following cases:
  1350.  
  1351.         i)  The boxes are all orthogonal to the XY plane;
  1352.         ii) The boxes is oriented such that the smallest area
  1353.             rectangular bounding boxes are computed.
  1354.  
  1355.     2) What is the most efficient way to tell if a polygon crosses
  1356.        itself?  i.e. without intersecting every edge with every edge.
  1357.  
  1358. ----------------------------------------------------------------------
  1359.  
  1360. Subject: 51) Contributors.  Who made this all possible.
  1361.  
  1362.     andrewfg@aifh.ed.ac.uk (Andrew Fitzgibbon)
  1363.     atae@spva.ph.ic.ac.uk (Ata Etemadi)
  1364.     atsao@tkk.win.net (Anson Tsao)
  1365.     barber@geom.umn.edu (Brad Barber)
  1366.     bromage@mundil.cs.mu.OZ.AU (Andrew James Bromage)
  1367.     cek@Princeton.EDU (Craig Kolb)
  1368.     fritz@riverside.MR.Net (Fritz Lott)
  1369.     hollasch@kgc.com (Steve Hollasch)
  1370.     jens_alfke@powertalk.apple.com (Jens Alfke)
  1371.     karsten@addx.stgt.sub.org (Karsten Weiss)
  1372.     lhf@visgraf.impa.br (Luiz Henrique de Figueiredo)
  1373.     orourke@cs.smith.edu (Joseph O'Rourke)
  1374.     paik@mlo.dec.com (Samuel S. Paik)
  1375.     sammy@icarus.smds.com (Samuel Murphy)
  1376.     sanguish@digifix.com (Scott Anguish)
  1377.     shoemake@graphics.cis.upenn.edu (Ken Shoemake)
  1378.     slin@esri.com (Sum Lin)
  1379.     spl@szechuan.ucsd.edu (Steve Lamont)
  1380.     weilej@rpi.edu (Jason Weiler)
  1381.  
  1382.  
  1383. $Id: algorithms,v 1.14 1994/09/29 00:54:31 jdstone Exp $
  1384.  
  1385. -- 
  1386. ----------------------------------------------------------------------
  1387. Jon Stone                             Intergraph Corporation
  1388. jdstone@ingr.com                      Boulder, CO
  1389. ----------------------------------------------------------------------
  1390.