;+
; NAME:
; cross
;
;
; PURPOSE:
; compute the cross product of two vectors
;
;
; CATEGORY:
; vector
;
;
; INPUTS:
; a: first vector (3d)
; b: second vector (3d)
;
;
; OUTPUTS:
; cross product in component form
;
;
; RESTRICTIONS:
; only works for 3d vectors
;
;
;
; MODIFICATION HISTORY:
;
; Tue Jan 22 17:57:45 2008, Brian Larsen
;
; documented, written much earlier
;
;-
FUNCTION cross, a, b
IF n_elements(a) NE 3 OR n_elements(b) NE 3 THEN BEGIN
print, 'Cross products are only defined in 3 dimensions'
return, [!VALUES.F_NAN, !VALUES.F_NAN, !VALUES.F_NAN ]
ENDIF
x = dblarr(3)
x[0] = a[1]*b[2] - b[1]*a[2]
x[1] = a[2]*b[0] - b[2]*a[0]
x[2] = a[0]*b[1] - b[0]*a[1]
return, x
END