俩矩形重叠面积的代码怎么求?
1个回答
展开全部
你是想求两个矩形目标区域的overlap吧?这边有个matlab代码,你稍稍改动一下就好了。。里面只用到了max,和min库函数:
function ratio = overlap(Rectan_A,Rectan_B)
x1 = Rectan_A(1);
y1 = Rectan_A(2);
width1 = Rectan_A(3);
height1 = Rectan_A(4);
x2 = Rectan_B(1);
y2 = Rectan_B(2);
width2 = Rectan_B(3);
height2 = Rectan_B(4);
startx = min(x1, x2); endx = max(x1+width1, x2+width2);
over_width = width1 + width2 - (endx - startx);
starty = min(y1, y2); endy = max(y1 + height1, y2 + height2);
over_height = height1+height2-(endy-starty);
if over_width< 3.0009e-04||over_height< 3.0009e-04
rario = 0;
else
Area_over = over_width*over_height;
Area1 = width1*height1;
Area2 = width2*height2;
ratio = Area_over/(Area1+Area2-Area_over);
end
function ratio = overlap(Rectan_A,Rectan_B)
x1 = Rectan_A(1);
y1 = Rectan_A(2);
width1 = Rectan_A(3);
height1 = Rectan_A(4);
x2 = Rectan_B(1);
y2 = Rectan_B(2);
width2 = Rectan_B(3);
height2 = Rectan_B(4);
startx = min(x1, x2); endx = max(x1+width1, x2+width2);
over_width = width1 + width2 - (endx - startx);
starty = min(y1, y2); endy = max(y1 + height1, y2 + height2);
over_height = height1+height2-(endy-starty);
if over_width< 3.0009e-04||over_height< 3.0009e-04
rario = 0;
else
Area_over = over_width*over_height;
Area1 = width1*height1;
Area2 = width2*height2;
ratio = Area_over/(Area1+Area2-Area_over);
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询