title: Implementation of Radial Sweep
body: <p>You have given N points in 2D plane ,i need to find out the smallest radius of a circle that contain at least  M points . </p>
  
  <p>Approach I am using :-</p>
  
  <p>I will do binary search on radius of circle . </p>
  
  <p>Pick an arbitrary point P from the given set. We rotate a circle C with radius R using P as the "axis of rotation" (by convention, in the counter-clockwise direction), i.e. we keep C to touch P any time during the rotation. While C is being rotated, we maintain a counter to count the number of points C encloses.</p>
  
  <p>Note that this counter only changes when some point Q enters (or leaves) the region of the circle C. Our goal is to come up with an algorithm that will increment (or decrement) this counter, whenever some other point Q ≠ P enters (or leaves) the region of C.</p>
  
  <p>The state of the (rotating) circle C can be described by a single parameter θθ, where (r,θ) are the polar coordinates of the center of the circle C, if we pick P as the fixed point of the polar coordinate system. With this system, rotating C means increasing θ.</p>
  
  <p>For each other point Q (≠ P), we can actually compute the range of θ  for which C covers Q. Put more formally, C encloses Q whenever (iff) θ∈[α,β].</p>
  
  <p>So, up to this point, the original problem has been reduced to:</p>
  
  <p>What is an optimal value of θ that lies in the most number of [α,β] intervals?</p>
  
  <p>The reduced problem can be solved with a pretty standard O(NlogN) algorithm.[3] This reduced problem has to be solved N times (one for each point P), hence the time complexity O(N2logN).</p>
  
  <p>I am able to get the how to do this step :</p>
  
  <p><strong>For each other point Q (≠ P), we can actually compute the range of θ  for which C covers Q. Put more formally, C encloses Q whenever (iff) θ∈[α,β].
  So, up to this point, the original problem has been reduced to:
  What is an optimal value of θ that lies in the most number of [α,β]intervals?</strong></p>
  
  <p>can you please suggest how to implement that part .</p>