Table of contents
CSPICE_VSEP finds the separation angle in radians between two double
precision, 3-dimensional vectors. This angle is defined as zero
if either vector is zero.
Given:
v1,
v2 two double precision 3-dimensional vectors.
help, v1
DOUBLE = Array[3]
help, v2
DOUBLE = Array[3]
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 frame. If this is not
the case, the numerical result of this routine has no
meaning.
the call:
vsep = cspice_vsep( v1, v2 )
returns:
vsep the double precision, positive definite, scalar angular
separation between `v1' and `v2' expressed in radians.
help, vsep
DOUBLE = Scalar
If either `v1' or `v2' is the zero vector, then cspice_vsep 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 3-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 vsep_ex1
;;
;; Local parameters.
;;
SETSIZ = 3L
;;
;; Define the two vector sets.
;;
v1 = [ [ 1.D0, 0.D0, 0.D0 ], $
[ 1.D0, 0.D0, 0.D0 ], $
[ 3.D0, 0.D0, 0.D0 ] ]
v2 = [ [ 1.D0, 0.D0, 0.D0 ], $
[ 0.D0, 1.D0, 0.D0 ], $
[-5.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_vsep( 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
Second vector : 1.0 0.0 0.0
Angular separation (rad): 0.0000000000
First vector : 1.0 0.0 0.0
Second vector : 0.0 1.0 0.0
Angular separation (rad): 1.5707963268
First vector : 3.0 0.0 0.0
Second vector : -5.0 0.0 0.0
Angular separation (rad): 3.1415926536
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_vsep/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_vsep may be calculated
by inverting the first expression given above as
cspice_vsep = 2.0 * arcsin ( length/2.0 )
This expression becomes increasingly unstable when cspice_vsep 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_vsep is given by
cspice_vsep = 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.
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.5, 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.4, 03-DEC-2009 (EDW)
Edited header, improved/clarified -I/O descriptions.
-Icy Version 1.0.3, 23-SEP-2008 (EDW)
Eliminated grammar error.
-Icy Version 1.0.2, 18-APR-2006 (EDW)
Expanded header comments.
-Icy Version 1.0.1, 09-DEC-2005 (EDW)
Added -Examples section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
angular separation of 3-dimensional vectors
|