Point in (skewed) circle sector

Started by
2 comments, last by Striken 15 years, 2 months ago
Hi all, I have two circles - one inside the other, and I need to and I'm trying to figure out which sector (of which circle) a given point is inside. The obvious easy scenario is when one circle is perfectly centered within another; but if the inner circle isn't centered, how do I find out what I want to know? The sector edges are (2pi / #sectors) on the circumference on the outer circle. Diagram to explain: Image Hosted by ImageShack.us<br/> Thanks - I'd very much appreciate any tips / pointers in the right direction!
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.
Advertisement
Off-the-top-of-my-head solution:

1. Run point-in-circle tests on the given point for both circles. This will tell you if the point is outside both circles, inside the larger circle but not the smaller circle, or inside both.

2. Construct hyperplanes corresponding to each of the 'spokes' that define the sectors. These will be lines in the form ax+by+d = 0. (Post back if you're not sure how to do this.)

3. Each consecutive pair of hyperplanes forms an unbounded triangle. For each of these triangles, test the point for inclusion by performing a 'which side' test against each of the two bounding hyperplanes.

You now have enough info to determine which circle and sector (if any) the point is in (assuming I didn't mess anything up).

Post back if you have any questions about this.
You can also use the CCW function to determine on which side of a spoke you are

From http://www.macs.hw.ac.uk/~alison/ds98/node114.html :
int ccw(point p1, point p2, point p3)// Slightly deficient function to determine if the two lines p1, p2 and// p2, p3 turn in counter clockwise direction}{  int dx1, dx2, dy1, dy2;  dx1 = p2.x - p1.x; dy1 = p2.y - p1.y;  dx2 = p3.x - p2.x; dy2 = p3.y - p2.y;  if(dy1*dx2 < dy2*dx1) return 1;  else return 0;}
Thanks for the ideas - I hadn't even thought about just performing a above/below plane test, that seems in theory to be the best way to tackle this.

Much appreciated :)
- Teach a programmer an answer, he can code for a day. Show a programmer the documentation, he can code for a lifetime.

This topic is closed to new replies.

Advertisement