Implicit plotter

Plotting solutions of implicit functions f(x,y) = 0 is not trivial. Yet, it is the most general way of plotting things, since all functions y = g(x) can be written in the implicit form f(x,y) = g(x) - y = 0.

Try typing any function f(x,y) into the text input above and it will plot f(x,y) = 0. If you wanted to plot g(x,y) = h(x,y), just type in g(x,y) - h(x,y) since the equal sign is not supported. Any JavaScript function of variables x, y would work, even Boolean-valued ones (such as inequalities). Common functions such as sin, cos, tan, exp, pow, min, max, abs, log, atan, asin, acos, atan2 are supported. The pipe | is interpreted as absolute value. For better speed, do exponentiation using pow instead of ^. Please note that this uses Function in JavaScript, meaning that whatever you type into that text input will be executed as JavaScript on your browser, so be careful not to paste suspicious code into it.

1 Implementation details

I implemented this recursive subdivision implicit plotter using random sampling. It works by randomly sampling points to test if there are points where f(x,y) \leq 0 as well as f(x,y) \geq 0 in a square region. If so, it subdivides the region into four quadrants and continues. This program plots solutions in the square -15 \leq x < 15 and -15 \leq y < 15. White areas are likely not to contain solutions, orange areas can possibly contain solutions, and blue areas definitely contain solutions. This demo is implemented in JavaScript using Web Workers to divide the computation among four threads, and may not work on old or inferior browsers.

The advantage of using random sampling is that, with high probability, it will converge towards the correct plot of arbitrary pathological functions. The disadvantage is that it is slow and we are never sure if it is actually correct.

This plotter does not test for divergence, so it cannot distinguish between diverging asymptotes and zeros.

2 Examples of interesting functions

FIGURE 1 \exp(\sin(x) + \cos(y)) - \sin(\exp(x+y)) = 0, a pathological function that oscillates extremely rapidly in the “checkerboard” regions. Most software such as Wolfram Alpha struggle with plotting this.
FIGURE 2 \sin(x \sin(x) + \cos(2y)) - \cos(y\cos(y) + \sin(2x)) = 0
FIGURE 3 10\sin((|x|+y)^2/30 + (|x|-y)^2/10) < 3 even has less-than-three in the equation.
FIGURE 4 |\sin(x^2-y^2) - \sin(x+y) - \cos(xy) = 0

For more cool things to try, check out Samuel Alexander’s blog post.