Table of contents
CSPICE_VPROJG computes the projection of one vector onto another vector.
All vectors are of arbitrary dimension.
Given:
a a double precision vector of arbitrary dimension.
[n,1] = size(a); double = class(a)
This vector is to be projected onto the vector `b'.
b a double precision vector of arbitrary dimension.
[n,1] = size(b); double = class(b)
This vector is the vector which receives the projection.
the call:
[p] = cspice_vprojg( a, b )
returns:
p a double precision vector of arbitrary dimension containing
the projection of `a' onto `b'.
[n,1] = size(p); double = class(p)
(`p' is necessarily parallel to `b'.)
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
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.
function vprojg_ex1()
%
% Local parameters.
%
SETSIZ = 4;
%
% Define the two vector sets.
%
seta = [ [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]' ];
setb = [ [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=1:SETSIZ
[pvec] = cspice_vprojg( seta(:,i), setb(:,i) );
fprintf( 'Vector A : %4.1f %4.1f %4.1f %4.1f\n', ...
seta(1,i), seta(2,i), seta(3,i), seta(4,i) )
fprintf( 'Vector B : %4.1f %4.1f %4.1f %4.1f\n', ...
setb(1,i), setb(2,i), setb(3,i), setb(4,i) )
fprintf( 'Projection: %4.1f %4.1f %4.1f %4.1f\n', ...
pvec(1), pvec(2), pvec(3), pvec(4) )
fprintf( ' \n' )
end
When this program was executed on a Mac/Intel/Octave6.x/64-bit
platform, the output was:
Vector A : 6.0 6.0 6.0 0.0
Vector B : 2.0 0.0 0.0 0.0
Projection: 6.0 0.0 0.0 0.0
Vector A : 6.0 6.0 6.0 0.0
Vector B : -3.0 0.0 0.0 0.0
Projection: 6.0 -0.0 -0.0 -0.0
Vector A : 6.0 6.0 0.0 0.0
Vector B : 0.0 7.0 0.0 0.0
Projection: 0.0 6.0 0.0 0.0
Vector A : 6.0 0.0 0.0 0.0
Vector B : 0.0 0.0 9.0 0.0
Projection: 0.0 0.0 0.0 0.0
The 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.
1) If any of the input arguments, `a' or `b', is undefined, an
error is signaled by the Matlab error handling system.
2) If any of the input arguments, `a' or `b', is not of the
expected type, or it does not have the expected dimensions and
size, an error is signaled by the Mice interface.
3) If the input vector arguments `a' and `b' do not have the same
dimension (n), an error is signaled by the Mice interface.
None.
1) 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.
MICE.REQ
[1] G. Thomas and R. Finney, "Calculus and Analytic Geometry,"
7th Edition, Addison Wesley, 1988.
J. Diaz del Rio (ODC Space)
-Mice Version 1.0.0, 26-NOV-2021 (JDR)
n-dimensional vector projection
|