News for hackers. Stuff that matters.
Re:My Fourier Epicycles by encypruon on Sunday August 23, 2020 @05:53PM (#24255593)
Shameless plug: A friend of mine and I made a game[1] for a jam that works the other way around. The goal is to manually fiddle with the coefficients to recreate a given shape.

It gives an easy way to play with the coefficients and hopefully allows the player to gain some intuitions. For example how some combinations of frequencies lead to rotational symmetry and why negative frequencies are necessary.

It's not very polished, though. I made a mistake while writing the algorithm that checks whether the shape is matching. It causes some false negatives in certain situations. There might also be some issues with dragging the controls on Mac OS.

[1] https://coldiv.itch.io/fouriershaper

Re:My Fourier Epicycles by bargle0 on Sunday August 23, 2020 @02:12PM (#24253930)
It would be cool to have a slider or something to hide cycles, starting with the highest frequency. Basically, a way to visualize lossy compression.
Re:My Fourier Epicycles by fnord77 on Sunday August 23, 2020 @07:25PM (#24256164)
I tried to stump it with this SVG. I didn't expect it to really work, but it failed fairly spectacularly

https://upload.wikimedia.org/wikipedia/en/a/a4/Flag_of_the_U...

Re:My Fourier Epicycles by loa_in_ on Sunday August 23, 2020 @01:49PM (#24253744)
Why does it use two sets of vectors?

One sum of vectors is enough to trace any continuous line.

Re:My Fourier Epicycles by lordnacho on Sunday August 23, 2020 @07:01PM (#24256013)
Here's a hypnotic version with one sum:

https://youtu.be/-qgreAUpPwM

Re:My Fourier Epicycles by hinkley on Sunday August 23, 2020 @05:31PM (#24255447)
Perhaps so the animations are outside of the drawing area?
Re:My Fourier Epicycles by golem14 on Monday August 24, 2020 @12:50AM (#24257593)
And I would guess you get fewer artifacts - the version linked in a sibling comment with just one end has a lot of factors and yet is not very accurate.
Re:My Fourier Epicycles by falseprofit on Sunday August 23, 2020 @03:53PM (#24254762)
Yeah, this is pretty annoying. Starting with a function from the circle to the complex plane, the Fourier series decomposes it into a sum of exponentials, which are circular motions about 0. This version with x and y coordinates separated overcomplicates and confuses. And with a four-dimensional output, there are 2 unused dimensions whose values are arbitrary.
Re:My Fourier Epicycles by physicles on Sunday August 23, 2020 @09:42PM (#24256857)
I wonder if this means the problem is under-determined (too many degrees of freedom) and that leads to numerical instability. Certainly one set of equations is enough, as 3Blue1Brown’s Fourier transform video shows.
Re:My Fourier Epicycles by hardmath123 on Sunday August 23, 2020 @09:19PM (#24256769)
I implemented such a version in Scratch back in 2016! https://scratch.mit.edu/projects/117304786/

Here’s a gif of that if the project player doesn’t work for you: https://github.com/kach/gifblocks/blob/master/gallery/fourie...

Re:My Fourier Epicycles by lurquer on Monday August 24, 2020 @02:05PM (#24263466)
Brilliant demonstration!

As you undoubtedly know, there is nothing essential about using sin waves with Fourier stuff... it can work with any shaped curve. A cool modification would be use a combination of the users input to generate a circle instead of the other way around. That is, if I draw a square, a multitude of squares of different sizes and phases, each tracing their contour, will generate the X,Y values for a circle.

Re:My Fourier Epicycles by ndr on Sunday August 23, 2020 @03:01PM (#24254362)
This is fun but I think it's a bit buggy.

Trying to draw lines parallel and close to more than one border generates a lot of nonsense. Try with a square almost as big as the canvas.

Re:My Fourier Epicycles by ladberg on Sunday August 23, 2020 @07:58PM (#24256347)
Same thing happens when I try (emphasis on try, it wasn't that good) to draw a circle, which should be the easiest shape.
Re:My Fourier Epicycles by cgufus on Monday August 24, 2020 @02:33AM (#24258023)
As I understand a "time series" is created for both x und y coordinates, then these are fourier transformed for the spectral components. Then when redrawing, only the real parts are used.

Is it necessary to do it for x and y separated? Couldn't you just take x for the real part and y for the imaginary part of the time series and do the Fourier transform on that?

edit: monday morning typos.

Re:My Fourier Epicycles by bldavies on Monday August 24, 2020 @12:58AM (#24257625)
For those interested, I explain some of the math involved in computing epicycles from sample data here: http://bldavies.com/blog/computing-epicycles/
Re:My Fourier Epicycles by NiceWayToDoIT on Monday August 24, 2020 @12:56AM (#24257613)
Nice one, despite understanding inner workings all I can think of is the song title "A Kind of Magic"
Re:My Fourier Epicycles by m3kw9 on Sunday August 23, 2020 @08:06PM (#24256392)
Could this be a way to compress vectors?
Re:My Fourier Epicycles by vladTheInhaler on Sunday August 23, 2020 @08:27PM (#24256518)
Depending on what you mean by vectors, yes. I don't know how it, if at all, it would apply to svg files, but you can absolutely take a vector and take its Fourier transform, and only keep the first few components to get a compressed representation. That is one way to do image compression.
Re:My Fourier Epicycles by hinoki on Sunday August 23, 2020 @08:22PM (#24256491)
My (poor) understanding of existing compression techniques is that you have to know what frequencies are OK to discard, otherwise the amount of information remains the same. For things like mp3 or jpg, this depends a lot on human perception of sound and images.
Re:My Fourier Epicycles by cgufus on Monday August 24, 2020 @02:39AM (#24258043)
I fear that by dropping high frequency components, the result becomes visually unappealing (such as lines being parallel in the original becoming extremely wiggly and non-parallel).

Maybe OP can make an example with high frequencies removed?

Re:My Fourier Epicycles by gus_massa on Sunday August 23, 2020 @08:39AM (#24251480)
The second pass makes the line darker. Is it on purpose or just a numeric error?
Re:My Fourier Epicycles by ReactiveJelly on Sunday August 23, 2020 @04:54PM (#24255215)
It may also be a result of the canvas drawing anti-aliased lines. Since an anti-aliased line contains some partially transparent pixels, drawing exactly the same line a second time will darken those pixels.