Numerical methods for estimating the circular area in Python
1 Circle equation
\[x^2+y^2=r^2\] where $r$ is the radius.
Rewriting the above equation yields \[y=\pm\sqrt{r^2-x^2}.\]
2 Sweeping algorithm
The basic idea is to split a circle with a radius of $r$ into multiple rectangles with the same base width $dx$ by sweeping a vertical line starting from the left-most point on the circumference at $(-r, 0)$ along the $x$-axis towards the right-most point on the circumference at $(r, 0)$.
There are three ways to calculate the height of each rectangle. Take two points at the current sweeping point $x$ and the next $x+dx$ which compose the width of the current rectangle. We can calculate its height at
- $x$ (red),
- $x+dx$ (blue), or
- $x+0.5\,dx$ (magenta).
We will see how these different approaches work.
2.1 $n=1$
2.2 $n=2$
2.3 $n=4$
2.4 $n=10$
2.5 $n=100$
2.6 $n=1000$
3 Homework: A biased numerical method for estimating the circular area
Please implement the for and while versions of method 2 (rectangular height at $x+dx$). Submit FirstLastname_circ_area.zip
that contains circ_area_for.py
and circ_area_while.py
to the D2L assignment folder.