0

I have a function that draw functions in processing.js like this:

var plot_line = function(x1, y1, x2, y2) {
    line(x1+200, -y1+200, x2+200, -y2+200);
};

var plot = function (f, scale) {
    scale = scale || 1;
    for (var x=-200; x<200; x++) {
        var y1 = f(x/scale)*scale;
        var y2 = f((x+1)/scale)*scale;
        plot_line(x, y1, x+1, y2);
    }
};

but the function fail if I call plot(Math.tan, 20); because the function have Asymptotes, the ouput look like this:

tangens

Is it possible to have generic draw function that will work for functions like tangens?

Here is a demo the output should look like on google (without vertial lines where there are Asymptotes)

jcubic
  • 61,973
  • 54
  • 229
  • 402
  • You mean "tangent"? Those look correct to me. Your angles should be in radians, not degrees. – duffymo Jan 30 '17 at 21:15
  • Can you be more specific about exactly what the problem is here? You've posted what happens- what did you expect to happen instead? And similar to your other question, can you please post a [mcve] that we can copy and paste to run ourselves? – Kevin Workman Jan 31 '17 at 01:48
  • @KevinWorkman added a demo and link to goole that show how the image should look like. – jcubic Jan 31 '17 at 08:36
  • Can you not just figure out if you are sitting on a vertical asymptote (or will have crossed over it) and just not bother calling the plot function for that one iteration? – Norguard Jan 31 '17 at 08:45
  • it is unclear if you are asking for removing lines from the plot, handling FPU overflow or for detecting ranges and scales of unknown function. – Spektre Jan 31 '17 at 16:55

0 Answers0