On plotting frac(x^2+y^2) as complex and implicit plot

88 views
Skip to first unread message

Georgi Guninski

unread,
Feb 25, 2025, 8:00:42 AM2/25/25
to sage-...@googlegroups.com
I am looking for both theoretical and technical answer for the following plots.

Define f(x,y)=frac(x^2+y^2)

When I complex plot x+I*y to f(x,y) as colormap, the result depends on
the plotted rectangle.
In the rectangle $0 < x,y <14$ I see many circles of different sizes.
In the rectangle $8 < x < 12, 4 <y <6$ I don't see any circles, only lines.

When I do implicit plot of $f(x,y)=0.5$ I see similar results in the
big and the small rectangles.

Question: Is there fractal-like structure of any of the plots or is
it just coincidence?

Attaching sage session
fracx2y2.sage.txt
frac_0..14,pp=400.png

Emmanuel Charpentier

unread,
Feb 26, 2025, 7:33:26 AM2/26/25
to sage-devel

I think that the shapes you perceive are moiré patterns, depending on the resolution of your plot, the resolution of your screen and the region you plot.

To understand it, start with a plot of \operatorname{frac}\left(x^2\right),as done here, which is a “cut” of your function on any straight line including (0, 0). Even at “high” resolution, the moiré appears at about x=7.

This effect is better illustrated by an implicit plot : at default resolution, you see sharp (and irregular) patterns, which disappear at higher resolution (as done here).

The same is true for a plot3d (here) and for your complex_plot (see here) : in all these cases, strong moiré patterns observed at default resolution disappear (oe ar severely modified) at high resolution.

HTH,

Georgi Guninski

unread,
Feb 26, 2025, 11:14:34 AM2/26/25
to sage-...@googlegroups.com
Thanks for the plots.
Are you sure that the example with implicit_plot and plot_points=800
doesn't have patterns?
I suspect that precision issues (float?) together with small "pixel"
size incorrectly kill the pattern.

implicit_plot(lambda u, v:frac(u^2+v^2)-0.5, (13, 14), (13, 14),
plot_points=800)
shows lines, not sure if this is correct.
I think if you increase the number of points you must zoom in,
decreasing the size of the region.

Travis Scrimshaw

unread,
Feb 27, 2025, 8:05:49 PM2/27/25
to sage-devel
I concur that it is just a moiré pattern and issues from sampling. Once you get sufficiently far from the origin, the interval of r for frac(r^2) = (0,1) gets very small (in fact, very quickly). Contrast this with

f(x,y) = frac(sqrt(x^2+y^2))

It comes down to the sampling being done to make the 2d image.

Best,
Travis
Reply all
Reply to author
Forward
0 new messages