0
$\begingroup$

I am trying to draw llamas with the discrete Fourier transform on sample complex points of an SVG image of a llama. In my Javascript code (using the p5js. library) I sample points from the SVG and then take the DFT of those points and sum them by $$p(t)=\sum_{n=0}^{\#samples}{C_ne^{iFt}}$$ where $F$ is the frequency corresponding to the fourier coefficient $C_n$.

I then graph a plot of the parametric form of the complex numbers $$x(t)=\text{Re}(p(t))\\y(t)=\text{Im}(p(t))$$

My javascript code works (supposedly) fine. I get the following llama as output: Javascript drawn Llama

However, converting the code into Mathematica produces this mess: If this is a llama, it's certainly not alive

I even tried exporting the same coefficients from my Javascript into Mathematica, and verified that inputs to my Parametric form are the same as the ones of Javascript. Is there some hidden piece I'm missing with regards to how ParametricPlot works in Mathematica?

For reference, here's how the javascript code is working: https://gist.github.com/adekau/59d2935d3b52bffa61be37539fa2202f

And here's my mathematica code (which is importing the same sample points and coefficients that the javascript uses/procudes): https://gist.github.com/adekau/007e669b09ceb0081782ec1c21cb4ac2

The following json files are needed to be imported (pts.json and coeffs.json): https://gist.github.com/adekau/674d0ebb3cefed835e1f779a1dbd33a1

Also, it seems to work fine in mathematica if I follow the same code as How can I draw a Homer with epicycloids? and use $m = 2n + 1, n\in\mathbb{N}$ and do the DFT over the range $[-m, m]$ instead of using only positive-valued frequencies. I don't know if this matters or not, but it seems like it works fine with positive-valued frequencies only in the javascript version.

$\endgroup$
  • $\begingroup$ What’s the shape of your final output which gives this result? $\endgroup$ – CA Trevillian Mar 29 at 19:04
  • $\begingroup$ I suppose I'm not entirely sure what you mean. If I take the parametric plot in Mathematica over a small interval like {t, 0, 1/100 pi} then I see a spiral shape $\endgroup$ – Alex D Mar 29 at 20:11
  • $\begingroup$ Ah I can see how you would read the question that way. What I meant was, the shape of your data that you plot, what is it? I was not asking about what it plots, but what is the shape of your data, once you run all of the code, prior to plotting it? Also, see what the plot looks like without the lines connecting the points? $\endgroup$ – CA Trevillian Mar 29 at 20:16
  • $\begingroup$ The data is a list of length 2 tuples, like so: {{1, -115.416 + 73.4052 I}, {2, 40.8509 + 5.57138 I}, {3, 14.8001 + 0.139403 I},...} Also, I just changed ParametricPlot to Plot and I now see a bunch of Sine waves. However, evaluating the function at some $t\in [0,2Pi]$ seems to give an answer I expect it to... imgur.com/3xjjA0u $\endgroup$ – Alex D Mar 29 at 20:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.