Is there a function in MATLAB for detecting points inside a polyhedron?

156 views (last 30 days)
The INPOLYGON function in MATLAB detects points inside a polygonal region. I would like to determine whether a given three-dimensional point is inside a polyhedron.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 6 Jan 2012
The TSEARCHN and DELAUNAY functions in MATLAB can be used to detect whether a given three-dimensional point is inside a convex polyhedron for a small datasets. For example, consider the polyhedron defined by the vertices generated by the following commands:
n = 12; % Number of vertices
theta = 2*pi*rand(n,1)-pi; % Random theta
phi = pi*rand(n,1) - pi/2; % Random phi
x = cos(phi).*cos(theta); % Create x values
y = cos(phi).*sin(theta); % Create y values
z = sin(phi); % Create z values
The following commands determine if 20 randomly generated points within the unit square are also within the given polyhedron.
xyz = rand(3, n); % Generate random points
tri = delaunayn([x y z]); % Generate delaunay triangulization
tn = tsearchn([x y z], tri, xyz'); % Determine which triangle point is within
IsInside = ~isnan(tn) % Convert to logical vector

More Answers (2)

Thorey on 24 Feb 2014
Edited: Thorey on 24 Feb 2014
We have the same kind of problem, but our polyhedron is defined by the isosurface function. That is why we have a list of vertices and faces. We would like to either calculate the volume of the polyhedron defined by faces and vertices or detect which points are inside the polyhedron.
Unfortunately, the polyhedron is not necessarily convex.
  1 Comment
John Magradey
John Magradey on 31 Jul 2018
Did you ever find a resolution to this problem? I am in the exact same predicament as you are.

Sign in to comment.

KAE on 18 Feb 2020
You could use inpolyhedron from the FEX, discussed here.


Find more on Delaunay Triangulation 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!

Translated by