Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
November 24, 2021 03:06 pm GMT

Drawing with Mr. Fourier and Typescript

What if we connect a couple of rotating sticks together and trace the shape they make? We can get something like this.

Rotating Sticks

The most interesting part about this is if we get enough sticks we can draw anything we want!

You can try it yourself here. Just draw a closed (that's pretty important) shape and press 'Start'.

This is based on a thing caller Fourier Transform. Basically, every complex function on a set interval can be represented as an infinite sum of exponents:

f(t)=n=infinfcnen2it,0t1f(t) = \sum_{n=-\inf}^{\inf}c_n e^{n 2 \pi i t}, 0 \le t \le 1f(t)=n=infinfcnen2it,0t1

Where

cn=01f(t)en2itc_n = \int_0^1 f(t) e^{-n 2 \pi i t}cn=01f(t)en2it

But if we look closer we may notice that every element of that sum is actually a rotating vector Cn. So if we manage to represent a shape as a complex function, we could find these vectors (maybe not all, since there is infinite number of them, but we don't need all) and that would mean drawing the shape just by rotating those vectors!

I made a video where I tried to explain this in more detail and code it in TypeScript.

Enjoy!


Original Link: https://dev.to/nordicbeaver/drawing-with-mr-fourier-and-typescript-5h70

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To