Draw part of circle and fill it based on percent

365 Views Asked by At

enter image description here

I need a mathematical algorithm to draw a part of a circle, and fill it ( draw another, smaller part of a circle inside it ) based on a number (percent) from 1 to 100. At the 2. circle the percent is 0, while at 1. its about 30.

Ime certain this can be done with math, but ime beyond stuck :(

1

There are 1 best solutions below

1
On

Let $r$ be the radius of the inner circle and $R$ be the radius of the outer circle.

Let $t\in [0,100]$ be the percentage you're given.

Then the area you want is obtained with a circle of radius $u$, where $$ \dfrac{u^2-r^2}{R^2-r^2}=\dfrac{t}{100} $$ So, you need to solve this equation for $u$.

This equation follows from the expression of the area of a circular sector of radius $u$ and angle $\theta$: $$ \text{area}=\dfrac{\theta}{2\pi} \pi u^2 $$