Solved

# Find the angle of a sector in a circle using the origin, radius, and two points.

Posted on 2009-04-28
1,300 Views
I managed to find a few examples for this, but I dont think they were exactly what I needed.

To make things worse I am a bit confused now as to which part of the circle starts at 0 radians. (Pretty sure its the east/right hand side rather than the north/top side of the circle).

Anyway, if you can imagine a point centered on the right-hand side of the circle, then moving clockwise from that point we will reach another given point on the circle.  This is the angle (in radians) that I am after.

So, given a single point, a radius, and an origin(although I dont think the origin matters) we want to find the angle between the right-hand point (at 0 radians) and the given single point which can be anywhere on the circle.

I thought that I could do this with some trignometry and triangles, but then I realised anything over pi radians changes the direction of the triangle.  I am looking for the clockwise angle between these two points, and I am pretty sure theres an equation for this, just havnt found one yet.

To simplify.

Given the Point P, the Radius R, and Origin O.  Find the clockwise angle between the righthand point X and the point P.

This is something I cant answer, but hopefully someone here can! Thanks :o)
0
Question by:recruitit

Author Comment

Just a note.

What I am doing here, is finding the base angles in radians of the 4 points of a rectangle.  If it was a square, then the base angle points are...

Top Left = pi * (5/4)
Top Right = pi * (7/4)
Bottom Left = pi * (3/4)
Bottom Right = (pi/4)

The reasoning behind this is basically if you can imagine a circle encasing the square/rectangle, I can find the points of the square/rectangle when I rotate the square/rectangle, by adding the rotation angle to the base angle and working out the points using the formula

x = Origin.X * (Radius * (Cos(Angle)))
y = Origin.Y * (Radius * (Sin(Angle)))

Then from those 4 points I can construct 4 lines which I can use to check for collision, and then perform Vector Reflection if a collision is made with the line.

I will probably end up making an object that can handle all square/rectangular objects, I just need to find the formula to calculate the base angles of the points on the square/rectangle.
0

LVL 84

Accepted Solution

atan2( (P-O) cross (X-O) , (P-O) dot (X-O) )
0

LVL 53

Assisted Solution

>> starts at 0 radians. (Pretty sure its the east/right hand side rather than the north/top side of the circle).

That's right. 0 angle is towards the right. Angles usually go counter-clockwise though, so, the up/north angle is 90 degrees (pi/2 in radians), and the down/south angle is -90 degrees (-pi/2 or 3pi/2 in radians).

>> Given the Point P, the Radius R, and Origin O.  Find the clockwise angle between the righthand point X and the point P.

If point P is given by (x,y) coordinates relative to point O, then :

angle = atan(y / x)

where atan is the arctangent.

And since you want the clockwise angle, you'll need to negate that :

angle = - atan(y / x)
0

LVL 53

Expert Comment

Make sure that you also account for the different quadrants. The 2nd and 3rd quadrants (ie. if x is negative) result in angles between pi/2 and 3pi/2.
0

LVL 53

Expert Comment

or you could just use atan2 like ozo suggested (way faster than me as usual), which does all of that for you.
0

Author Comment

Im going to feel a bit silly now im sure but, using this example...

Origin = (3,2)
Point P = (3,3)
Right-Hand Point = (4,2)

If I use atan(3/3) (Which is the top-most point of the circle, e.g. should be pi/2)
I get .7853981634

Was expecting 1.570796327.

And Ozo

atan2( (P-O) cross (X-O) , (P-O) dot (X-O) )

I assume your using vector math for P-O etc,   is that "," in the middle supposed to be the division?  or is that atan2(x,y) e,g atan2(y/x) ?

Thanks for the help guys
0

Author Comment

Er... Im starting to think I should probably know what atan2 is first before I make comments lol
0

Author Comment

Nevermind, I wiki'ed it, ignore my previous question ozo
0

Author Comment

atan2( (P-O) cross (X-O) , (P-O) dot (X-O) )

P-O = (0,1)
X-O = (1,0)

angle = atan2((0,1) cross (1,0), (0,1).(1,0))
(0,1).(1,0) = 0
(0,1) cross (1,0) = 0 * (1,0) + 1 * (1,0) = 1
angle = atan2(1,0)
Ok, just need to figure out how to calculate atan2 lol give me a sec
0

LVL 53

Expert Comment

>> If I use atan(3/3)

You need coordinates relative to the origin (ie. translate the origin and the whole coordinate system to (0, 0)). But I see you're already handling that by following ozo's advice :)
0

Author Comment

Ok seems atan2(y,x) = 2 arctan (y / (square root of (x^2+y^2) + x))

2 arctan (1 / ( (_/1) + 0)) = 1.570796327

Brilliant! Thanks guys!

0

Author Closing Comment

Perfect
0

Author Comment

Just a note for anyone coming across this solution.

The cross product in this case between two 2d vectors results in a scalar, and the formula is

A cross B = (AxBy) - (AyBx)
0

## Featured Post

### Suggested Solutions

Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
Have you ever thought of installing a power system that generates solar electricity to power your house? Some may say yes, while others may tell me no. But have you noticed that people around you are now considering installing such systems in their …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…