我一直致力于在matlab中实现分离轴算法。我搜索了很多,但我没有提出任何解决方案。你能指出错误吗? 提前致谢
function flag = intersection(P1,P2)
%P1 and P2 are x,y coordinates of triangles and 3x2 matrix
%a normal line of an edge of P1
dx = P1(2,1)-P1(1,1);
dy = P1(2,2)-P1(1,2);
normal(1,:)=[-dy dx];
%same procedure for P2..
%getting the projection
P1_proj = dot(P1(1,:),normal(1,:))/dot(normal(1,:),normal(1,:))*normal(1,:);
%same procedure for P2..
xmin_P1 = min(P1_proj(:,1));
xmax_P1 = max(P1_proj(:,1));
%same procedure for P2..
if((xmin_P1>xmax_P2)||(xmin_P2>xmax_P1))
flag = false;
return;
end
flag=true;
end