What algorithm can I use to determine points within a semi-circle?

Posted by khayman218 on Stack Overflow See other posts from Stack Overflow or by khayman218
Published on 2009-02-11T00:50:01Z Indexed on 2010/05/08 0:48 UTC
Read the original article Hit count: 244

Filed under:
|
|

I have a list of two-dimensional points and I want to obtain which of them fall within a semi-circle.

Originally, the target shape was a rectangle aligned with the x and y axis. So the current algorithm sorts the pairs by their X coord and binary searches to the first one that could fall within the rectangle. Then it iterates over each point sequentially. It stops when it hits one that is beyond both the X and Y upper-bound of the target rectangle.

This does not work for a semi-circle as you cannot determine an effective upper/lower x and y bounds for it. The semi-circle can have any orientation.

Worst case, I will find the least value of a dimension (say x) in the semi-circle, binary search to the first point which is beyond it and then sequentially test the points until I get beyond the upper bound of that dimension. Basically testing an entire band's worth of points on the grid. The problem being this will end up checking many points which are not within the bounds.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about geometry