ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/fvect.c
Revision: 1.4
Committed: Fri Feb 28 20:11:29 2003 UTC (21 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad3R7P1, rad4R0, rad3R5, rad3R6, rad3R6P1, rad3R8, rad3R9, rad3R7P2
Changes since 1.3: +2 -4 lines
Log Message:
Updates for 3.5 release

File Contents

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