Table of contents
CSPICE_VZEROG indicates whether an n-dimensional vector is the zero
vector.
Given:
v any double precision vector of arbitrary dimension.
help, v
DOUBLE = Array[N]
the call:
vzerog = cspice_vzerog( v )
returns:
vzerog the value True if and only if `v' is the zero vector.
help, vzerog
BOOLEAN = Scalar
None.
Any numerical results shown for these examples may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Given a set of n-dimensional vectors, check which ones are
the zero vector.
Example code begins here.
PRO vzerog_ex1
;;
;; Local parameters.
;;
SETSIZ = 2L
;;
;; Define the vector set.
;;
v = [[0.D0, 0.D0, 0.D0, 2.D-7], [0.D0, 0.D0, 0.D0, 0.D0]]
;;
;; Check each n-dimensional vector within the set.
;;
for i=0L, SETSIZ-1L do begin
;;
;; Check if the I'th vector is the zero vector.
;;
print
print, format='(A,4F11.7)', 'Input vector: ', v[*,i]
if ( cspice_vzerog( v[*,i] ) ) then begin
print, format='(A)', ' The zero vector.'
endif else begin
print, format='(A)', ' Not all elements of the vector' + $
' are zero.'
endelse
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Input vector: 0.0000000 0.0000000 0.0000000 0.0000002
Not all elements of the vector are zero.
Input vector: 0.0000000 0.0000000 0.0000000 0.0000000
The zero vector.
2) Define a unit quaternion and confirm that it is non-zero
before converting it to a rotation matrix.
Example code begins here.
PRO vzerog_ex2
;;
;; Define a unit quaternion.
;;
s = sqrt( 2.D0 ) / 2.D0
q = [ s, 0.D0, 0.d0, -s ]
print, format='(A,4F12.7)', 'Quaternion :', q
;;
;; Confirm that it is non-zero and
;;
if ( cspice_vzerog( q ) ) then begin
print, ' Quaternion is the zero vector.'
endif else begin
;;
;; Confirm q satisfies ||q|| = 1.
;;
print, format='(A,F12.7)', 'Norm :', cspice_vnormg( q )
;;
;; Convert the quaternion to a matrix form.
;;
cspice_q2m, q, m
print, format='(A)', 'Matrix form:'
print, format='(3F12.7)', m
endelse
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Quaternion : 0.7071068 0.0000000 0.0000000 -0.7071068
Norm : 1.0000000
Matrix form:
0.0000000 1.0000000 0.0000000
-1.0000000 0.0000000 -0.0000000
-0.0000000 0.0000000 1.0000000
This function has the same truth value as the logical expression
( cspice_vnormg( v ) eq 0.d0 )
Replacing the above expression by
cspice_vzerog ( v )
has several advantages: the latter expresses the test more
clearly, looks better, and doesn't go through the work of scaling,
squaring, taking a square root, and re-scaling (all of which
cspice_vnormg must do) just to find out that a vector is non-zero.
A related function is cspice_vzero, which accepts three-dimensional
vectors.
1) If the input argument `v' is undefined, an error is signaled
by the IDL error handling system.
2) If the input argument `v' 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.
None.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.2, 10-AUG-2021 (JDR)
Edited the header to comply with NAIF standard. Added complete
code examples.
Added -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.1, 09-DEC-2005 (EDW)
Added -Examples section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
test whether an n-dimensional vector is the zero vector
|