Table of contents
CSPICE_VSEPG finds the separation angle in radians between
two double precision vectors of arbitrary dimension. This angle is
defined as zero if either vector is zero.
Given:
v1,
v2 two double precision vectors of arbitrary dimension.
help, v1
DOUBLE = Array[N]
help, v2
DOUBLE = Array[N]
Either `v1' or `v2', or both, may be the zero vector.
An implicit assumption exists that `v1' and `v2' are
specified in the same reference space. If this is not
the case, the numerical result of this routine has no
meaning.
the call:
vsepg = cspice_vsepg( v1, v2 )
returns:
vsepg the angle between `v1' and `v2' expressed in radians.
help, vsepg
DOUBLE = Scalar
cspice_vsepg is strictly non-negative. For input vectors of
four or more dimensions, the angle is defined as the
generalization of the definition for three dimensions. If
either `v1' or `v2' is the zero vector, then cspice_vsepg is
defined to be 0 radians.
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 n-dimensional vectors and compute the
angular separation between each vector in first set and the
corresponding vector in the second set.
Example code begins here.
PRO vsepg_ex1
;;
;; Local parameters.
;;
SETSIZ = 3L
;;
;; Define the two vector sets.
;;
v1 = [ [ 1.D0, 0.D0, 0.D0, 0.D0 ], $
[ 1.D0, 0.D0, 0.D0, 0.D0 ], $
[ 3.D0, 0.D0, 0.D0, 0.D0 ] ]
v2 = [ [ 1.D0, 0.D0, 0.D0, 0.D0 ], $
[ 0.D0, 1.D0, 0.D0, 0.D0 ], $
[-5.D0, 0.D0, 0.D0, 0.D0 ] ]
;;
;; Calculate the angular separation between each pair
;; of vectors.
;;
for i=0L, SETSIZ-1L do begin
print, format='(A,4F6.1)', 'First vector : ', v1[*,i]
print, format='(A,4F6.1)', 'Second vector : ', v2[*,i]
print, format='(A,F15.10)', 'Angular separation (rad): ', $
cspice_vsepg( v1[*,i], v2[*,i] )
print
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
First vector : 1.0 0.0 0.0 0.0
Second vector : 1.0 0.0 0.0 0.0
Angular separation (rad): 0.0000000000
First vector : 1.0 0.0 0.0 0.0
Second vector : 0.0 1.0 0.0 0.0
Angular separation (rad): 1.5707963268
First vector : 3.0 0.0 0.0 0.0
Second vector : -5.0 0.0 0.0 0.0
Angular separation (rad): 3.1415926536
In four or more dimensions this angle does not have a physically
realizable interpretation. However, the angle is defined as
the generalization of the following definition which is valid in
three or two dimensions:
In the plane, it is a simple matter to calculate the angle
between two vectors once the two vectors have been made to be
unit length. Then, since the two vectors form the two equal
sides of an isosceles triangle, the length of the third side
is given by the expression
length = 2.0 * sin ( cspice_vsepg/2.0 )
The length is given by the magnitude of the difference of the
two unit vectors
length = norm ( u1 - u2 )
Once the length is found, the value of cspice_vsepg may be calculated
by inverting the first expression given above as
cspice_vsepg = 2.0 * arcsin ( length/2.0 )
This expression becomes increasingly unstable when cspice_vsepg gets
larger than pi/2 radians or 90 degrees. In this situation
(which is easily detected by determining the sign of the dot
product of `v1' and `v2') the supplementary angle is calculated
first and then cspice_vsepg is given by
cspice_vsepg = pi - supplementary_angle
1) If any of the input arguments, `v1' or `v2', is undefined, an
error is signaled by the IDL error handling system.
2) If any of the input arguments, `v1' or `v2', is not of the
expected type, or it does not have the expected dimensions and
size, an error is signaled by the Icy interface.
3) If the input vector arguments `v1' and `v2' do not have the
same dimension (N), an error is signaled by the Icy interface.
None.
1) The user is required to insure that the input vectors will not
cause floating point overflow upon calculation of the vector
dot product since no error detection or correction code is
implemented. In practice, this is not a significant
restriction.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.3, 10-AUG-2021 (JDR)
Edited the header to comply with NAIF standard. Added complete
code examples.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections, and
completed -Particulars section.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.2, 23-SEP-2008 (EDW)
Eliminated error in English.
-Icy Version 1.0.1, 09-DEC-2005 (EDW)
Added -Examples section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
angular separation of n-dimensional vectors
|