ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/fvect.c
(Generate patch)

Comparing ray/src/common/fvect.c (file contents):
Revision 2.1 by greg, Tue Nov 12 16:55:09 1991 UTC vs.
Revision 2.7 by greg, Tue Feb 25 02:47:21 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5 < *  fvect.c - routines for float vector calculations
9 < *
10 < *     8/14/85
5 > *  fvect.c - routines for floating-point vector calculations
6   */
7  
8 + #include "copyright.h"
9 +
10 + #include  <math.h>
11   #include  "fvect.h"
12  
13  
# Line 25 | Line 23 | double
23   dist2(p1, p2)                   /* return square of distance between points */
24   register FVECT  p1, p2;
25   {
26 <        static FVECT  delta;
26 >        FVECT  delta;
27  
28          delta[0] = p2[0] - p1[0];
29          delta[1] = p2[1] - p1[1];
30          delta[2] = p2[2] - p1[2];
31 +
32          return(DOT(delta, delta));
33   }
34  
# Line 39 | Line 38 | dist2line(p, ep1, ep2)         /* return square of distance t
38   FVECT  p;               /* the point */
39   FVECT  ep1, ep2;        /* points on the line */
40   {
41 <        static double  d, d1, d2;
41 >        register double  d, d1, d2;
42  
43          d = dist2(ep1, ep2);
44          d1 = dist2(ep1, p);
45 <        d2 = dist2(ep2, p);
45 >        d2 = d + d1 - dist2(ep2, p);
46  
47 <        return(d1 - (d+d1-d2)*(d+d1-d2)/d/4);
47 >        return(d1 - 0.25*d2*d2/d);
48   }
49  
50  
# Line 54 | Line 53 | dist2lseg(p, ep1, ep2)         /* return square of distance t
53   FVECT  p;               /* the point */
54   FVECT  ep1, ep2;        /* the end points */
55   {
56 <        static double  d, d1, d2;
56 >        register double  d, d1, d2;
57  
58          d = dist2(ep1, ep2);
59          d1 = dist2(ep1, p);
# Line 67 | Line 66 | FVECT  ep1, ep2;       /* the end points */
66                  if (d1 - d2 > d)
67                          return(d2);
68          }
69 +        d2 = d + d1 - d2;
70  
71 <        return(d1 - (d+d1-d2)*(d+d1-d2)/d/4);   /* distance to line */
71 >        return(d1 - 0.25*d2*d2/d);      /* distance to line */
72   }
73  
74  
75 + void
76   fcross(vres, v1, v2)            /* vres = v1 X v2 */
77   register FVECT  vres, v1, v2;
78   {
# Line 81 | Line 82 | register FVECT  vres, v1, v2;
82   }
83  
84  
85 + void
86   fvsum(vres, v0, v1, f)          /* vres = v0 + f*v1 */
87 < FVECT  vres, v0, v1;
88 < double  f;
87 > register FVECT  vres, v0, v1;
88 > register double  f;
89   {
90          vres[0] = v0[0] + f*v1[0];
91          vres[1] = v0[1] + f*v1[1];
# Line 95 | Line 97 | double
97   normalize(v)                    /* normalize a vector, return old magnitude */
98   register FVECT  v;
99   {
100 <        static double  len;
100 >        register double  len, d;
101          
102 <        len = DOT(v, v);
102 >        d = DOT(v, v);
103          
104 <        if (len <= 0.0)
104 >        if (d <= 0.0)
105                  return(0.0);
106          
107 <        /****** problematic
108 <        if (len >= (1.0-FTINY)*(1.0-FTINY) &&
109 <                        len <= (1.0+FTINY)*(1.0+FTINY))
110 <                return(1.0);
109 <        ******/
107 >        if (d <= 1.0+FTINY && d >= 1.0-FTINY)
108 >                len = 0.5 + 0.5*d;      /* first order approximation */
109 >        else
110 >                len = sqrt(d);
111  
112 <        len = sqrt(len);
113 <        v[0] /= len;
114 <        v[1] /= len;
115 <        v[2] /= len;
112 >        v[0] *= d = 1.0/len;
113 >        v[1] *= d;
114 >        v[2] *= d;
115 >
116          return(len);
117   }
118  
119  
120 + void
121   spinvector(vres, vorig, vnorm, theta)   /* rotate vector around normal */
122   FVECT  vres, vorig, vnorm;
123   double  theta;
124   {
123        extern double  cos(), sin();
125          double  sint, cost, normprod;
126          FVECT  vperp;
127          register int  i;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines