home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / LIB / GLE / intersect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-12  |  2.2 KB  |  68 lines

  1. /*
  2.  * FUNCTION:
  3.  * This file contains a number of utilities useful to 3D graphics in
  4.  * general, and to the generation of tubing and extrusions in particular
  5.  * 
  6.  * HISTORY:
  7.  * Written by Linas Vepstas, August 1991
  8.  */
  9.  
  10. #include "gutil.h"
  11. #include "intersect.h"
  12.  
  13. /* ========================================================== */
  14. /* 
  15.  * The macro and subroutine INTERSECT are designed to compute the
  16.  * intersection of a line (defined by the points v1 and v2) and a plane
  17.  * (defined as plane which is normal to the vector n, and contains the
  18.  * point p).  Both sect the array "sect", which is the point of
  19.  * interesection.
  20.  * 
  21.  * The subroutine returns a value indicating if the specified inputs
  22.  * represented a degenerate case. Valid is TRUE if the computed
  23.  * intersection is valid, else it is FALSE.
  24.  */
  25.  
  26.  
  27. /* ========================================================== */
  28.  
  29. void intersect (gleDouble sect[3],    /* returned */
  30.                 gleDouble p[3],    /* input */
  31.                 gleDouble n[3],    /* input */
  32.                 gleDouble v1[3],    /* input */
  33.                 gleDouble v2[3])    /* input */
  34. {
  35.    INTERSECT (sect, p, n, v1, v2);
  36. }
  37.  
  38. /* ========================================================== */
  39. /* 
  40.  * The macro and subroutine BISECTING_PLANE compute a normal vecotr that
  41.  * describes the bisecting plane between three points (v1, v2 and v3).  
  42.  * This bisecting plane has the following properties:
  43.  * 1) it contains the point v2
  44.  * 2) the angle it makes with v21 == v2 - v1 is equal to the angle it 
  45.  *    makes with v32 == v3 - v2 
  46.  * 3) it is perpendicular to the plane defined by v1, v2, v3.
  47.  *
  48.  * Having input v1, v2, and v3, it returns a vector n.
  49.  * Note that n is NOT normalized (is NOT of unit length).
  50.  * 
  51.  * The subroutine returns a value indicating if the specified inputs
  52.  * represented a degenerate case. Valid is TRUE if the computed
  53.  * intersection is valid, else it is FALSE.
  54.  */
  55.  
  56. int bisecting_plane (gleDouble n[3],    /* returned */
  57.                       gleDouble v1[3],    /* input */
  58.                       gleDouble v2[3],    /* input */
  59.                       gleDouble v3[3])    /* input */
  60. {
  61.    int valid;
  62.  
  63.    BISECTING_PLANE (valid, n, v1, v2, v3);
  64.    return (valid);
  65. }
  66.  
  67. /* ========================================================== */
  68.