Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function crosses = crossesLine(xOld, yOld, x, y, xLine, yLine)
- p1=[xOld, yOld];
- q1 = [x,y];
- p2 = [xLine(1), yLine(1)];
- o1 = orientationMy(p1, q1, p2);
- o2 = orientationMy([xOld, yOld], [x,y], [xLine(2), yLine(2)]);
- o3 = orientationMy([xLine(1), yLine(1)], [xLine(2), yLine(2)], [xOld, yOld]);
- o4 = orientationMy([xLine(1), yLine(1)], [xLine(2), yLine(2)], [x, y]);
- crosses = 0;
- if (o1 ~= o2)
- if(o3 ~= o4)
- crosses = 1;
- end;
- end;
- return;
- end
- function ret = orientationMy(p,q,r)
- val = (q(2) - p(2)) * (r(1) - q(1)) - (q(1) - p(1)) * (r(2) - q(2));
- if val == 0
- ret = 0; %coliner
- else
- if val > 0
- ret = 1; %clockwise
- else
- ret = 2; %coutnerclockwise
- end;
- end;
- return;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement