source: trunk/MagicSoft/slalib/vn.c@ 13591

Last change on this file since 13591 was 732, checked in by tbretz, 24 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 906 bytes
Line 
1#include "slalib.h"
2#include "slamac.h"
3void slaVn ( float v[3], float uv[3], float *vm )
4/*
5** - - - - - -
6** s l a V n
7** - - - - - -
8**
9** Normalizes a 3-vector also giving the modulus.
10**
11** (single precision)
12**
13** Given:
14** v float[3] vector
15**
16** Returned:
17** uv float[3] unit vector in direction of v
18** *vm float modulus of v
19**
20** Note: v and uv may be the same array.
21**
22** If the modulus of v is zero, uv is set to zero as well.
23**
24** Last revision: 6 November 1999
25**
26** Copyright P.T.Wallace. All rights reserved.
27*/
28{
29 int i;
30 float w1, w2;
31
32/* Modulus */
33 w1 = 0.0f;
34 for ( i = 0; i < 3; i++ ) {
35 w2 = v[i];
36 w1 = w1 + w2 * w2;
37 }
38 w1 = (float) sqrt ( w1 );
39 *vm = w1;
40
41/* Normalize the vector */
42 if ( w1 <= 0.0f ) {
43 w1 = 1.0f;
44 }
45 for ( i = 0; i < 3; i++ ) {
46 uv[i] = v[i] / w1;
47 }
48}
Note: See TracBrowser for help on using the repository browser.