6
$\begingroup$

I don't know relevant keywords about this algorithm. I can show you visually Sort elements like circular pattern

Second image is result

Any ideas are appreciated

$\endgroup$
  • 3
    $\begingroup$ ("scan|sweep line" or "line|plane scan|scanning|sweep|sweeping" and "polar coordinates"?) Are you looking for terminology or algorithm? Tag accordingly! $\endgroup$ – greybeard Feb 25 at 9:11
  • 1
    $\begingroup$ Take a look at stackoverflow.com/questions/6989100/… $\endgroup$ – ciamej Feb 25 at 17:12
  • 1
    $\begingroup$ This reminds me of parts of the Jarvis March algorithm or Graham scan for convex hull calculation. Maybe these articles will give you some additional wording clues. $\endgroup$ – Nobody Feb 25 at 22:38
9
$\begingroup$

For each of your points in the field, calculate the red angle: enter image description here

Then sort all the (point, angle)-tuples by the angle.

| cite | improve this answer | |
$\endgroup$
2
$\begingroup$

Here's a way to sort points by angle in Swift:

let radarSortedPoints: [CGPoint] = points.sorted { pointA, pointB -> Bool in
    atan2(pointA.y, pointA.x) < atan2(pointB.y, pointB.x)
}
| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.