Find all 3D points inside a cube(3D Box) - c++11

I'm trying to find out the 3D points of a point cloud which are inside a 3D Box. I'm able to get the points inside 3D box by the below logic, only when the 3d box is align with the axis, but on rotating the 3d box, the logic fails.
(This only applies if the box's edges are aligned with the coordinate axes.)
If the vertices are (x1,y1,z1),(x2,y1,z1),(x1,y2,z1),⋯,(x2,y2,z2), then any point (x,y,z) is inside the box if and only if
x1<x<x2
and
y1<y<y2
and
z1<z<z2
In other words, the point's coordinates are between the vertices' coordinates.
Now I got algo from https://math.stackexchange.com/questions/2909812/points-inside-a-3d-rectangle?noredirect=1&lq=1 but not able to figure out how to take the "position vectors".
Any suggestions!!
Another issue: Is there any fast way to find out all the points inside a 3D box, rather than iterating over the whole point cloud.
Any suggestion is appreciated!!!

Since you listed point-cloud-library in the question's tags, pcl::CropBox is probably what you are looking for. You basically provide the two corner points, a translation and a rotation, after that, you can extract all points inside the box.

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.
O,A,B,C in there are vertices of cuboid. Being a parallelepiped, cube can defined by three adjacent faces, that's four points in total.

Related

Convert simple isometric image to 3D

I'm curious how one would deduce 3D coordinates in simple isometric images.
The only approach I could come up with is to do depth-first searches to find the vertices of each face and then use complex branching logic to figure out the vertex position from all the possibilities there are for how faces can be partially hidden. What would be a better approach to go about this?
This is just for hobby, so I'm fine with simplifying the problem further (say by requiring the scene to be composed of only unit voxels or by giving the solution only as coordinates of the midpoints of individual voxels instead of giving the coordinates and their face indices in counter-clockwise order).
I'd assume the input to be given as a matrix of the five different colors I use in the picture. As output I'd expect a list of 3D coordinates, possibly accompanied by a list of coordinate indices for the faces.
I assume that you are able to detect all edges and their direction (among six possilbe). Also if they are complete or occluded. And detect the vertices, so that you get a 2D graph.
Assign the coordinates (0, 0, 0) to some point, such as the lowest vertex. Then following every complete edge from the already known points, you will obtain the coordinates of the endpoints by considering the edge direction (and possibly length) and you will know which coordinate to increment/decrement.
In the end, you will get all coordinates of the endpoints of the complete edges, tell the complete faces, and be able to tell the occluded faces.

Getting the boundary of a hole in a 3d plane

I have a set of 3d points that lie in a plane. Somewhere on the plane, there will be a hole (which is represented by the lack of points), as in this picture:
I am trying to find the contour of this hole. Other solutions out there involve finding convex/concave hulls but those apply to the outer boundaries, rather than an inner one.
Is there an algorithm that does this?
If you know the plane (which you could determine by PCA), you can project all points into this plane and continue with the 2D coordinates. Thus, your problem reduces to finding boundary points in a 2D data set.
Your data looks as if it might be uniformly sampled (independently per axis). Then, a very simple check might be sufficient: Calculate the centroid of the - let's say 30 - nearest neighbors of a point. If the centroid is very far away from the original point, you are very likely on a boundary.
A second approach might be recording the directions in which you have neighbors. I.e. keep something like a bit field for the discretized directions (e.g. angles in 10° steps, which will give you 36 entries). Then, for every neighbor, calculate its direction and mark that direction, including a few of the adjacent directions, as occupied. E.g. if your neighbor is in the direction of 27.4°, you could mark the direction bits 1, 2, and 3 as occupied. This additional surrounding space will influence how fine-grained the result will be. You might also want to make it depend on the distance of the neighbor (i.e. treat the neighbors as circles and find the angular range that is spanned by the circle). Finally, check if all directions are occupied. If not, you are on a boundary.
Alpha shapes can give you both the inner and outer boundaries.
convert to 2D by projecting the points onto your plane
see related QA dealing with this:
C++ plane interpolation from a set of points
find holes in 2D point set
simply apply this related QA:
Finding holes in 2d point sets?
project found holes back to 3D
again see the link in #1
Sorry for almost link only answer but booth links are here on SO/SE and deals exactly with your issue when combined. I was struggling first to flag your question as duplicate and leave this in a comment but this is more readable.

Point of intersection between Oriented Boxes (or OBB)

I am trying to write a Rigid body simulator, and during simulation, I am not only interested in finding whether two objects collide or not, but also the point as well as normal of collision. I have found lots of resources which actually says whether two OBB are colliding or not using separating axis theorem. Also I am interested in 3D representation of OBB. Now, if I know the axis with minimum overlap region for two colliding OBB, is there any way to find the point of collision and normal of collision? Also, there are two major cases of collision, first, point-face and second edge-edge.
I tried to google this problem, but almost every solution is only detecting collision with true or false.
Kindly somebody help!
Look at the scene in the direction of the motion (in other terms, apply a change of coordinates such that this direction becomes vertical, and drop the altitude). You get a 2D figure.
Considering the faces of the two boxes that face each other, you will see two hexagons each split in three parallelograms.
Then
Detect the intersections between the edges in 2D. From the section ratios along the edges, you can determine the actual z distances.
For all vertices, determine the face they fall on in the other box; and from the 3D equations, the piercing point of the viewing line into the face plane, hence the distance. (Repeat this for the vertices of A and B.)
Comparing the distances will tell you which collision happens first and give you the coordinates of the first meeting point (in the transformed system, the back to absolute coordinates).
The point-in-face problem is easy to implement as the facesare convex polygons.

minimal bounding box of a clipped point cloud

I am trying to find the minimal bounding box of a 2d point cloud, where only a part of the point cloud is visible.
Given a point cloud with a rough rectangular shape, clipped so that only one corner is visible:
The point cloud is clipped at the green border. I know the position of the border in the image, and I know that there will always be exactly one corner of the rectangular shape visible within this border. I also know the size of the rectangular shape.
Now I want to find the minimal bounding box that contains all the points of this shape, even those not visible on-screen. Since I know the dimensions of the box, finding the two sides visible is enough to determine the other two.
(there are actually two possible solutions, since width and height of the shape can be swapped, but let's ignore that for the moment)
I want to find the red box.
I do not need an exact solution, or a fast one. My current attempt uses a simple brute force algorithm that rotates the point cloud in 1° steps and finds the axis-aligned bounding box.
I just need a criterion that tells me which rotation is the best one for this case. Minimal-Area is the usual criterion for a minimal bounding box, but that obviously only works if all points are visible.
There is probably some optimal algorithm involving convex hulls, but I'd rather keep the solution as simple as possible
All you really need is the positions of the corners of the intersection between your red and green rectangle. Assuming the points are a decent approximation of the border, this should be a reasonably reliable method to get those:
Pick the two points A and B most distant from eachother. Those are two corners of the area of intersection.
Find the points C and D with the greatest perpendicular distance from the line AB (example) on either side. Those are another two corners of the area intersection.
A, B, C & D are some combination of corners of the red rectangle and intersections between the green and the red rectangles. To work out which are which, just check which are within some small tolerance of the green rectangle's border. And with that, you've got enough information to easily work out the position of the red rectangle.

Intersection Algorithm between 3D Polygon and A Cube

I need a quick algorithm to check whether a 3D Polygon (a list of 3D coordinates that are co-planar, given a list of points in counter-clockwise or clockwise order, the polygon can be convex or concave, in other words, it must be simple polygons non-intersecting itself) and a cube(given the lower-left and top-right coordinates, the cube edges align with the X/Y/Z axis) intersects.
Is there any quick way to do this? thanks.. I've google for a few pages, but not yet found something exactly the same.
Many thanks..
EDIT
Sorry, when I said 'Box', I meant 'Cube'.
A cube is defined as two corner points. lower-left and top-right (or the other pair, doesn't matter).
Check for polygon-polygon intersection between your polygon and each side of the box.
Check if any of the polygon's points are inside the box.
Here are some tests that should work
Check if 1 or more of the polygon points inside the box, but not all of them.
Check if any of the polygon's edges intersect with the edges of the box.
Check if any of the polygon's faces intersect with the faces of the box.
If any of the above hold then they intersect. All area listed as it's probably worth the trouble to test them in order as extracting the faces and calculating if they intersect may not be do able in linear time.

Resources