vprojg_c |

Table of contents## Procedurevprojg_c ( Vector projection, general dimension ) void vprojg_c ( ConstSpiceDouble a [], ConstSpiceDouble b [], SpiceInt ndim, SpiceDouble p [] ) ## AbstractCompute the projection of one vector onto another vector. All vectors are of arbitrary dimension. ## Required_ReadingNone. ## KeywordsVECTOR ## Brief_I/OVARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- a I The vector to be projected. b I The vector onto which `a' is to be projected. ndim I Dimension of `a', `b', and `p'. p O The projection of `a' onto `b'. ## Detailed_Inputa is a double precision vector of arbitrary dimension. This vector is to be projected onto the vector `b'. b is a double precision vector of arbitrary dimension. This vector is the vector which receives the projection. ndim is the dimension of `a', `b' and `p'. ## Detailed_Outputp is a double precision vector of arbitrary dimension containing the projection of `a' onto `b'. (`p' is necessarily parallel to `b'.) ## ParametersNone. ## ExceptionsError free. ## FilesNone. ## ParticularsThe projection of a vector `a' onto a vector `b' is, by definition, that component of `a' which is parallel to `b'. To find this component it is enough to find the scalar ratio of the length of `b' to the projection of `a' onto `b', and then use this number to scale the length of `b'. This ratio is given by ratio = < a, b > / < b, b > where <,> denotes the general vector dot product. This routine does not attempt to divide by zero in the event that `b' is the zero vector. ## ExamplesThe numerical results shown for this example may differ across platforms. The results depend on the SPICE kernels used as input, the compiler and supporting libraries, and the machine specific arithmetic implementation. 1) Define two sets of vectors and compute the projection of each vector of the first set on the corresponding vector of the second set. Example code begins here. /. Program vprojg_ex1 ./ #include <stdio.h> #include "SpiceUsr.h" int main( ) { /. Local parameters. ./ #define NDIM 4 #define SETSIZ 4 /. Local variables. ./ SpiceDouble pvec [NDIM]; SpiceInt i; /. Define the two vector sets. ./ SpiceDouble seta [SETSIZ][NDIM] = { {6.0, 6.0, 6.0, 0.0}, {6.0, 6.0, 6.0, 0.0}, {6.0, 6.0, 0.0, 0.0}, {6.0, 0.0, 0.0, 0.0} }; SpiceDouble setb [SETSIZ][NDIM] = { {2.0, 0.0, 0.0, 0.0}, {-3.0, 0.0, 0.0, 0.0}, {0.0, 7.0, 0.0, 0.0}, {0.0, 0.0, 9.0, 0.0} }; /. Calculate the projection ./ for ( i = 0; i < SETSIZ; i++ ) { ## Restrictions1) No error detection or recovery schemes are incorporated into this routine except to insure that no attempt is made to divide by zero. Thus, the user is required to make sure that the vectors `a' and `b' are such that no floating point overflow will occur when the dot products are calculated. ## Literature_References[1] G. Thomas and R. Finney, "Calculus and Analytic Geometry," 7th Edition, Addison Wesley, 1988. ## Author_and_InstitutionJ. Diaz del Rio (ODC Space) ## Version-CSPICE Version 1.0.0, 01-NOV-2021 (JDR) ## Index_Entriesn-dimensional vector projection |

Fri Dec 31 18:41:15 2021