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

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)

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.

>> 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

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

0

recruititAuthor Commented:

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)
Radius = 1

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

recruititAuthor Commented:

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

0

recruititAuthor Commented:

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

0

recruititAuthor Commented:

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

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

recruititAuthor Commented:

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

recruititAuthor Commented:

Perfect

0

recruititAuthor Commented:

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

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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.