Determine if 3d point belongs to polyhedron
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ekamresh
el 26 de Dic. de 2023
Editada: John D'Errico
el 26 de Dic. de 2023
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 comentarios
Respuesta aceptada
John D'Errico
el 26 de Dic. de 2023
Editada: John D'Errico
el 26 de Dic. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!