Separating axis in matlab

274 views Asked by At

I've been working on implementing separating axis algorithm in matlab. I've searched a lot but I didn't come up any solution. Could you point the mistake? Thanks in advance

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
0

There are 0 answers