1

my task is to find, and mark, all the points from a point cloud that are inside a 3D rectangle. I have the coordinates of all the 8 vertices. Is there a mathematical formula which I can use? To be precise, I'm working with python and all the points are inside a np array, so if someone knows a library that can do that, I'm open to suggestions. Thanks a lot.

User
  • 137
  • Assuming that $OA,OB,OC$ are three mutually orthogonal edges of the box, the points in the box are given by $xA+yB+zC$ with $x,y,z\in[0,1]$. – Jack D'Aurizio Sep 08 '18 at 16:23
  • So you mean O is a vertex and A, B, C are the 3 vertices reachable from O with for example A = [x1, y1, z1]. Multiplying the coordinates of one random point by these 3 vertices gives me a result that could be interpreted like inside/on the edge/outside? But I have to repeat it for all the 8 vertices? – User Sep 08 '18 at 16:35
  • (Assuming that the box's edges are aligned with the coordinate axes.) If the vertices are $(x_1,y_1,z_1),,(x_2,y_1,z_1),,(x_1,y_2,z_1),\cdots,,(x_2,y_2,z_2)$, then any point $(x,y,z)$ is inside the box if and only if $x_1<x<x_2$ and $y_1<y<y_2$ and $z_1<z<z_2$ . In other words, the point's coordinates are between the vertices' coordinates. – mr_e_man Sep 08 '18 at 16:36
  • No, they are not aligned with coordinate axes. This point cloud is coming from a street view and the boxes are around cars, so they are everywhere. – User Sep 08 '18 at 16:39
  • @User -- In Jack's comment, $x,y,z$ are not coordinates, but interpolation coefficients. A point inside the box is a weighted average of the vertices. – mr_e_man Sep 08 '18 at 16:39
  • Ok, now it's a bit clearer. But what is the relationship between one point and these x, y, z? How can I translate them in [0, 1]? – User Sep 08 '18 at 16:47
  • Do you know about the vector dot product? I'll use the notation $\vec{OA}=\vec A-\vec O$ for a difference of position vectors. A point $\vec p$ is inside the box if and only if $\vec O\cdot\vec{OA}<\vec p\cdot\vec{OA}<\vec A\cdot\vec{OA}$ , and $\vec O\cdot\vec{OB}<\vec p\cdot\vec{OB}<\vec B\cdot\vec{OB}$ , and $\vec O\cdot\vec{OC}<\vec p\cdot\vec{OC}<\vec C\cdot\vec{OC}$ . This generalizes my previous comment. – mr_e_man Sep 08 '18 at 16:58
  • Thank you! Now it's clear. – User Sep 08 '18 at 17:01
  • Equivalently, $\vec{Op}\cdot\vec{OA},;\vec{Op}\cdot\vec{OB},;\vec{Op}\cdot\vec{OC},;\vec{Ap}\cdot\vec{AO},;\vec{Bp}\cdot\vec{BO},;\vec{Cp}\cdot\vec{CO}$ are all positive numbers. – mr_e_man Sep 08 '18 at 17:02
  • Ok, that's faster. Thank you a lot – User Sep 08 '18 at 17:07
  • By “inside the box” do you want only points that are on the plane of the box (in which case you’ll need to make sure that the corners really are coplanar), or all points that are within the pyramid defined by the box and the origin? – amd Sep 08 '18 at 18:51
  • The box is made using also the information of the car, so length, width and height and all the corners are coplanar. – User Sep 09 '18 at 06:07
  • @mr_e_man can you write the answer in an answer box, so I can close this question? Thanks. – User Sep 10 '18 at 08:25

1 Answers1

1

(This only applies if the box's edges are aligned with the coordinate axes.)

If the vertices are $(x_1,y_1,z_1),\;(x_2,y_1,z_1),\;(x_1,y_2,z_1),\;\cdots,\;(x_2,y_2,z_2)$, then any point $(x,y,z)$ is inside the box if and only if

$$x_1<x<x_2$$ and $$y_1<y<y_2$$ and $$z_1<z<z_2$$

In other words, the point's coordinates are between the vertices' coordinates.


(This applies regardless of coordinates.)

I'll use the notation $\vec{OA}=\vec A-\vec O$ for a difference of position vectors. $O$ is one vertex, and $A,B,C$ are its three adjacent vertices.

A point $P$ is inside the box if and only if $$\vec O\cdot\vec{OA}<\vec P\cdot\vec{OA}<\vec A\cdot\vec{OA}$$ and $$\vec O\cdot\vec{OB}<\vec P\cdot\vec{OB}<\vec B\cdot\vec{OB}$$ and $$\vec O\cdot\vec{OC}<\vec P\cdot\vec{OC}<\vec C\cdot\vec{OC}$$

This generalizes the previous expression with coordinates.

Equivalently, $\vec{OP}\cdot\vec{OA},\;\vec{OP}\cdot\vec{OB},\;\vec{OP}\cdot\vec{OC},\;\vec{AP}\cdot\vec{AO},\;\vec{BP}\cdot\vec{BO},\;\vec{CP}\cdot\vec{CO}$ are all positive numbers.

mr_e_man
  • 5,364