Length of a Circle: Iterative Numerical Approximation (Ver.1)

The equation of a general circle centered at the point

$$ c = (c_x, c_y)$

with radious $$ r$ is

$$ (x-c_x)^2+(y-c_y)^2 = r^2 $$

it is known that its length is $$ L = 2\pi r $$. We want to approach the actual length by an increasing value of the inscrived polygon length.

Contents

Automatic point generation

Now we'll generate the appropriate number of points using polar coordinates

$$ x = r \cos(\theta); y=r \sin(\theta); $$

where $$\theta \in [0,2\pi]$

( Hint : see at the end of this page)

radious = 1;
numPoints = 8;
points = generatePolygonPoints(radious, numPoints)
[m,n] = size(points)
points =

    1.0000         0
    0.7071    0.7071
    0.0000    1.0000
   -0.7071    0.7071
   -1.0000    0.0000
   -0.7071   -0.7071
   -0.0000   -1.0000
    0.7071   -0.7071


m =

     8


n =

     2

m rows (number of points) and n columns (number of coordinates)

Now we compute the length of the closed curve associated to this polygon

Build also a funtion that returns the length of this polygon

clength = curveLength(points,m)
clength =

    6.1229

Finally the error obtained by the present approximation is:

actualLength = 2*pi*radious;
absError = abs(clength-actualLength);
relError = absError/actualLength;
[absError,relError]
ans =

    0.1603    0.0255

Write the following function file and named it as generatePolygonPoints

$$ \texttt{ function pts = generatePolygonPoints(r, numP) }$

$$ \texttt{   ang=0; }$

$$ \texttt{   pasAng=2*pi/numP; }$

$$ \texttt{   for i = 1:numP }$

$$ \texttt{      x(i) = r*cos(ang); }$

$$ \texttt{      y(i) = r*sin(ang); }$

$$ \texttt{      ang=ang+pasAng; }$

$$ \texttt{   end }$

$$ \texttt{   pts=[x',y']; }$

(c) Numerical Factory 2017