Numerical methods for estimating the circular area in Python

Dr. Huidae Cho
Institute for Environmental and Spatial Analysis...University of North Georgia

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

  1. $x$ (red),
  2. $x+dx$ (blue), or
  3. $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 that contains and to the D2L assignment folder.