1

These shapes are generated by tracing the sum of 2 vectors with different lengths rotating in opposite directions at different frequencies. I am trying to obtain these images using only fragment shaders, so I am unable to record each location of the sum as the vectors rotate.

spirograph 1 spirograph 2

Rotating vector function of $\theta$ (angle) and $\ell$ (length)

$$\theta = [0, 2\pi]$$

$$ \vec{R}\left(\theta, \ell\right)= \begin{bmatrix} \ell \cos{\theta} \\ \ell \sin{\theta} \end{bmatrix} $$

Two vectors rotating at different frequencies, $f$ $$ \vec{a} = \vec{R}\left(f\theta, 1\right) \quad f=1 $$ $$ \vec{b} = \vec{R}\left(f\theta, \frac{1}{2}\right) \quad f=-3 $$

The line is traced at $\vec{c}$ $$ \vec{c} = \vec{a} + \vec{b} $$

This process resembles figures produced by a Spirograph, which requires $\vec{c}$ to be recorded for every value of $\theta$.

One way to obtain these shapes with fragment shaders is to recycle the output of the buffer, tracing the shape over time. My goal is to be able to generate these shapes in parallel, without having to reuse any frame-buffers. I have been trying to find a method to compose a distance field that would produce a similar pattern, when intersected with a plane.

The function $f(x,y)=\sqrt{x^2 + y^2}$ plots the distance from $(x,y)$ to the origin. How may I find a function $f(x,y)$ which is the distance between $(x,y)$, and the nearest point that $\vec{c}$ may pass through?

If there is a better method to achieve this please let me know!

Iain
  • 189

1 Answers1

0

The sum of the two vectors is $$ \begin{bmatrix} \cos{\theta} \\ \sin{\theta} \end{bmatrix} + \begin{bmatrix} \frac{1}{2}\cos{-3\theta} \\ \frac{1}{2}\sin{-3\theta} \end{bmatrix} = \begin{bmatrix} \cos{\theta}+\frac{1}{2}\cos{-3\theta} \\ \cos{\theta}+\frac{1}{2} \sin{-3\theta} \end{bmatrix} $$

I used wolfram alpha to convert these two parametric equations to a Cartesian equation (I think thats what it is called).

$$ y = \pm\sqrt{-x^2 \pm\sqrt{x^2 (8 x + 9)} - 3 x} $$

Using some algebra and some help from wolfram (again)

$$ x^4 - 2 x^3 + 2 x^2 y^2 + 6 x y^2 + y^4 = 0 $$

Then to create my distance field, I exchange $z$ for $0$

$$ x^4 - 2 x^3 + 2 x^2 y^2 + 6 x y^2 + y^4 = z $$

therefore my distance field is

$$ f(x,y)=x^4 - 2 x^3 + 2 x^2 y^2 + 6 x y^2 + y^4 $$

Before this, I had no idea what parametric functions were, and I am still very unclear on how this works. Though I am really happy because I learned something, and I solved my problem!

Here is a more generalized method: Converting parametric equation to Cartesian

Iain
  • 189