is_cross.m

来自「best routing protocol」· M 代码 · 共 35 行

M
35
字号
function res =is_cross(pt1, pt2, pt3, pt4)%check if line (pt1->pt2) and line (pt3->pt4) is acrossres=0;if pt3(1)==pt4(1) %horizontal line  x=pt3(1);  if (pt1(1)>=x) & (pt2(1)>=x) %above the h-line	return  elseif (pt1(1)<=x) & (pt2(1)<=x) % below the h-line	return  end  b=(x-pt1(1))/(pt2(1)-pt1(1));  cross_pt_y = pt1(2)+(pt2(2)-pt1(2))*b;  if cross_pt_y>min(pt3(2),pt4(2)) & cross_pt_y<max(pt3(2),pt4(2))	res=1;  end	elseif pt3(2)==pt4(2) % vertical line  y=pt3(2);  if (pt1(2)>=y) & (pt2(2)>=y) % right to the v-line	return  elseif (pt1(2)<=y) & (pt2(2)<=y) % left to the v-line	return  end  b=(y-pt1(2))/(pt2(2)-pt1(2));  cross_pt_x = pt1(1)+(pt2(1)-pt1(1))*b;  if cross_pt_x>min(pt3(1),pt4(1)) & cross_pt_x<max(pt3(1), pt4(1))	res = 1;  endelse  error(['unsupported line cross computation--pt3->pt4 must be either' ...		 ' horizontal or vertical']);end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?