comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Distances in 3D
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Distances in 3D [message #46003] Thu, 27 October 2005 12:17 Go to previous message
panblosky is currently offline  panblosky
Messages: 17
Registered: May 2005
Junior Member
Hi all,

probably this is a knwon question with a known solution, but I
haven't figure it out yet. I have points in 3D, and I want to calculate
the distances between them, but not the distance between the same
point. This is because I want to know the total sum of the inverse of
those distances. The first thing it came to my mind was to do it with a
for loop, but of course, for large number of points (which is the
case), takes for ever (basically a nxn operation). This is the code I
did (very simple, brutal way):

; xp,yp,zp are the positions

xold=xp
yold=yp
zold=zp

np=n_elements(xp)

dist=fltarr(np)

for i=0,np-1 do begin

xp[i]=0.
esc1=where(xp ne 0,cc1) ;removing the i-th particle
newxp=xp[esc1]

yp[i]=0.
esc2=where(yp ne 0,cc2)
newyp=yp[esc2]

zp[i]=0.
esc3=where(zp ne 0,cc3)
newzp=zp[esc3]


dist[i]=total(1./sqrt((newxp-xold(i))^2.+(newyp-yold(i))^2.+ (newzp-zold(i))^2.))

xp[i]=xold[i]
yp[i]=yold[i] ; restoring the i-th particle
zp[i]=zold[i]

endfor


Any idea of how to make this better? Thanks a lot!!

Andres
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: default plot window size in IDL 6.2
Next Topic: format integers with place separators

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:52:18 PDT 2025

Total time taken to generate the page: 0.00471 seconds