source: trunk/MagicSoft/slalib/dvn.c@ 5018

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