GaryS

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


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.