MATLAB: Calculate percentage of similarities in two polygons

polygonsimilarity

Hello friends.
Is there any framework in Matlab that can calculate the percentage of similarities between two polygons?
If not, how can i implement one?
Googling i found out a formula to calculate the similarities of two polygons R and P2 using this formula:
But i don't know how to calculate the union and intersection polygons.
Any help please? 🙂
Thanks in advance!

Best Answer

If you have the Mapping Toolbox and want a more exact answer:
% Some example polygons
theta = linspace(0, 2*pi, 100);
x1 = cos(theta) - 0.5;
y1 = -sin(theta);
x2 = x1 + 1;
y2 = y1;
% Calculate
[xint, yint] = polybool('&', x1, y1, x2, y2);
[xun, yun] = polybool('|', x1, y1, x2, y2);
a1 = polyarea(xun, yun);
a2 = polyarea(xint, yint);
sim = 1 - (a1- a2)./a1;