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

Home » Public Forums » archive » Re: the fastest way to find number of points in sphere(radius r)
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: the fastest way to find number of points in sphere(radius r) [message #46414 is a reply to message #46413] Tue, 22 November 2005 04:02 Go to previous messageGo to previous message
Xavier Llobet is currently offline  Xavier Llobet
Messages: 7
Registered: April 2005
Junior Member
In article <1132647395.741577.324420@z14g2000cwz.googlegroups.com>,
"PYJ" <snfinder@naver.com> wrote:

> Dear all,
>
> First of all, my data is three-dimensional set.
> I have to use a loop because I have a lot of positions of centers of
> spheres that I should examine.
> I want to find the # of points inside each sphere.
> Now, I use a where function in order to find points inside the cube,
> then I compute distances of all. Next, I use where function again to
> examine # of distances less than radius of sphere.
> I think it is fairly slow when large data is considered.
>
> Is there any faster way?
> The fastest way to find the number of points in sphere(radius r)
>
> ------------------------------------
> data:
> positions of points: X, Y, Z
> centers of spheres: XC, YC, ZC
> radius of spheres: r
> ------------------------------------
>
> Help me~

A way:

ix=indgen(n_elements(X)) ; index array to be used in BLAS_AXPY
t=transpose([[X], [Y], [Z]]) ; array(3,n) of cartesian coordinates

;Loop over spheres' centers:
t1=t ; temporary array

; Shift points' coordinates to the j-th sphere's center
blas_axpy, t1, -1, [XC(j), YC(j), ZC(j)], [0,0], 2, ix

; Convert to spherical coordinates (long, lat, radius)
sph = cv_coord(from_rect=t1, /TO_SPHERE)

; So sph(2,*) is the array of distances.
; Histogram it, or treat as you please.

;end_loop


It could be faster...

--
_xavier
--
Only one "o" in my e-mail address
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: image display with different pixel size in x & y
Next Topic: Re: 3d space set up and plotting data on maps

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

Current Time: Sat Oct 18 04:46:28 PDT 2025

Total time taken to generate the page: 0.72202 seconds