1
votes

I am given a pivot point (by the integer coordinates) and a line that goes through that point and makes an x degree with the horizontal. The line makes a 360 degrees clockwise rotation around the pivot point with speed s= 0.001 degree per second. I am now given N points (with integer coordinates) and I have to sort these points in the order in which the line touches these points. How can i compute this? Thank you in advance.

2

2 Answers

3
votes

You need to do something equivalent to the following:

  1. Translate everything so that the pivot point is at the origin
  2. Convert each point to polar coordinates.
  3. Subtract x from each point's angle component, modulo 360 degrees (2pi radians).
  4. Sort the angle components in ascending order.
0
votes

Write the comparison function that takes two points and compare the angles they make with horizontal line.