ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/cv/mgflib/fvect.c
Revision: 1.2
Committed: Thu Jun 23 23:02:45 1994 UTC (29 years, 10 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 1.1: +5 -2 lines
Log Message:
made normalize() more like Radiance lib version

File Contents

# Content
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 len = DOT(v, v);
23
24 if (len <= 0.0)
25 return(0.0);
26
27 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
32 v[0] /= len;
33 v[1] /= len;
34 v[2] /= len;
35
36 return(len);
37 }
38
39
40 fcross(vres, v1, v2) /* vres = v1 X v2 */
41 register FVECT vres, v1, v2;
42 {
43 vres[0] = v1[1]*v2[2] - v1[2]*v2[1];
44 vres[1] = v1[2]*v2[0] - v1[0]*v2[2];
45 vres[2] = v1[0]*v2[1] - v1[1]*v2[0];
46 }