Re: the fastest way to find number of points in sphere(radius r) [message #46413 is a reply to message #46411] |
Tue, 22 November 2005 04:16   |
Xavier Llobet
Messages: 7 Registered: April 2005
|
Junior Member |
|
|
In article <1132659183.873193.230050@g44g2000cwa.googlegroups.com>,
"PYJ" <snfinder@naver.com> wrote:
> Data-------------------------------------------------------- ---------------
> lots of points: X, Y, Z
> lots of spheres: XC, YC, ZC (positions of center), R(radius)
> ------------------------------------------------------------ ------------------
>
> I want to know the number of galaxies inside each sphere without a
> loop.(If it is possible)
> The faster, the better!
>
> Help me, experts~~!!!
I have the nagging feeling of doing someone's homework...
A way to do what you want:
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)], 1, [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 than your method...
--
_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?
|
|
|