1

Please check this image first

enter image description here

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.

Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
  • What you are using right now? Can you explain in details? – Abhishek Mishra Jun 29 '16 at 07:36
  • I am working on racing application in which user is logging all the GPS point with external GPS device and when he connect to that GPS device with my application then on mapview user is able to see all the travelled path now user can cut the travelled path from any where to mark the start line (Race Track) and based on start line i have to figure out how many laps user had travelled and other things. http://i.stack.imgur.com/H2znR.png In this image Blue line is user travelled path and white line is user Marked line So I need the Intersecting point coordinates between both the PolyLine. – Deepak Singh Jun 29 '16 at 08:32

1 Answers1

3

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;
}
rohit Sidpara
  • 547
  • 2
  • 14