Open magocto opened 11 years ago
+1 on that. Any Ideas how to approach this?
Put some very cumbersome solution for one simple singularity ( form of y=(1/x+p)+q works fine )
Find those lines in main.js
//begin the path. Colour (fill and stroke) is already done for us in ui.js
builder+="ctx.beginPath();var x=boundleft;ctx.move(x,"+jsc+");";
if(0 && singularities.length){
//Better plot logic.
//For example, this would allow us to plot y=sqrt(1-x^2) from [-1,1] exactly with no abrupt endings.
and add below
//Better plot logic.
//For example, this would allow us to plot y=sqrt(1-x^2) from [-1,1] exactly with no abrupt endings.
window.sings=[];
for(var i=0; i<singularities.length; i++){
sings.push(singularities[i]);
}
builder+="var jsc =0; window.c = ctx; window.interval= (boundright-boundleft)/width;\
for(var x=boundleft;x<boundright;x+=interval){\
if(!(x<sings[0] && x+interval>sings[0])){\
ctx.line(x,"+jsc+");\
}else{\
var color = ctx.strokeStyle;\
ctx.stroke();\
\
/* Vertical Asymptote */\
ctx.beginPath();\
ctx.strokeStyle = '#ff0000';\
for(var draw=false,start = boundbottom; start < boundtop;start+=0.1){\
ctx[draw? 'move' : 'line'](x,start);\
draw = !draw;\
}\
ctx.stroke();\
\
/* Horizontal Asymptote */\
if(this.math.length && this.math[0].type==2){\
ctx.beginPath(); console.log("+jsc+",this);\
for(var draw=false,start = boundleft; start < boundright;start+=0.1){\
ctx[draw? 'move' : 'line'](start,this.math[0][1]);\
draw = !draw;\
}\
ctx.stroke();\
}\
\
ctx.beginPath();\
ctx.strokeStyle = color;\
}}ctx.stroke();";
Let me know if its something You might use and whats missing. Sample equations welcomed. If I find some time maby i'll put some more robust solution at least for multiple function y singularities (asymptotes drawing)
FYI: http://en.wikipedia.org/wiki/Mathematical_singularity http://en.wikipedia.org/wiki/Limit_of_a_function http://en.wikipedia.org/wiki/Interval_arithmetic
Fix to better handle vertical asymptotes
"/* Horizontal Asymptote */\
ctx.beginPath(); console.log("+jsc+",this);\
for(var draw=false,start = boundleft; start < boundright;start+=0.1){\
var t=x; x=boundleft;\
ctx[draw? 'move' : 'line'](start,"+jsc+");x=t;\
draw = !draw;\
}\
ctx.stroke();\
It works well but not quite perfect. Same as with vertical a mathematical solution would be better than graphical one. http://www.onlinemathlearning.com/asymptote.html - some inspiration on calculating asymptotes
things like roots() factorise() and singularities() are already in place. better chart plotting would be great. Maby separate builders for separate parts of graph line and separate for asymptotes.
No time to do it properly though.
Thank you for your additions, and for the link. But since that code is pretty old, and nothing at all like what the next release will be like (thank god), these code improvements won't be able to be used.
Are you planning to support all kinds of Asymptotes the right way? (the way singularities are calculated, not my way ;)) Also modular approach would be great as for my needs highschool math level is enough and code would be much simpler. Where is the newest code base? Can I contribute somehow?
Any chance the next version will correctly graph horizontal, vertical asymptotes and discontinuities?