Please check this image first
I have an array of lat long coordinates through which I created a MKPolyline
now I want to find the intersecting point coordinates lat long of two MKPolyline
.
For this I have tried MKPolyLine Intersects or not method but it only returns the bool value, not lat long coordinates. Also I have tried http://www.movable-type.co.uk/scripts/latlong.html to find out the mid point between 2 points but it's not working.
So can we find the exact intersecting point between two MKPolyline
.
Try This
CGFloat m1, c1, m2, c2;
CGFloat x11, y11, x12, y12; //line 1
CGFloat x21, y21, x22, y22; //line 2
CGFloat dx, dy;
CGFloat intersection_X, intersection_Y;
dx = x12 - x11;
dy = y12 - y11;
m1 = dy / dx;
c1 = y11 - m1 * x11;
dx = x22 - x21;
dy = y22 - y21;
m2 = dy / dx;
c2 = y22 - m2 * x22;
if( (m1 - m2) == 0)
{
NSLog(@"No Intersection between the lines");
}
else
{
intersection_X = (c2 - c1) / (m1 - m2);
intersection_Y = m1 * intersection_X + c1;
}