Optimizing Complex Fourier Tracing

Hello, I am working on a project that traces a looping bezier spline connected with piecewise equations with a definite complex fourier series that I hope to animate later. Right now I am struggling to get rid of the lag that occurs whenever I change the length of the series or edit a control point of the spline. The issue escalated after I switched from using sum-function based integration to integral-function based integration.

Sum based: (\sum_{n=0}^{b}\left(\left(\left(\left(\int_{0}^{b}\left(e^{\left(-1\right)^{n}\operatorname{round}\left(\frac{n}{2}\right)2\pi ki}Z\left(k\right)\right)dk\right)\right)\right)e^{\left(-1\right)^{n}\operatorname{round}\left(\frac{n}{2}\right)2\pi ti}\right))

vs.

Integral based:\sum_{n=0}^{b}\left(\left(\left(\left(\frac{\int_{0}^{b}\left(e^{\left(-1\right)^{n}\operatorname{round}\left(\frac{n}{2}\right)2\pi ki}G\left(8k\right)\right)dk}{b}\right)\right)\right)e^{\left(-1\right)^{n}\operatorname{round}\left(\frac{n}{2}\right)2\pi ti}\right)[1]

My three main plans for addressing this lag have been 1) go back to sum integration :weary_face:, 2) replace piecewise function for spline with some other one(?), or 3) find a way to define bezier spline designs in a separate graph and copy-paste them into the fourier rendering graph.

This is my current graph (will not be changed with progress for continuity). Any feedback or advice on the best path forward is greatly appreciated.

Fourier Tracing


  1. There is supposed to be a traced pattern here in orange

    (note the lack thereof) ↩︎

I am not familiar with the concept of Fourier approximations of Bezier curves.
I asked ChatGPT, here’s his answer, hope this helps:

this is a complex Fourier approximation of a closed Bézier path. The formula as posted is probably missing both a minus sign and the period scaling.

For a closed complex-valued path Z(k) of period b, the standard formula is

Combined:

Thus:

  • the exponent inside the integral has a minus sign;
  • the exponent outside has a plus sign;
  • both normally contain division by b;
  • H is the maximum Fourier frequency, not necessarily the length of the spline parameter interval.

Their indexing expression

(−1)nround⁡(n2)(-1)^n\operatorname{round}\left(\frac n2\right)(−1)nround(2n​)

just generates

0,−1,1,−2,2,…0,-1,1,-2,2,\ldots0,−1,1,−2,2,…

It is not necessary in Desmos. The frequency list can simply be


M=[-H,\ldots,H]

The order does not affect the final sum.

Why the integral version lags

Desmos must numerically evaluate

separately for every frequency m. When a control point changes, the entire function Z changes, so all 2H+1 adaptive numerical integrals must be recalculated.

This is especially expensive because:

  • Z is piecewise;
  • each piece is a Bézier polynomial;
  • there may be discontinuities in the piecewise definition or its derivatives;
  • numerical integration repeatedly samples the same spline;
  • increasing H adds another complete integral for every new frequency.

The important point is that switching from a sum to an integral did not merely change the notation: it replaced a fixed number of evaluations with many adaptive calculations.

Best Desmos approach: sampled Fourier coefficients

I would use a discrete approximation rather than Desmos’s integral operator. Choose a sample count N, for example N=256, and define

Then approximate each coefficient by

The reconstructed curve is

This is essentially a discrete Fourier transform. It is normally much faster and more predictable than nested numerical integrals.

The confirmation of the fallback option definitely helps (thank you very much), but it is still the fallback option. Maybe the issues in accuracy with discrete integration are my best bet? If that fails, I will return to trying to make a discrete approximation of the complex-valued bezier path.

Maybe I can break up the two parts using CL?

Well, yes, but the part with the integral will still lag …
I tried some variations but to no avail …