diff --git a/zUtil_Maths/gtMathsIsPointInPolyhedron.m b/zUtil_Maths/gtMathsIsPointInPolyhedron.m index a15da256f85d6ba5d533541913ffc18bb178238f..68622a1d6ec3c48159d44fe983377f6a06fb1212 100755 --- a/zUtil_Maths/gtMathsIsPointInPolyhedron.m +++ b/zUtil_Maths/gtMathsIsPointInPolyhedron.m @@ -1,16 +1,18 @@ +function ok = gtMathsIsPointInPolyhedron(p, faces) +% GTMATHSISPOINTINPOLYHEDRON Tells if the given point is inside the defined 3D +% polyhedron. % -% FUNCTION ok = gtMathsIsPointInPolyhedron(p,faces) +% ok = gtMathsIsPointInPolyhedron(p, faces) % -% Tells if the given point is inside the defined 3D polyhedron. -% -% INPUT: p(1x3) - [X,Y,Z] coordinates of the point -% faces(nx6) - coordinates of the facet planes of the polyhedron -% [p0x p0y p0z pnormx pnormy pnormz] -% pnorm vectors point out of the volume -% -% OUTPUT: ok - true if the point is inside the polyhedron +% INPUT: p(mx3) - [X,Y,Z] coordinates of the point +% faces(nx6) - coordinates of the facet planes of the polyhedron +% [p0x p0y p0z pnormx pnormy pnormz] +% pnorm vectors point out of the volume % +% OUTPUT: ok - true if the point is inside the polyhedron + + aa = (p(ones(size(faces, 1), 1), :) - faces(:, 1:3)) .* faces(:, 4:6); -function ok = gtMathsIsPointInPolyhedron(p,faces) + ok = all(sum(aa, 2) <= 1e-12); -ok = all(sum((repmat(p,size(faces,1),1)-faces(:,1:3)).*faces(:,4:6),2) <= 1e-12); +end