ios - How to check if CLCircularRegions intersect -
i'm developing ios app (with swift) keeps log of user's location history. part of search algorithm, i'd check if 2 clcircularregions
intersect, can't seem find core location method or function it. clcircularregion
has containscoordinate
method, that's not need. know map kit includes functions check intersecting mkmaprects
, since i'm not working maps, solutions don't seem ideal.
i hope i'm missing obvious, can't seem figure out. how can check if 2 clcircularregions
intersect?
if don't mind small inaccuracies, can assume regions small enough curvature of earth negligible therefore regions can treated planes.
in case, check whether distance of 2 center points smaller sum of radii. 2 circles intersect if , if centers closer sum of radii.
clcircularregion r1, r2; const double meanearthrad = 6371009; const double metersperdegree = 2 * m_pi * meanearthrad / 360; double dlat = r2.center.latitude - r1.center.latitude; double dlon = r2.center.longitude - r1.center.longitude; double actcenterdist = hypot(dlat, dlon) * metersperdegree; double mincenterdist = r1.radius + r2.radius; if (actcenterdist < mincenterdist) { // regions intersect }
Comments
Post a Comment