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

1 回表示 (過去 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 Center および File ExchangeSTL (STereoLithography) についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by