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
Error occurred while calculating annotation data.
Log Message:
Finish of code reorg, moving MGF library into src/cv and src/common

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: fvect.c,v 1.4 2003/02/28 20:11:29 greg Exp $";
3 #endif
4 /*
5 * Routines for 3-d vectors
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #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 len = DOT(v, v);
21
22 if (len <= 0.0)
23 return(0.0);
24
25 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
30 v[0] /= len;
31 v[1] /= len;
32 v[2] /= len;
33
34 return(len);
35 }
36
37
38 void
39 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 }