[Math] How to calculate the angle of a slice of an ellipse

geometrytrigonometry

I'm attempting to draw a pie-chart programmatically, using an ellipse instead of a circle, but I'm having trouble calculating the correct angles for the slices. If it were a circle, I could use the percentage that the slice represents multiplied by $360$ degrees to obtain the accurate angles created by the slices.

Assume the following is known about an ellipse centered at the origin with a slice $s$:

  1. radii $a$ and $b$
  2. the percentage of the area that slice $s$ represents
  3. angle $\theta_1$, which is the angle from $0$ degrees to the beginning of the first edge of the slice (moving counter-clockwise).

How do you calculate the angle that slice $s$ creates from the center of the ellipse?

Note: Essentially, I would need to find either $\theta_2$ or the angle of the yellow-shaded slice depicted in this question:

enter image description here

Best Answer

The process given by Rahul Narain in the question you link to gives just what you want when inverted. Let $\theta_1$ and $\theta_2$ be as shown. He suggests scaling the ellipse vertically by a factor $\frac ab$ to make it a circle. If $p_1$ has coordinates $(p_{1x},p_{1y})$, its image $r_1$ will have coordinates $(p_{1x},\frac abp_{1y})$. Similarly, the image of $p_2$ will have coordinates $(p_{2x},\frac abp_{2y})$. The image of $\theta_1$ is then $\phi_1=\arctan \frac {ap_{1y}}{bp_{1x}}=\arctan [\frac ab \tan \theta_1$] and the image of $\theta_2$ is then $\phi_2=\arctan \frac {ap_{2y}}{bp_{2x}}=\arctan [\frac ab \tan \theta_2]$. You are asking that $\frac {\phi_2-\phi_1}{2\pi}=a$, the fraction of the circle the slice represents or $\phi_2=2a\pi+\phi_1$. So $\theta_2=\arctan [\frac ba \tan \phi_2]=2a\pi+\arctan [\frac ba \tan \phi_1]$

Related Question