1 /* vhat.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* $Procedure VHAT ( "V-Hat", unit vector along V, 3 dimensions ) */
vhat_(doublereal * v1,doublereal * vout)9 /* Subroutine */ int vhat_(doublereal *v1, doublereal *vout)
10 {
11 doublereal vmag;
12 extern doublereal vnorm_(doublereal *);
13
14 /* $ Abstract */
15
16 /* Find the unit vector along a double precision 3-dimensional */
17 /* vector. */
18
19 /* $ Disclaimer */
20
21 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
22 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
23 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
24 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
25 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
26 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
27 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
28 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
29 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
30 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
31
32 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
33 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
34 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
35 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
36 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
37 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
38
39 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
40 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
41 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
42 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
43
44 /* $ Required_Reading */
45
46 /* None. */
47
48 /* $ Keywords */
49
50 /* VECTOR */
51
52 /* $ Declarations */
53 /* $ Brief_I/O */
54
55 /* VARIABLE I/O DESCRIPTION */
56 /* -------- --- -------------------------------------------------- */
57 /* V1 I Vector to be normalized. */
58 /* VOUT O Unit vector V1 / |V1|. */
59 /* If V1 = 0, VOUT will also be zero. */
60 /* VOUT can overwrite V1. */
61
62 /* $ Detailed_Input */
63
64 /* V1 This is any double precision, 3-dimensional vector. If */
65 /* this vector is the zero vector, this routine will detect */
66 /* it, and will not attempt to divide by zero. */
67
68 /* $ Detailed_Output */
69
70 /* VOUT VOUT contains the unit vector in the direction of V1. If */
71 /* V1 represents the zero vector, then VOUT will also be the */
72 /* zero vector. VOUT may overwrite V1. */
73
74 /* $ Parameters */
75
76 /* None. */
77
78 /* $ Particulars */
79
80 /* VHAT determines the magnitude of V1 and then divides each */
81 /* component of V1 by the magnitude. This process is highly stable */
82 /* over the whole range of 3-dimensional vectors. */
83
84 /* $ Examples */
85
86 /* The following table shows how selected V1 implies VOUT. */
87
88 /* V1 VOUT */
89 /* ------------------ ------------------ */
90 /* (5, 12, 0) (5/13, 12/13, 0) */
91 /* (1D-7, 2D-7, 2D-7) (1/3, 2/3, 2/3) */
92
93
94 /* $ Restrictions */
95
96 /* There is no known case whereby floating point overflow may occur. */
97 /* Thus, no error recovery or reporting scheme is incorporated */
98 /* into this subroutine. */
99
100 /* $ Exceptions */
101
102 /* Error free. */
103
104 /* $ Files */
105
106 /* None. */
107
108 /* $ Author_and_Institution */
109
110 /* N.J. Bachman (JPL) */
111 /* H.A. Neilan (JPL) */
112 /* W.M. Owen (JPL) */
113
114 /* $ Literature_References */
115
116 /* None. */
117
118 /* $ Version */
119
120 /* - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
121
122 /* Comment section for permuted index source lines was added */
123 /* following the header. */
124
125 /* - SPICELIB Version 1.0.0, 31-JAN-1990 (WMO) */
126
127 /* -& */
128 /* $ Index_Entries */
129
130 /* unitize a 3-dimensional vector */
131
132 /* -& */
133 /* $ Revisions */
134
135 /* - Beta Version 1.1.0, 10-FEB-1989 (HAN) (NJB) */
136
137 /* Contents of the Exceptions section was changed */
138 /* to "error free" to reflect the decision that the */
139 /* module will never participate in error handling. */
140 /* Also, the declaration of the unused variable I was */
141 /* removed. */
142 /* -& */
143
144 /* Obtain the magnitude of V1 */
145
146 vmag = vnorm_(v1);
147
148 /* If VMAG is nonzero, then normalize. Note that this process is */
149 /* numerically stable: overflow could only happen if VMAG were small, */
150 /* but this could only happen if each component of V1 were small. */
151 /* In fact, the magnitude of any vector is never less than the */
152 /* magnitude of any component. */
153
154 if (vmag > 0.) {
155 vout[0] = v1[0] / vmag;
156 vout[1] = v1[1] / vmag;
157 vout[2] = v1[2] / vmag;
158 } else {
159 vout[0] = 0.;
160 vout[1] = 0.;
161 vout[2] = 0.;
162 }
163 return 0;
164 } /* vhat_ */
165
166