Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I am struggling with the following question. I'd like to check if a point on a circle is between two other points to check if the point is in the boundary. It is easy to calculate when the boundary doesn't go over 360 degrees. But when the boundary goes over 360 degrees (e.g. 270° - 180°), the second point is smaller than the first point of the boundary. And then I don't know how to check if my point on the circle is between the boundary points, because I cannot check "first boundary point" < "my point" < "second boundary point".

Is there an easy way to check this? Either a mathematical function or an algorithm would be good.

share|improve this question
2  
en.wikipedia.org/wiki/Midpoint_circle_algorithm –  user12205 Nov 21 '11 at 18:08
7  
You need to decide precisely what kind of "betweenness" you want to determine here. Is north between east and west? Does "between east and west" mean something different from "between west and east"? If so, then how about "between northeast and east" versus "between east and northeast"? If not, then does north suddenly cease to be between east and westish when the westish boundary moves slightly south of due west? –  Henning Makholm Nov 21 '11 at 18:10
    
I'm somewhat confused about what exactly you want. Are you looking for a function that will take in 3 points which are known to be on the circle, and classify one of them by its position relative to the other two? Is this in $\mathbb{R^2}$ or $\mathbb{R^3}$? Are they in rectangular or polar coordinates? –  user_123abc Nov 21 '11 at 19:07
1  
'the second point is smaller than the first point' ... what? –  leonbloy Nov 21 '11 at 19:29
1  
Hi. Wow, that's a lot of answers. I think it's easier when I say what I want to do with the function. I have a circle with a certain sector blocked. Say for example the sector between 90° and 180° is blocked (@Mike with increasing θ). I now want to check if a point on the circle is in this sector or not to see if it is a valid point or not. –  Dude Nov 22 '11 at 22:09
show 2 more comments

2 Answers

You should put all of the angles involved into canonical form before testing. For example, let angles $a, b$ be given (corresponding to the locations of your two sector-limiting points). Reduce $a, b$ to the range $(0, 2\pi)$ by modulo operations. Then if $b<a$ add $2\pi$ to $b$. For each test, let us say of angle $c$, reduce $c$ to the range $(0, 2\pi)$, getting $c'$; if $c' < a$, add $2\pi$ to $c'$ getting $c_t$, else set $c_t=c'$. Then $c$ is between $a$ and $b$ if $a \le c_t \le b$.

share|improve this answer
add comment

From the question comments with added symbols

I have a circle with a certain sector blocked. Say for example the sector between $a = 90°$ and $b = 180°$ is blocked. I now want to check if a point $P = (x,y)$ in the circle of center $C = (x_0,y_0)$ of radius $r$ is in this sector or not to see if it is a valid point or not.

In other words what you need is the angle the $PC$ line forms with the $x$ axis of your system of reference. And that's already been answered here:

$$v = \arccos\left(\frac{xx_0 + yy_0}{\sqrt{(x^2+y^2) \cdot (x_0^2+y_0^2)}}\right)$$

Notice that you still need to calculate the distance $\bar{PC}$ to make sure your point is in the circle to begin with.

share|improve this answer
    
Hmm. $\arccos$ takes values between -90 and +90 degrees, so I don't think this works. OTOH ATAN2 is designed to handle precisely this kind of questions. –  Jyrki Lahtonen Jan 22 '12 at 6:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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