ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/fvect.c
Revision: 1.3
Committed: Tue Mar 18 11:05:33 1997 UTC (27 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.2: +1 -0 lines
Log Message:
added fh entity and general cleanup

File Contents

# User Rev Content
1 greg 1.1 /* Copyright (c) 1994 Regents of the University of California */
2    
3     #ifndef lint
4     static char SCCSid[] = "$SunId$ LBL";
5     #endif
6    
7     /*
8     * Routines for 3-d vectors
9     */
10    
11     #include <stdio.h>
12     #include <math.h>
13     #include "parser.h"
14    
15    
16     double
17     normalize(v) /* normalize a vector, return old magnitude */
18     register FVECT v;
19     {
20     static double len;
21    
22 greg 1.2 len = DOT(v, v);
23 greg 1.1
24     if (len <= 0.0)
25     return(0.0);
26    
27 greg 1.2 if (len <= 1.0+FTINY && len >= 1.0-FTINY)
28     len = 0.5 + 0.5*len; /* first order approximation */
29     else
30     len = sqrt(len);
31 greg 1.1
32     v[0] /= len;
33     v[1] /= len;
34     v[2] /= len;
35    
36     return(len);
37     }
38    
39    
40 greg 1.3 void
41 greg 1.1 fcross(vres, v1, v2) /* vres = v1 X v2 */
42     register FVECT vres, v1, v2;
43     {
44     vres[0] = v1[1]*v2[2] - v1[2]*v2[1];
45     vres[1] = v1[2]*v2[0] - v1[0]*v2[2];
46     vres[2] = v1[0]*v2[1] - v1[1]*v2[0];
47     }