1 /* nplnpt.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      NPLNPT ( Nearest point on line to point ) */
nplnpt_(doublereal * linpt,doublereal * lindir,doublereal * point,doublereal * pnear,doublereal * dist)9 /* Subroutine */ int nplnpt_(doublereal *linpt, doublereal *lindir,
10 	doublereal *point, doublereal *pnear, doublereal *dist)
11 {
12     extern /* Subroutine */ int vadd_(doublereal *, doublereal *, doublereal *
13 	    );
14     doublereal proj[3];
15     extern /* Subroutine */ int vsub_(doublereal *, doublereal *, doublereal *
16 	    ), chkin_(char *, ftnlen);
17     doublereal trans[3];
18     extern doublereal vdist_(doublereal *, doublereal *);
19     extern /* Subroutine */ int vproj_(doublereal *, doublereal *, doublereal
20 	    *);
21     extern logical vzero_(doublereal *);
22     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
23 	    ftnlen), setmsg_(char *, ftnlen);
24     extern logical return_(void);
25 
26 /* $ Abstract */
27 
28 /*     Find the nearest point on a line to a specified point, and find */
29 /*     the distance between the two points. */
30 
31 /* $ Disclaimer */
32 
33 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
34 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
35 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
36 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
37 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
38 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
39 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
40 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
41 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
42 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
43 
44 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
45 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
46 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
47 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
48 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
49 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
50 
51 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
52 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
53 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
54 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
55 
56 /* $ Required_Reading */
57 
58 /*     None. */
59 
60 /* $ Keywords */
61 
62 /*     GEOMETRY */
63 /*     MATH */
64 /*     VECTOR */
65 
66 /* $ Declarations */
67 /* $ Brief_I/O */
68 
69 /*     Variable  I/O  Description */
70 /*     --------  ---  -------------------------------------------------- */
71 /*     LINPT, */
72 /*     LINDIR     I   Point on a line and the line's direction vector. */
73 /*     POINT      I   A second point. */
74 /*     PNEAR      O   Nearest point on the line to POINT. */
75 /*     DIST       O   Distance between POINT and PNEAR. */
76 
77 /* $ Detailed_Input */
78 
79 /*     LINPT */
80 /*     LINDIR         are, respectively, a point and a direction vector */
81 /*                    that define a line in 3-dimensional space.  The */
82 /*                    line is the set of points */
83 
84 /*                       LINPT   +   t * LINDIR */
85 
86 /*                    where t is any real number. */
87 
88 /*     POINT          is a point in 3-dimensional space. */
89 
90 /* $ Detailed_Output */
91 
92 /*     PNEAR          is the nearest point on the input line to the input */
93 /*                    point. */
94 
95 /*     DIST           is the distance between the input line and input */
96 /*                    point. */
97 
98 /* $ Parameters */
99 
100 /*     None. */
101 
102 /* $ Exceptions */
103 
104 /*     1)  If the line direction vector LINDIR is the zero vector, the */
105 /*         error SPICE(ZEROVECTOR) is signaled. */
106 
107 /* $ Files */
108 
109 /*     None. */
110 
111 /* $ Particulars */
112 
113 /*     For every line L and point P, there is a unique closest point */
114 /*     on L to P.  Call this closest point C.  It is always true that */
115 /*     P - C  is perpendicular to L, and the length of P - C is called */
116 /*     the `distance' between P and L. */
117 
118 /* $ Examples */
119 
120 /*     1)  Suppose a line passes through the point ( 1, 2, 3 ) and */
121 /*         has direction vector ( 0, 1, 1 ).  We wish to find the */
122 /*         closest point on the line to the point ( -6, 9, 10 ).  We */
123 /*         can use the code fragment */
124 
125 /*            LINPT(1)   =  1.D0 */
126 /*            LINPT(2)   =  2.D0 */
127 /*            LINPT(3)   =  3.D0 */
128 
129 /*            LINDIR(1)  =  0.D0 */
130 /*            LINDIR(2)  =  1.D0 */
131 /*            LINDIR(3)  =  1.D0 */
132 
133 /*            POINT(1)   = -6.D0 */
134 /*            POINT(2)   =  9.D0 */
135 /*            POINT(3)   = 10.D0 */
136 
137 /*            CALL NPLNPT ( LINPT, LINDIR, POINT, PNEAR, DIST ) */
138 
139 /*         After the call, PNEAR will take the value */
140 
141 /*            ( 1.D0, 9.D0, 10.D0 ); */
142 
143 /*         DIST will be 7.0. */
144 
145 /* $ Restrictions */
146 
147 /*     None. */
148 
149 /* $ Literature_References */
150 
151 /*     None. */
152 
153 /* $ Author_and_Institution */
154 
155 /*     N.J. Bachman   (JPL) */
156 
157 /* $ Version */
158 
159 /* -    SPICELIB Version 1.2.0, 17-SEP-2014 (NJB) */
160 
161 /*        Now uses discovery check-in. */
162 
163 /* -    SPICELIB Version 1.1.0, 09-SEP-2005 (NJB) */
164 
165 /*        Updated to remove non-standard use of duplicate arguments */
166 /*        in VADD call. */
167 
168 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
169 
170 /*        Comment section for permuted index source lines was added */
171 /*        following the header. */
172 
173 /* -    SPICELIB Version 1.0.0, 02-NOV-1990 (NJB) */
174 
175 /* -& */
176 /* $ Index_Entries */
177 
178 /*     distance between point and line */
179 /*     nearest point on line to point */
180 
181 /* -& */
182 /* $ Revisions */
183 
184 /* -    SPICELIB Version 1.1.0, 09-SEP-2005 (NJB) */
185 
186 /*        Updated to remove non-standard use of duplicate arguments */
187 /*        in VADD call. */
188 
189 /* -& */
190 
191 /*     SPICELIB functions */
192 
193 
194 /*     Local variables */
195 
196 
197 /*     Use discovery check-in. */
198 
199     if (return_()) {
200 	return 0;
201     }
202 
203 /*     We need a real direction vector to work with. */
204 
205     if (vzero_(lindir)) {
206 	chkin_("NPLNPT", (ftnlen)6);
207 	setmsg_("Direction vector must be non-zero.", (ftnlen)34);
208 	sigerr_("SPICE(ZEROVECTOR)", (ftnlen)17);
209 	chkout_("NPLNPT", (ftnlen)6);
210 	return 0;
211     }
212 
213 /*     We translate line and input point so as to put the line through */
214 /*     the origin.  Then the nearest point on the translated line to the */
215 /*     translated point TRANS is the projection of TRANS onto the line. */
216 
217     vsub_(point, linpt, trans);
218     vproj_(trans, lindir, proj);
219     vadd_(proj, linpt, pnear);
220     *dist = vdist_(pnear, point);
221     return 0;
222 } /* nplnpt_ */
223 
224