pointLocation return only one ID if a point lies in more than one triangle

조회 수: 4 (최근 30일)
Matteo Nicoletta
Matteo Nicoletta 2022년 3월 10일
편집: VINAYAK LUHA 2023년 9월 27일
Hi everyone,
this is my code in which I've two triangles and one point and I want to check in which triangle my point lies (I've to use pointLocation for more complex case like a mesh of STL file).
clear all
points=[0 0;1 0; 0 1; 1 1];
tri=[1 2 3; 1 2 4];
TR=triangulation(tri,points);
triplot(TR);
check=[0.6 0.2];
hold on
plot(check(1,1),check(1,2),'o');
ID = pointLocation(TR,check);
I'd like to be returned both the ID of the triangles in which the point lies. How can I do?

답변 (1개)

VINAYAK LUHA
VINAYAK LUHA 2023년 9월 27일
편집: VINAYAK LUHA 2023년 9월 27일
Hi Matteo,
I understand that you want to find the IDs of all triangles which enclose a point.The “pointLocation” function returns the triangle ID of only the first enclosing triangle as defined in the “Triangulation connectivity”.
To get triangleIDs of all the enclosing triangles, you can do a linear search over all the triangles and register the ones which enclose the given point.
The code snippet to achieve this can be seen below:
points = [0 0; 1 0; 0 1; 1 1];
tri = [1 2 3; 1 2 4];
check = [0.6 0.2];
plot(check(1,1), check(1,2), 'o');
hold on
enclosingTriangleIDs = [];
for i = 1:size(tri, 1)
TR = triangulation(tri(i,:), points);
ID = pointLocation(TR, check);
if ~isnan(ID)
enclosingTriangleIDs = [enclosingTriangleIDs, i];
end
triplot(TR);
end
disp("IDs of triangles enclosing the point:");
disp(enclosingTriangleIDs);
hold off
To learn more about “traingulation” and “pointLocation”, you may refer to the MathWorks documentation links below:
  1. https://in.mathworks.com/help/matlab/ref/triangulation.html
  2. https://in.mathworks.com/help/matlab/ref/triangulation.pointlocation.html
Hope this helps.
Regards,
Vinayak Luha

카테고리

Help CenterFile Exchange에서 Delaunay Triangulation에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by