pointLocation doesn't work for points on boundary edges.
조회 수: 2 (최근 30일)
이전 댓글 표시
pointLocation sometimes doesn't work for points on the boundary edge, but sometimes it does work. Is it a bug or am I missing anything? Code below:
TP= [0 0;1 0;0 0.55362;0.34043 0;0 1;0.32885 0.30133;0.24765 0.71525;0.21437 1;0.41137 0.54785;1 0.30028;1 0.52531;1 0.74369;1 1]
C=[7 3 5;7 8 5;6 3 7;6 9 7;11 10 6;11 9 6;1 3 6;1 4 6;4 6 10;4 2 10;11 9 7;11 12 7;12 7 8;12 13 8]
TR = triangulation(C,TP)
triplot(TR)
hold on
P=[0.3,1]
plot(P(:,1),P(:,2),'k*')
ID = pointLocation(TR,P) %output NaN
ID2 = pointLocation(TR,[0.301,1]) %output 14
댓글 수: 0
답변 (1개)
Divyam
2024년 8월 30일
편집: Divyam
2024년 9월 5일
This is a numerical precision issue which may arise because the point you have selected lies exactly on the edge or vertex of the triangle. Thus, the floating-point precision error is causing the "pointLocation" function to assert that the point is located outside the triangle.
To determine whether the point chosen lies on the edge, fetch the "Barycentric coordinates" using the "pointLocation" method. The points which lie on an edge have at least one "Barycentric coordinate" equal to "zero" while the ones which lie on a vertex have the "Barycentric coordinate" corresponding to that vertex equal to "one" and others equal to "zero".
TP = [0 0; 1 0; 0 0.55362; 0.34043 0; 0 1; 0.32885 0.30133; 0.24765 0.71525; 0.21437 1; 0.41137 0.54785; 1 0.30028; 1 0.52531; 1 0.74369; 1 1];
C = [7 3 5; 7 8 5; 6 3 7; 6 9 7; 11 10 6; 11 9 6; 1 3 6; 1 4 6; 4 6 10; 4 2 10; 11 9 7; 11 12 7; 12 7 8; 12 13 8];
TR = triangulation(C,TP);
P1 = [0.3, 1];
P2 = [0.301, 1];
[ID1, B1] = pointLocation(TR,P1);
[ID2, B2] = pointLocation(TR,P2);
% P1 lies on the edge of the triangle
B1
% P2 also lies on the edge of the triangle
B2
As you have correctly determined, adjusting the point location slightly may help your case as it will mitigate the precision error.
Another workaround to this issue is to code a tolerance-based approach which will solve the floating-point precision error by introducing a certain tolerance to the distances calculated for determining whether a point lies inside the triangle or not.
This issue has been fixed in MATLAB R2022b, you can download the latest version using this link: https://www.mathworks.com/downloads
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Triangulation Representation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!