[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


As far as I can tell from "f and g are unknown functions" and "Only know
g and f by some points in 3D space", it looks to me that you are trying
to find the closest points of two FLTARR(x, 3) arrays (or similar XYZ
description) in 3D coordinates. Will a simple method like this work for you?

; Make fake data that are not a line
x = findgen(1000)
x = [[x], [x], [x]]
x[*, 0] = x[*, 0]+20*sin(x[*, 0]*0.05)+randomu(seed, 1000)*10
x[*, 1] = x[*, 1]+25*sin(x[*, 0]*0.02)+randomu(seed, 1000)*5
x[*, 2] = x[*, 1]+28*sin(x[*, 0]*0.1)+randomu(seed, 1000)*20
y = x^1.5 * 0.75
; X and Y are the two curves A and B that you mention.
;Lets try to execute the following on them:

function test, x, y, min_delta=min_delta
start = systime(1)
min_delta = sqrt((x[0, 0] - y[0, 0])^2+(x[0, 1] - y[0, 1])^2+(x[0, 2] -
y[0, 2])^2)
loc = 0
for i=0, n_elements(x)/3-1 do begin
	delta_x = x[i, 0] - y[*, 0]
	delta_y = x[i, 1] - y[*, 1]
	delta_z = x[i, 2] - y[*, 2]
	delta = sqrt(delta_x^2+delta_y^2+delta_z^2)
	temp = min(delta, /nan)
	if temp le min_delta then begin
		min_delta = temp
		loc = i
print, "Finished in", systime(1)-start, ' s'
return, loc

IDL> print, test(x, y)
Finished in      0.61666667 s

Min_delta can be retrieved via keyword. The loop is slow, sorry. I am
sure one of the Pros would be able to speed it up with Histogram :-)
Hope this helps.

"Mark C." wrote:
> Given:
> a=f(x,y,z) and b=g(x,y,z), both a and b are separate curves. (Not straight
> lines. Nor do they loop over themselves). f and g are unknown functions.
> Only know g and f by some points in 3D space. Points are irregularly spaced.
> Objective:
> Find the minimum distance between a and b. Give the coordinate where this
> minimum occurs in term of the nearest point on a and the nearest point on b.
> Needs help:
> Does anyone have a routine to do such calculation using IDL? Any other
> suggestions appreciated.
> Thanks in advance,
> Mark Chan