1 /* vproj.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      VPROJ ( Vector projection, 3 dimensions ) */
vproj_(doublereal * a,doublereal * b,doublereal * p)9 /* Subroutine */ int vproj_(doublereal *a, doublereal *b, doublereal *p)
10 {
11     /* System generated locals */
12     doublereal d__1, d__2;
13 
14     /* Local variables */
15     doublereal biga, bigb;
16     extern /* Subroutine */ int vscl_(doublereal *, doublereal *, doublereal *
17 	    );
18     extern doublereal vdot_(doublereal *, doublereal *);
19     doublereal r__[3], t[3], scale;
20 
21 /* $ Abstract */
22 
23 /*     VPROJ finds the projection of one vector onto another vector. */
24 /*     All vectors are 3-dimensional. */
25 
26 /* $ Disclaimer */
27 
28 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
29 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
30 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
31 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
32 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
33 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
34 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
35 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
36 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
37 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
38 
39 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
40 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
41 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
42 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
43 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
44 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
45 
46 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
47 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
48 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
49 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
50 
51 /* $ Required_Reading */
52 
53 /*     None. */
54 
55 /* $ Keywords */
56 
57 /*     VECTOR */
58 
59 /* $ Declarations */
60 /* $ Brief_I/O */
61 
62 /*     VARIABLE  I/O  DESCRIPTION */
63 /*     --------  ---  -------------------------------------------------- */
64 /*     A          I   The vector to be projected. */
65 /*     B          I   The vector onto which A is to be projected. */
66 /*     P          O   The projection of A onto B. */
67 
68 /* $ Detailed_Input */
69 
70 /*     A     is a double precision, 3-dimensional vector.  This */
71 /*           vector is to be projected onto the vector B. */
72 
73 /*     B     is a double precision, 3-dimensional vector.  This */
74 /*           vector is the vector which receives the projection. */
75 
76 /* $ Detailed_Output */
77 
78 /*     P     is a double precision, 3-dimensional vector containing the */
79 /*           projection of A onto B.  (P is necessarily parallel to B.) */
80 /*           If B is the zero vector then P will be returned as the zero */
81 /*           vector. */
82 
83 /* $ Parameters */
84 
85 /*     None. */
86 
87 /* $ Exceptions */
88 
89 /*     Error free. */
90 
91 /* $ Files */
92 
93 /*     None. */
94 
95 /* $ Particulars */
96 
97 /*     The given any vectors A and B there is a unique decomposition of */
98 /*     A as a sum V + P such that V  the dot product of V and B is zero, */
99 /*     and the dot product of P with B is equal the product of the */
100 /*     lengths of P and B.  P is called the projection of A onto B.  It */
101 /*     can be expressed mathematically as */
102 
103 /*        DOT(A,B) */
104 /*        -------- * B */
105 /*        DOT(B,B) */
106 
107 /*     (This is not necessarily the prescription used to compute the */
108 /*     projection. It is intended only for descriptive purposes.) */
109 
110 /* $ Examples */
111 
112 /*     The following table gives sample inputs and results from calling */
113 /*     VPROJ. */
114 
115 /*        A                  B           NDIM               P */
116 /*        ------------------------------------------------------- */
117 /*        (6, 6, 6)      ( 2, 0, 0)        3            (6, 0, 0) */
118 /*        (6, 6, 6)      (-3, 0, 0)        3            (6, 0, 0) */
119 /*        (6, 6, 0)      ( 0, 7, 0)        3            (0, 6, 0) */
120 /*        (6, 0, 0)      ( 0, 0, 9)        3            (0, 0, 0) */
121 
122 /* $ Restrictions */
123 
124 /*     None. */
125 
126 /* $ Literature_References */
127 
128 /*     Any reasonable calculus text (for example Thomas) */
129 
130 /* $ Author_and_Institution */
131 
132 /*     W.L. Taber      (JPL) */
133 
134 /* $ Version */
135 
136 /* -    SPICELIB Version 1.0.2, 23-APR-2010 (NJB) */
137 
138 /*        Header correction: assertions that the output */
139 /*        can overwrite the input have been removed. */
140 
141 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
142 
143 /*        Comment section for permuted index source lines was added */
144 /*        following the header. */
145 
146 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) */
147 
148 /* -& */
149 /* $ Index_Entries */
150 
151 /*     3-dimensional vector projection */
152 
153 /* -& */
154 
155 
156 /* Computing MAX */
157     d__1 = abs(a[0]), d__2 = abs(a[1]), d__1 = max(d__1,d__2), d__2 = abs(a[2]
158 	    );
159     biga = max(d__1,d__2);
160 /* Computing MAX */
161     d__1 = abs(b[0]), d__2 = abs(b[1]), d__1 = max(d__1,d__2), d__2 = abs(b[2]
162 	    );
163     bigb = max(d__1,d__2);
164     if (biga == 0.) {
165 	p[0] = 0.;
166 	p[1] = 0.;
167 	p[2] = 0.;
168 	return 0;
169     }
170     if (bigb == 0.) {
171 	p[0] = 0.;
172 	p[1] = 0.;
173 	p[2] = 0.;
174 	return 0;
175     }
176     r__[0] = b[0] / bigb;
177     r__[1] = b[1] / bigb;
178     r__[2] = b[2] / bigb;
179     t[0] = a[0] / biga;
180     t[1] = a[1] / biga;
181     t[2] = a[2] / biga;
182     scale = vdot_(t, r__) * biga / vdot_(r__, r__);
183     vscl_(&scale, r__, p);
184     return 0;
185 } /* vproj_ */
186 
187