Reputation: 5018
I have a pie chart which is drawn in HTML5 canvas .. I am retrieving the Point (X,Y) on mouse over .. Now i want to know whether the Point (X,Y) is in which slice of the pie chart ..
Note :
Known values :
Upvotes: 1
Views: 512
Reputation: 406
So, we know the angle where a slice starts. We know the center and point (x,y).
Let's assume the origin is (0,0) and we draw a line from there to point (x,y) . The angle between the x-axis and the line will be tan^-1(y/x)
.
Once we know the angle it's a simple calculation to see between which arc section it lies, since we know the start and ending angles of each slice.
If the origin is not (0,0) you can make it so with some simple math.
Upvotes: 1