# Detect sectors of a circle

## Recommended Posts

So, circles are confounding me today... About twenty years ago I did GCSE maths and remember wondering when or why I would ever need to know any of this stuff about circles and angles and the like.
Now. Now is when I need to know all that stuff.

So I've been all over the interwebz and have learned lots about circles, but while there are myriad explainations of how to work out the length of an arc, the angle and area of a sector... and use both radians and degrees to calculate same; I can find nothing that will tell me which sector a given value (theta, radian, degree, whatever) is in.

If I've divided my circle into 12 segments, can I pass a value and know that it belongs in sector 3, for instance?

##### Share on other sites

I've made the changes directly to the last example you shared. You can find the code to detect a segment in the create tab.
http://phaser.io/sandbox/zDpiEpoY

The steps are:
Ensure the rotation value you have exists in a 0<->X range, and not a -Y<->Y range.
Divide that number by the size of each segment in rads or degrees, and then round the number down to get the segment index.

##### Share on other sites

Brilliant, that's just what I was after (and seems simple now it's laid out for me...)

Thanks once again!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.