;+
; NAME:
;	V4localcart
; PURPOSE:
;	Generates a local-cartesian transformation matrix that goes between 
;	small offsets in one coordinate system to small offsets in another.
; CALLING SEQUENCE:
;	matrix = V4localcart(origin,from)
; INPUTS:
;	origin - a v4 structure indicating the origin
;	from - a string identifying the coordinate system to compare
; RETURNS:
;	matrix(i,j) tells you the offset of the jth coordinate in the
;	origin unit system per unit offset in the ith from-coordinate.
; METHOD:
;	Does the explicit transform on a (hopefully suitably small) 
;	simplex.
; WARNINGS:
;	THE NUMBERS IN THE MATRIX CARRY UNITS!  All units are assumed
;	to be the canonical units for that coordinate system (seconds 
;	for time-axis coordinates...)
; BUGS:
;	WE DO NOT IMPLEMENT RELATIVISTIC CORRECTIONS!!!  This would be
;	tedious.
;
;	We assume that 1e-3 is TINY.  This is not true for some unit
;	systems (eg megaradians)
;-
function v4localcart,origin,from,tiny=tiny
if(origin.(4) eq from) then return,[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]
or1 = v4canon(origin)
or2 = v4xform(origin,from)

if not isvalid(tiny) then tiny = double(1e-3)

;
; A 4-simplex would have five points; but we're only doing a 3-simplex.
;
simplex = replicate(or2,4)
for i=1,3 do simplex(i).(i) = simplex(i).(i)+tiny

sim2 = v4xform(simplex,origin.(4))
matrix = dblarr(4,4)
matrix(0,0) = 1
for i=1,3 do for j=1,3 do $
	matrix(i,j) = (sim2(i).(j)-sim2(0).(j)) / tiny

return,matrix
end