Table of contents
CSPICE_VHATG finds the unit vector along a double precision vector of
arbitrary dimension.
Given:
v1 any double precision vector of arbitrary dimension.
help, v1
DOUBLE = Array[N]
the call:
cspice_vhatg, v1, vout
returns:
vout the unit vector in the direction of `v1':
v1
vout = --------
||v1||
If `v1' represents the zero vector, then `vout' will also be
the zero vector.
help, vout
DOUBLE = Array[N]
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 a set of n-dimensional vectors and find the unit vector
along each of them.
Example code begins here.
PRO vhatg_ex1
;;
;; Local parameters.
;;
SETSIZ = 2L
;;
;; Define the vector set.
;;
v1 = [ [ 5.D0, 12.D0, 0.D0, 0.D0 ], $
[ 1.D-7, 2.D-7, 2.D-7, 0.D0 ] ]
;;
;; Calculate the unit vectors.
;;
for i=0L, SETSIZ-1L do begin
cspice_vhatg, v1[*,i], vout
print, format='(A,4F12.7)', 'Input vector: ', v1[*,i]
print, format='(A,4F12.7)', 'Unit vector : ', vout
print
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Input vector: 5.0000000 12.0000000 0.0000000 0.0000000
Unit vector : 0.3846154 0.9230769 0.0000000 0.0000000
Input vector: 0.0000001 0.0000002 0.0000002 0.0000000
Unit vector : 0.3333333 0.6666667 0.6666667 0.0000000
cspice_vhatg determines the magnitude of `v1' and then divides each
component of `v1' by the magnitude. This process is highly stable
over the whole range of multi-dimensional vectors.
This routine will detect if `v1' the zero vector, and will not
attempt to divide by zero.
The IDL native code to perform this operation:
vout = vin/norm(vin)
The IDL version also accepts arbitrary N-vectors.
1) If the input argument `v1' is undefined, an error is signaled
by the IDL error handling system.
2) If the input argument `v1' 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 output argument `vout' is not a named variable, an
error is signaled by the Icy interface.
None.
1) The relative number of cases whereby floating point overflow
may occur is negligible. Thus, no error recovery or reporting
scheme is incorporated into this routine.
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 example.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections, and
completed -Particulars section. Moved the existing contents of -Examples
section to -Particulars.
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, 09-DEC-2005 (EDW)
Added -Examples section.
-Icy Version 1.0.1, 10-OCT-2005 (EDW)
Corrected notation |vin| to ||vin||
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
unitize a n-dimensional vector
|