Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asymptotes and Discontinuities #64

Open
magocto opened this issue May 7, 2013 · 5 comments
Open

Asymptotes and Discontinuities #64

magocto opened this issue May 7, 2013 · 5 comments

Comments

@magocto
Copy link

magocto commented May 7, 2013

Any chance the next version will correctly graph horizontal, vertical asymptotes and discontinuities?

@ev45ive
Copy link

ev45ive commented Jul 29, 2013

+1 on that. Any Ideas how to approach this?

@ev45ive
Copy link

ev45ive commented Jul 29, 2013

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

@ev45ive
Copy link

ev45ive commented Sep 4, 2013

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.

@aantthony
Copy link
Owner

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.

@ev45ive
Copy link

ev45ive commented Sep 5, 2013

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants