Intersections just loops through all segments of curves and find all intersections
Many of segments have intersections, but intersection point has to be on these segments
Here are equations need to be solved to find intersection point
Try to find x,y and see if this solution has something in common with this
function u = D(x,y)
u = bsxfun(@minus,x(:,1:end-1),y).*bsxfun(@minus,x(:,2:end),y);
end