14

I was writing a simple program to help visualize inequalities based on 2 variables. The test inequality that I was using was this: $$\sin\left(0.1(x^2+y^2)\right)\geq0$$ Regions that satisfy the inequality are coloured in white.

Here's the result, for a bounding box of $(-25,-25),(25,25)$:

enter image description here

Now, I am aware that due to computational inefficiency and round-off errors, we might often get absurd and incorrect results while doing simulations. But the results, when I chose a bigger bounding box, were not what I expected.

For bounding boxes $(-50,-50),(50,50)$ (left) and $(-250,-250),(250,250)$ (right): enter image description here

I was expecting glitches, random patterns, maybe something like Moire patterns. But this regularized repeating behaviour (especially in the largest bounding box) seems too orderly to be a result of errors. While I am convinced that the first image is closest to the truth, but there is no way I can explain this "beauty in error".

All I can see:

  • Initial appearance of randomly located circular patches.
  • Circular patches get relocated to grid locations.
  • Cyclization between the previous two.
  • Overarching larger circles that encompass the smaller ones.

I am looking for ideas that might explain how this pattern might result from computational errors.

Zoom-out animation:

enter image description here

Edit:

Something really wonderful happens if I allow the zoom-out process to continue longer. The first (and the correct) pattern appears again, and the cycle starts anew:

enter image description here

As many have noted in the comments, aliasing might be the cause of these patterns. But as of yet, everywhere I have seen, aliasing is shown as a negative factor, something to be removed. But has any research been done on how it can result in such beautiful patterns?

Edit:

Apparently, aliasing can be used to make even prettier patterns. Here’s what happens if we sample at a less points (sparse sampling):

enter image description here

More of such beautiful icons here

Soham Saha
  • 2,356
  • 6
    Offhand, it seems Moire-ish, having some possible connection with aliasing. But it might be hard to understand the more distant effects that way. – Brian Tung Mar 04 '24 at 16:44
  • @BrianTung I think I can tweak aliasing effects during the rendering. Let me see... – Soham Saha Mar 04 '24 at 16:44
  • @BrianTung failed to do so. Could you elaborate how aliasing might lead to the pattern? – Soham Saha Mar 04 '24 at 16:48
  • Something similar happens when zooming out on this graph. Aliasing is talked about here and here partly – Тyma Gaidash Mar 04 '24 at 16:54
  • 2
    I can't answer your question. But do you mind if I save the images you have generated to use in my profile picture? – Enforce Mar 04 '24 at 16:58
  • 5
    The sin function here is a little bit of a red herring, and errors in the computation aren't the issue; rather, as others have noted, it's an issue of aliasing: the points where you're sampling your values at introduce a pattern of their own into the results. It's essentially a more complex version of the process at https://math.stackexchange.com/questions/1251466/what-is-this-pattern-called/1251501 . – Steven Stadnicki Mar 04 '24 at 18:04
  • 1
    @Enforce No I wouldn’t mind. (And sorry for the late reply) – Soham Saha Mar 05 '24 at 04:45
  • @TymaGaidash thanks for digging the links up. – Soham Saha Mar 05 '24 at 04:49
  • @StevenStadnicki thanks for your explanation. Also, though I really like these patterns, but is there some way to choose a better ‘sampling policy’ that reduces this aliasing artifacts? – Soham Saha Mar 05 '24 at 05:18
  • There are several! I would suggest a combination of supersampling (take more than one sample per pixel and average them) along with stochastic sampling (take those multiple samples randomly distributed within the pixel) and stratified sampling (choose each sample randomly within a single sub-pixel, or one per 'column', or similar). See https://www.pbr-book.org/3ed-2018/Sampling_and_Reconstruction/Stratified_Sampling and especially figure 7.18 there to see how this sampling works. – Steven Stadnicki Mar 05 '24 at 16:56
  • @StevenStadnicki Thanks a lot! I will surely try to use them in my project. – Soham Saha Mar 05 '24 at 17:08
  • 3
    One caution that may be worth noting: there's only so much that antialiasing can do for you. Especially in the wider zooms, you're certainly going well past the Nyquist Limit and best-case scenario you should expect wide swaths of essentially pure 50% gray on your graph. – Steven Stadnicki Mar 05 '24 at 19:19
  • @StevenStadnicki do you mean that in the wider zooms, the colour alteration is happening too many times in each pixel (those located further from the center), so all those pixels can hope to register (in the best case scenario) is gray? – Soham Saha Mar 06 '24 at 07:22
  • Also I just saw a really weird thing… at extremely large scales, the entire cyclic pattern starts from the beginning, starting with perfect concentric circles again. Has there been any research on the patterns that aliasing can produce? @StevenStadnicki – Soham Saha Mar 06 '24 at 07:25
  • @StevenStadnicki added an edit to show how the pattern starts again. – Soham Saha Mar 06 '24 at 07:54
  • @Enforce you might like this better — sampling at a sparser rate. – Soham Saha Mar 10 '24 at 16:59
  • 2
    @Enforce or take your pick from here – Soham Saha Mar 10 '24 at 17:15

1 Answers1

2

Its not an effect of rounding errors but of the simple fact, that discrete Fourier series of functions in a finite interval develop fake periodicty as interference of the discretization periodicity and function periodicty.

For a function period smaller than about 10 times the lattice constant, the eye groups the points of a fast oscillating function into groups by the distance in in the 2d-graphics.

On picture says more than 2^10 words

pts=Array[({#, Sin[3 # [Pi]/256] + Cos[126 # [Pi]/256]} &), {256}]]

ListPlot[pts] 

Point picture

ListPlot[pts, Joined -> True]

enter image description here

Roland F
  • 5,122
  • I won't lie; I didn't understand much about your answer. However, your approach seems similar to many explanations I found online regarding the aliasing effect. Am I right in thinking so? – Soham Saha Mar 06 '24 at 08:41