Determine if 3d point belongs to polyhedron
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
John D'Errico
2023-12-26
编辑:John D'Errico
2023-12-26
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computational Geometry 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!