Prasath K
Prasath K

Reputation: 5018

Find particular slice of pie chart

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 :

  1. I have already found whether the Point(X,Y) is inside the pie chart or not

Known values :

  1. Center of Pie Chart (Cx,Cy)
  2. Start and End angle of each arc or slice
  3. Piechart radius (R)
  4. Start and End points of the arc or slice

Upvotes: 1

Views: 512

Answers (1)

pierdevara
pierdevara

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

Related Questions