Skip to content

C++ program using OpenGL to execute a discrete fourier transform on a set of datapoints and regraph it using epicycles derived from the DFT.

Notifications You must be signed in to change notification settings

chrwoods/fourier-grapher

Repository files navigation

A grapher built in C++ that converts vector images into an animation that uses a fourier transform to draw it using epicycles.

Currently this program uses manually inputted datapoints in .txt files in the data/ directory. Writing a program to parse actual vector images into usable data is a whole other project unto itself, so we just read in manual datapoints for now. However, the client and math behind the fourier transformation is fully functional! It contains a bunch of options, allowing the user to control the depth (number of circles), speed and scale of the animation, plus the ability to change the colors of the background, the circles, the lines that revolve inside the circle to hold the next, and the overall line that the rotation builds. There are also buttons to reset the time, and to clear the graph.

The math behind this is somewhat complex, but I can give a quick run-down. First, it takes a vector image as a large set of points, which is currently thirty points in a line. It then plots each point as a complex number, with the x representing the real, and the y representing the imaginary component. It then completes a Discrete Fourier Transform on this dataset, which finds waves with increasing frequency that, added together, make the original dataset. Namely, it will make twice as many waves as there are datapoints, so in our case we will make sixty waves, from a frequency of one wave over an interval from 0 to 2 * pi, to thirty waves over that same interval. From this wave we are able to calculate our amplitude and phase shift, which we use to plot our circles. We plot our first circle in the center-ish of the screen, with the radius represented by our amplitude, and the line in the center begins at an angle determined by the phase shift. The position in the circle that our line points to determines where the center of the next circle is placed. This system of graphing, with circles hinged on other circles, is epicycles. Once these circles all make the interval from 0 to 2 pi, the cycle repeats, and the original graph should be recreated. This regraphs our test data in this example, which in this case is a diagonal line. Our test data is found f

Building this is done by simply calling 'make', however these graphics libraries do have to be installed first. For installing on a Debian Linux system (i.e. Ubuntu), I'm almost certain that calling "sudo apt-get install libglfw3-dev mesa-common-dev" will install OpenGL and GLFW3, which are the bindings I used for my graphics library, Dear ImGui, which is self-contained in this package. If this doesn't work, try replacing 'libglfw3-dev' with 'libglfw-dev'. Personally I installed a lot of packages, so those might have had a factor in it too.

However, if you're on Slackware it isn't as simple as just calling good old apt-get install. Instead, you must install the SlackBuild for glfw3 from https://slackbuilds.org/repository/14.2/libraries/glfw3/. This means you have to download the slackbuild, download the source tarball, give yourself execute permission on the .SlackBuild file, run it, and then go into whereever it puts the .tgz file (usually /tmp/), and run installpkg on it. However, this is the only SlackBuild you need to install for this program to work, and more detailed instructions are on the slackbuilds.org website. I know for a fact this should work, since I ran it on a fresh install of a Slackware VM and my program was able to run.

Once the building is done, just call ./fourier_grapher, and you should be good to go!

!!IMPORTANT NOTE!!: The window defaults to being pretty small, if you drag the bottom-right corner you'll be able to see the entire animation, but if you don't it'll look like I just wrote a few sliders and called it a day.

More to come in the future, thanks to my Theory of Linear Algebra professor, Dr Roettger, for helping me piece together how to use fourier transforms in the context of epicycle graphing, github.com/ocornut for having ImGui ready to use, and thanks to me for spending way too much time piecing together how to use ImGui from its meager documentation.

About

C++ program using OpenGL to execute a discrete fourier transform on a set of datapoints and regraph it using epicycles derived from the DFT.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published