finding all points around a point in a cube

927 views Asked by At

Let's say I have list of points P0, P1, P2, P3 with coordinates X,Y,Z

Then I have a list of points with coordinates X1, Y1, Z1

I had to find all points inside a certain radius around P0: I did this using python scipy library using kdtree and query_ball_point function.

But now I'd like to find all points inside a cube. Points (P0 and P1) are not centered in the rectangle.

(Z)height of the rectangle is Z+4. (Y)The left side of P0 is +2 and right side of P0 is +1. To get X we need to calculate the distance between P0 and P1...

Any ideas?

I have good programming knowledge but my math and geometry skills are lacking.

1

There are 1 answers

0
Martin On

all you need to do is check all distnace conditions for every point in relation to your rectangle - in all dimensions x,y,z.

Lets say you have center of rectangle with coordinates cx,cy,cz

and you know that distance from X side is dX, from Y side is dY and from Z side is dZ.

the coordinates of your socalled center is cx,cy,cz

you can make loop

for point in all_points:
    px,py,pz = point # coordinates of a point which you try to examine

    if abs(cx-point[x]) < dX:
        if abs(cy-point[y]) < dY:
            if abs(cz-point[z]) < dZ:
                print('point is inside so called cube')


#abs(cx-point[x]) equals distance between your center and examined point in x-axis dimension...
#dX is distance between cube side and cx (center of cube in x-axis)

NOTE:

This example is good for cube with center in the middle. Since your center is not really in the middle, I advice you to find the center and do the above example

If you cant calculate center of your cube, you cant solve this problem anyway, so you better find the center.