Determine if 3d point belongs to polyhedron
7 views (last 30 days)
Show older comments
I want to determine whether a 3d point belongs to a polyhedron. This polyhedron is a rectangular pyramid which extends out from the origin. I was thinking of doing by defining the normal to each side of the polyhedron and then taking the distance between each side and the point. But I'm kind of stuck what to do after that. I was thinking of this plus a combination of inequalities would lead me to an answer.
5 Comments
Accepted Answer
John D'Errico
on 26 Dec 2023
Edited: John D'Errico
on 26 Dec 2023
Since I'm going to show how to do it using a triangulation anyway, I might as well post it as an answer instead of a comment.
xyz = [0 0 0;1 0 0;0 1 0;1 1 0;.5 .5 1];
tri = delaunayTriangulation(xyz)
help pointLocation
Now we can use that tool to identify a point as inside or out.
pointLocation(tri,[.5 .5 .5;1 2 3])
If it returns a number, then the point lies inside the triangulation. And it even tells you in which simplex the point falls. Note that in the case of a point on the surface, it should return a true result, but sometimes floating point trash can be an issue. If the point lies outside the triangulation, then you will get a NaN. So the test can be most simply written as
~isnan(pointLocation(tri,[.5 .5 .5;1 2 3]))
True is inside, false is outside.
Could you use an alpha shape? Again, yes. But you need to tell it the value of alpha.
S = alphaShape(xyz,inf)
Alpha shapes have many nice capabilities.
methods(S)
One of them is plot.
plot(S)
But now you can also use the inShape tool to identify a point inside.
inShape(S,[.5 .5 .5;1 2 3])
Both approaches will suffice. An alpha shape does have one virtue, in that if the polyhedron is not convex, then it will still work, as long as you are able to choose an alpha that works. However, that can sometimes be problematic.
0 Comments
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!