ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/fvect.c
Revision: 1.5
Committed: Tue Feb 22 15:58:41 2011 UTC (13 years, 2 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +1 -1 lines
State: FILE REMOVED
Log Message:
Finish of code reorg, moving MGF library into src/cv and src/common

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 1.5 static const char RCSid[] = "$Id: fvect.c,v 1.4 2003/02/28 20:11:29 greg Exp $";
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     }