Drawing shapes with maths

View with the Desmos Graphing Calculator

In school we learn how to draw circles:

```
x^2 + y^2 - r^2 = 0
where r is the circle radius
```

What if we want to draw lots of circles though? We can use a modulus function in the x and y axes to repeat values within a bounding box. This is kind of like folding space to get an infinite number of circles!

```
x_repeat = mod(x, width)
y_repeat = mod(y, height)
width = height = 2 * r
```

We also need to translate the circle into the repeating bounding box:

```
offset = -r
```

Boolean operations can be used to combine different shape functions:

```
union(f1, f2) = min(f1,f2)
intersection(f1, f2) = max(f1,f2)
difference(f1) = -(f1)
```

Combining this all we can draw patterns! Here's a repeating fish scale pattern:

```
circle_main = (x_repeat + offset)^2 + (y_repeat + offset)^2 - r)
circle_left = (x_repeat)^2 + (y_repeat)^2 - r
circle_right = (x_repeat + offset * 2)^2 + (y_repeat)^2 - r
pattern = max( circle_main , - min ( circle_left , circle_right ) )
```

See an interactive version on desmos, an amazing graph website!

In University my tutor introduced me to Hyperfun and Frep Frep or function representation is the idea of drawing (multidimensional) shapes with mathematics and Hyperfun is a high level programming language that helps you do the draw these shapes.

< previous next >