void vprjpi_c ( ConstSpiceDouble vin [3], ConstSpicePlane * projpl, ConstSpicePlane * invpl, SpiceDouble vout [3], SpiceBoolean * found ) /* -Brief_I/O Variable I/O Description -------- --- -------------------------------------------------- vin I The projected vector. projpl I Plane containing vin. invpl I Plane containing inverse image of vin. vout O Inverse projection of vin. found O Flag indicating whether vout could be calculated. -Detailed_Input vin, projpl, invpl are, respectively, a 3-vector, a CSPICE plane containing the vector, and a CSPICE plane containing the inverse image of the vector under orthogonal projection onto projpl. -Detailed_Output vout is the inverse orthogonal projection of vin. This is the vector lying in the plane invpl whose orthogonal projection onto the plane projpl is vin. vout is valid only when found (defined below) is SPICETRUE. Otherwise, vout is undefined. found indicates whether the inverse orthogonal projection of vin could be computed. found is SPICETRUE if so, SPICEFALSE otherwise. -Parameters None. -Exceptions 1) If the geometric planes defined by projpl and invpl are orthogonal, or nearly so, the inverse orthogonal projection of vin may be undefined or have magnitude too large to represent with double precision numbers. In either such case, found will be set to SPICEFALSE. 2) Even when found is SPICETRUE, vout may be a vector of extremely large magnitude, perhaps so large that it is impractical to compute with it. It's up to you to make sure that this situation does not occur in your application of this routine. -Files None. -Particulars Projecting a vector orthogonally onto a plane can be thought of as finding the closest vector in the plane to the original vector. This `closest vector' always exists; it may be coincident with the original vector. Inverting an orthogonal projection means finding the vector in a specified plane whose orthogonal projection onto a second specified plane is a specified vector. The vector whose projection is the specified vector is the inverse projection of the specified vector, also called the `inverse image under orthogonal projection' of the specified vector. This routine finds the inverse orthogonal projection of a vector onto a plane. Related routines are vprjp_c, which projects a vector onto a plane orthogonally, and vproj_c, which projects a vector onto another vector orthogonally. -Examples 1) Suppose vin = ( 0.0, 1.0, 0.0 ), and that projpl has normal vector projn = ( 0.0, 0.0, 1.0 ). Also, let's suppose that invpl has normal vector and constant invn = ( 0.0, 2.0, 2.0 ) invc = 4.0. Then vin lies on the y-axis in the x-y plane, and we want to find the vector vout lying in invpl such that the orthogonal projection of vout the x-y plane is vin. Let the notation < a, b > indicate the inner product of vectors a and b. Since every point x in invpl satisfies the equation < x, (0.0, 2.0, 2.0) > = 4.0, we can verify by inspection that the vector ( 0.0, 1.0, 1.0 ) is in invpl and differs from vin by a multiple of projn. So ( 0.0, 1.0, 1.0 ) must be vout. To find this result using CSPICE, we can create the CSPICE planes projpl and invpl using the code fragment nvp2pl_c ( projn, vin, &projpl ); nvc2pl_c ( invn, invc, &invpl ); and then perform the inverse projection using the call vprjpi_c ( vin, &projpl, &invpl, vout ); vprjpi_c will return the value vout = ( 0.0, 1.0, 1.0 ); -Restrictions None. -Literature_References [1] `Calculus and Analytic Geometry', Thomas and Finney. -Author_and_Institution N.J. Bachman (JPL) -Version -CSPICE Version 1.1.0, 05-APR-2004 (NJB) Computation of LIMIT was re-structured to avoid run-time underflow warnings on some platforms. -CSPICE Version 1.0.0, 05-MAR-1999 (NJB) -Index_Entries vector projection onto plane inverted -& */ /* -Revisions -CSPICE Version 1.1.0, 05-APR-2004 (NJB) Computation of LIMIT was re-structured to avoid run-time underflow warnings on some platforms. In the revised code, BOUND/dpmax_c() is never scaled by a number having absolute value < 1. -& */ { /* Begin vprjpi_c */ /* Local constants */ /* BOUND is used to bound the magnitudes of the numbers that we try to take the reciprocal of, since we can't necessarily invert any non-zero number. We won't try to invert any numbers with magnitude less than BOUND / dpmax_c() BOUND is chosen somewhat arbitrarily.... */ #define BOUND 10.0 /* Local variables */ SpiceDouble denom; SpiceDouble invc; SpiceDouble invn [3]; SpiceDouble limit; SpiceDouble mult; SpiceDouble numer; SpiceDouble projc; SpiceDouble projn [3]; /* Participate in error tracing. */ if ( return_c() ) { return; } chkin_c ( "vprjpi_c" ); /* Unpack the planes. */ pl2nvc_c ( projpl, projn, &projc ); pl2nvc_c ( invpl, invn, &invc ); /* We'll first discuss the computation of VOUT in the nominal case, and then deal with the exceptional cases. When projpl and invpl are not orthogonal to each other, the inverse projection of vin will differ from vin by a multiple of projn, the unit normal vector to projpl. We find this multiple by using the fact that the inverse projection vout satisfies the plane equation for the inverse projection plane invpl. We have vout = vin + mult * projn; (1) since vout satisfies < vout, invn > = invc we must have < vin + mult * projn, invn > = invc which in turn implies invc - < vin, invn > mult = ------------------------. (2) < projn, invn > Having mult, we can compute vout according to equation (1). Now, if the denominator in the above expression for mult is zero or just too small, performing the division would cause a divide-by-zero error or an overflow of mult. In either case, we will avoid carrying out the division, and we'll set found to SPICEFALSE. Compute the numerator and denominator of the right side of (2). */ numer = invc - vdot_c ( vin, invn ); denom = vdot_c ( projn, invn ); /* If the magnitude of the denominator is greater than BOUND limit = abs ( ---------- * numer ), dpmax_c() we can safely divide the numerator by the denominator, and the magnitude of the result will be no greater than dpmax_c() ----------- . BOUND Note that we have ruled out the case where numer and denom are both zero by insisting on strict inequality in the comparison of denom and limit: */ if ( fabs(numer) < 1.0 ) { limit = fabs ( BOUND / dpmax_c() ); } else { limit = fabs ( ( BOUND / dpmax_c() ) * numer ); } *found = ( fabs (denom) > limit ); if ( *found ) { /* We'll compute vout after all. */ mult = numer / denom; vlcom_c ( 1.0, vin, mult, projn, vout ); } chkout_c ( "vprjpi_c" ); } /* End vprjpi_c */
void vprjp_c ( ConstSpiceDouble vin [3], ConstSpicePlane * plane, SpiceDouble vout [3] ) /* -Brief_I/O Variable I/O Description -------- --- -------------------------------------------------- vin I Vector to be projected. plane I A CSPICE plane onto which vin is projected. vout O Vector resulting from projection. -Detailed_Input vin is a 3-vector that is to be orthogonally projected onto a specified plane. plane is a CSPICE plane that represents the geometric plane onto which vin is to be projected. -Detailed_Output vout is the vector resulting from the orthogonal projection of vin onto plane. vout is the closest point in the specified plane to vin. -Parameters None. -Exceptions 1) Invalid input planes are diagnosed by the routine pl2nvc_c, which is called by this routine. -Files None. -Particulars Projecting a vector v orthogonally onto a plane can be thought of as finding the closest vector in the plane to v. This `closest vector' always exists; it may be coincident with the original vector. Two related routines are vprjpi_c, which inverts an orthogonal projection of a vector onto a plane, and vproj_c, which projects a vector orthogonally onto another vector. -Examples 1) Find the closest point in the ring plane of a planet to a spacecraft located at positn (in body-fixed coordinates). Suppose the vector normal is normal to the ring plane, and that origin, which represents the body center, is in the ring plane. Then we can make a `plane' with the code pnv2pl_c ( origin, normal, &plane ); can find the projection by making the call vprjp_c ( positn, &plane, proj ); -Restrictions None. -Literature_References [1] `Calculus and Analytic Geometry', Thomas and Finney. -Author_and_Institution N.J. Bachman (JPL) -Version -CSPICE Version 1.0.0, 05-MAR-1999 (NJB) -Index_Entries vector projection onto plane -& */ { /* Begin vprjp_c */ /* Local variables */ SpiceDouble constant; SpiceDouble normal [3]; /* Participate in error tracing. */ if ( return_c() ) { return; } chkin_c ( "vprjp_c" ); /* Obtain a unit vector normal to the input plane, and a constant for the plane. */ pl2nvc_c ( plane, normal, &constant ); /* Let the notation < a, b > indicate the inner product of vectors a and b. vin differs from its projection onto plane by some multiple of normal. That multiple is < vin - vout, normal > * normal = ( < vin, normal > - < vout, normal > ) * normal = ( < vin, normal > - const ) * normal Subtracting this multiple of normal from vin yields vout. */ vlcom_c ( 1.0, vin, constant - vdot_c ( vin, normal ), normal, vout ); chkout_c ( "vprjp_c" ); } /* End vprjp_c */
void pjelpl_c ( ConstSpiceEllipse * elin, ConstSpicePlane * plane, SpiceEllipse * elout ) /* -Brief_I/O Variable I/O Description -------- --- -------------------------------------------------- elin I A CSPICE ellipse to be projected. plane I A plane onto which elin is to be projected. elout O A CSPICE ellipse resulting from the projection. -Detailed_Input elin, plane are, respectively, a cspice ellipse and a cspice plane. The geometric ellipse represented by elin is to be orthogonally projected onto the geometric plane represented by plane. -Detailed_Output elout is a cspice ellipse that represents the geometric ellipse resulting from orthogonally projecting the ellipse represented by inel onto the plane represented by plane. -Parameters None. -Exceptions 1) If the input plane is invalid, the error will be diagnosed by routines called by this routine. 2) The input ellipse may be degenerate--its semi-axes may be linearly dependent. Such ellipses are allowed as inputs. 3) The ellipse resulting from orthogonally projecting the input ellipse onto a plane may be degenerate, even if the input ellipse is not. -Files None. -Particulars Projecting an ellipse orthogonally onto a plane can be thought of finding the points on the plane that are `under' or `over' the ellipse, with the `up' direction considered to be perpendicular to the plane. More mathematically, the orthogonal projection is the set of points Y in the plane such that for some point X in the ellipse, the vector Y - X is perpendicular to the plane. The orthogonal projection of an ellipse onto a plane yields another ellipse. -Examples 1) With center = { 1., 1., 1. }, vect1 = { 2., 0., 0. }, vect2 = { 0., 1., 1. }, normal = { 0., 0., 1. } the code fragment nvc2pl_c ( normal, 0., plane ); cgv2el_c ( center, vect1, vect2, elin ); pjelpl_c ( elin, plane, elout ); el2cgv_c ( elout, prjctr, prjmaj, prjmin ); returns prjctr = { 1., 1., 0. }, prjmaj = { 2., 0., 0. }, prjmin = { 0., 1., 0. } 2) With vect1 = { 2., 0., 0. }, vect2 = { 1., 1., 1. }, center = { 0., 0., 0. }, normal = { 0., 0., 1. }, the code fragment nvc2pl_c ( normal, 0., plane ); cgv2el_c ( center, vect1, vect2, elin ); pjelpl_c ( elin, plane, elout ); el2cgv_c ( elout, prjctr, prjmaj, prjmin ); returns prjctr = { 0., 0., 0. }; prjmaj = { -2.227032728823213, -5.257311121191336e-1, 0. }; prjmin = { 2.008114158862273e-1, -8.506508083520399e-1, 0. }; 3) An example of actual use: Suppose we wish to compute the distance from an ellipsoid to a line. Let the line be defined by a point P and a direction vector DIRECT; the line is the set of points P + t * DIRECT, where t is any real number. Let the ellipsoid have semi- axis lengths A, B, and C. We can reduce the problem to that of finding the distance between the line and an ellipse on the ellipsoid surface by considering the fact that the surface normal at the nearest point to the line will be orthogonal to DIRECT; the set of surface points where this condition holds lies in a plane, and hence is an ellipse on the surface. The problem can be further simplified by projecting the ellipse orthogonally onto the plane defined by < X, DIRECT > = 0. The problem is then a two dimensional one: find the distance of the projected ellipse from the intersection of the line and this plane (which is necessarily one point). A `paraphrase' of the relevant code is: #include "SpiceUsr.h" . . . /. Step 1. Find the candidate ellipse cand. normal is a normal vector to the plane containing the candidate ellipse. The ellipse must exist, since it's the intersection of an ellipsoid centered at the origin and a plane containing the origin. For this reason, we don't check inedpl_c's "found flag" found below. ./ normal[0] = direct[0] / (a*a); normal[1] = direct[1] / (b*b); normal[2] = direct[2] / (c*c); nvc2pl_c ( normal, 0., &candpl ); inedpl_c ( a, b, c, &candpl, cand, &found ); /. Step 2. Project the candidate ellipse onto a plane orthogonal to the line. We'll call the plane prjpl and the projected ellipse prjel. ./ nvc2pl_c ( direct, 0., &prjpl ); pjelpl_c ( &cand, &prjpl, &prjel ); /. Step 3. Find the point on the line lying in the projection plane, and then find the near point pjnear on the projected ellipse. Here prjpt is the point on the input line that lies in the projection plane. The distance between prjpt and pjnear is dist. ./ vprjp_c ( linept, &prjpl, prjpt ); npelpt_c ( &prjel, prjpt, pjnear, &dist ); /. Step 4. Find the near point pnear on the ellipsoid by taking the inverse orthogonal projection of PJNEAR; this is the point on the candidate ellipse that projects to pjnear. Note that the output dist was computed in step 3. The inverse projection of pjnear is guaranteed to exist, so we don't have to check found. ./ vprjpi_c ( pjnear, &prjpl, &candpl, pnear, &found ); /. The value of dist returned is the distance we're looking for. The procedure described here is carried out in the routine npedln_c. ./ -Restrictions None. -Literature_References None. -Author_and_Institution N.J. Bachman (JPL) -Version -CSPICE Version 1.0.0, 02-SEP-1999 (NJB) -Index_Entries project ellipse onto plane -& */ { /* Begin pjelpl_c */ /* Local variables */ SpiceDouble center[3]; SpiceDouble cnst; SpiceDouble normal[3]; SpiceDouble prjctr[3]; SpiceDouble prjvc1[3]; SpiceDouble prjvc2[3]; SpiceDouble smajor[3]; SpiceDouble sminor[3]; /* Participate in error tracing. */ chkin_c ( "pjelpl_c" ); /* Find generating vectors of the input ellipse. */ el2cgv_c ( elin, center, smajor, sminor ); /* Find a normal vector for the input plane. */ pl2nvc_c ( plane, normal, &cnst ); /* Find the components of the semi-axes that are orthogonal to the input plane's normal vector. The components are generating vectors for the projected plane. */ vperp_c ( smajor, normal, prjvc1 ); vperp_c ( sminor, normal, prjvc2 ); /* Find the projection of the ellipse's center onto the input plane. This is the center of the projected ellipse. In case the last assertion is non-obvious, note that the projection we're carrying out is the composition of a linear mapping (projection to a plane containing the origin and parallel to PLANE) and a translation mapping (adding the closest point to the origin in PLANE to every point), and both linear mappings and translations carry the center of an ellipse to the center of the ellipse's image. Let's state this using mathematical symbols. Let L be a linear mapping and let T be a translation mapping, say T(x) = x + A. Then T ( L ( center + cos(theta)smajor + sin(theta)sminor ) ) = A + L ( center + cos(theta)smajor + sin(theta)sminor ) = A + L (center) + cos(theta) L(smajor) + sin(theta) L(sminor) From the form of this last expression, we see that we have an ellipse centered at A + L (center) = T ( L (center) ) This last term is the image of the center of the original ellipse, as we wished to demonstrate. Now in the case of orthogonal projection onto a plane PL, L can be taken as the orthogonal projection onto a parallel plane PL' containing the origin. Then L is a linear mapping. Let M be the multiple of the normal vector of PL such that M is contained in PL (M is the closest point in PL to the origin). Then the orthogonal projection mapping onto PL, which we will name PRJ, can be defined by PRJ (x) = L (x) + M. So PRJ is the composition of a translation and a linear mapping, as claimed. */ vprjp_c ( center, plane, prjctr ); /* Put together the projected ellipse. */ cgv2el_c ( prjctr, prjvc1, prjvc2, elout ); chkout_c ( "pjelpl_c" ); } /* End pjelpl_c */