pointLocation doesn't work for points on boundary edges.

2 visualizaciones (últimos 30 días)
John Grey
John Grey el 27 de Nov. de 2022
Editada: Divyam el 5 de Sept. de 2024
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

Respuestas (1)

Divyam
Divyam el 30 de Ag. de 2024
Editada: Divyam el 5 de Sept. de 2024
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
B1 = 1x3
-0.0000 0.1090 0.8910
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
% P2 also lies on the edge of the triangle
B2
B2 = 1x3
0.0000 0.1103 0.8897
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
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

Categorías

Más información sobre Triangulation Representation en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by