James Robb

Posted on

# Approximating PI

In this coding challenge we are going to try to approximate the value of PI using random number generation, Geometry and Cartesian Coordinates.

We will begin with an explainer of what the goal and solution path will be and from there we will visualise the output using p5.js.

## The challenge

Given a random set of points on a 2D plane, estimate the value of PI.

This is not such an easy challenge to wrap your head around at first because how can you even begin to approximate PI with nothing more than some randomly generated points and a 2D plane? On the face of it, that would be like saying "Go to the shop and buy some milk and then use it to fly to the moon".

Nevertheless this challenge is what we will be tackling today by breaking it down and piecing a solution back together. As usual we will begin the implementation with some tests.

## Tests

For the tests I will be using the Jest testing framework. If you have never used Jest before then I highly recommend you check it out. With that said, our tests are written as follows:

expect.extend({