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

Home » Public Forums » archive » Re: Positions in 3-d
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: Positions in 3-d [message #43802] Mon, 02 May 2005 10:38 Go to previous message
K. Bowman is currently offline  K. Bowman
Messages: 330
Registered: May 2000
Senior Member
In article <1115049911.382768.8960@o13g2000cwo.googlegroups.com>,
panblosky@gmail.com wrote:

> Thanks for your help Ken. It didn't occur to me to use histogram...
> But now I have another question: using histogram (and
> reverse_indices) tells me in which bin the x (or y or z) coordinate
> would be (and how many x-points are in the bin), but how do I know
> where the point (x,y,z) lies? I mean, if my cube goes from 0 to 1, and
> I have 4 bins (it could be more) in each dimension (so I would have 64
> sub-cubes in 3-D), how can I tell, in a fast way, in which sub-cube
> does the point (x,y,z) lies and how many points are in that sub-cube?
> Maybe there is an easy answer, but I haven't been able to do it...
> Thanks,
>
> Pablo


Assume you have a 3-D space that you divide into a regular grid of nx x ny x nz
boxes. The coordinates of the space range from [xmin, xmax], [ymin, ymax],
[zmin, zmax]. The box sizes for each dimension are dx = (xmax - xmin)/(nx -1),
...

You have N points with coordinates (x, y, z), and you want to know within which
box each point lies.

For the x-dimension, for example, the index of the grid box containing a point is

i = LONG(dx*(x - xmin))
j = LONG(dy*(y - ymin))
k = LONG(dz*(z - zmin))

The trick is to index the 3-D grid of boxes with a 1-D index:

m = i + (j*nx) + (k*nx*ny)

The index m ranges from 0 to (nx*ny*nz)-1. Use HISTOGRAM and REVERSE_INDICES on
the array of m's (BINSIZE = 1, MIN = 0, NBINS = nx*ny*nz). There will be one m
for each point. Histogram will tell you how many points in each box, and
reverse indices tells you which points.

You can use the ARRAY_INDICES function to convert from m back to (i, j, k).

Ken Bowman
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Data Structure in IDL
Next Topic: Re: Looping over parameters without EXECUTE()

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

Current Time: Wed Oct 08 13:04:18 PDT 2025

Total time taken to generate the page: 0.00596 seconds