Skip to content

Commit

Permalink
more inequalities
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony F committed Jun 18, 2011
1 parent 2d3e139 commit 21b2492
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions main.js
Expand Up @@ -158,10 +158,6 @@ function compile(n){
var jsc=fn.getString(0,true);
}
if(first){
//ret.f=eval("("+"function(x){return "+jsc+";})");
//The first value of a multi-valued function shall be its
//primary value.

ret.f=new Function("x","return "+jsc);
first=false;
}
Expand Down Expand Up @@ -262,7 +258,11 @@ function compile(n){
var fn=yfuncs[i].simplify();

//Get javascript expression.
var jsc=fn.getString(0,true);
if(fn.type==eqtype.lessthan || fn.type==eqtype.greaterthan){
var jsc=fn[0].getString(0,true);
}else{
var jsc=fn.getString(0,true);
}


var singularities=[];
Expand All @@ -288,8 +288,17 @@ function compile(n){
}else{
//The loop is within the function because calling a function is too slow in javascript (last time I checked)
//Plot each point: (jsc is the expression generated by CAS)
builder+="for(var y=boundbottom;y<boundtop;y+=(boundtop-boundbottom)/height){"+"ctx.line("+jsc+",y);}ctx.stroke();";
}
builder+="for(var y=boundbottom;y<boundtop;y+=(boundtop-boundbottom)/height){"+"ctx.line("+jsc+",y);}";
if(fn.type==eqtype.greaterthan){
builder+="ctx.line(boundright+2,boundtop+2);ctx.line(boundright+2,boundbottom-2);";
builder+="ctx.globalAlpha=0.2;ctx.fill();ctx.globalAlpha=1.0;";
}else if(fn.type==eqtype.lessthan){
builder+="ctx.line(boundleft-2,boundtop+2);ctx.line(boundleft-2,boundbottom-2);";
builder+="ctx.globalAlpha=0.2;ctx.fill();ctx.globalAlpha=1.0;";
}
builder+="ctx.stroke();";

}

try{
//Find stationary points:
Expand Down Expand Up @@ -352,7 +361,11 @@ function compile(n){
var fn=rfuncs[i].simplify();

//Get javascript expression.
var jsc=fn.getString(0,true);
if(fn.type==eqtype.lessthan || fn.type==eqtype.greaterthan){
var jsc=fn[0].getString(0,true);
}else{
var jsc=fn.getString(0,true);
}
jsc=jsc.replace(/app\.variables\[\"(x|y|z|r|theta)\"\]/g,"$1");
if(first){
//ret.f=eval("("+"function(x){return "+jsc+";})");
Expand Down Expand Up @@ -401,7 +414,15 @@ function compile(n){
y=r.sin(f(atan(y/x)))
asin(y/r)=f(atan(y/x))
*/
builder+="var rinc=(rmax-rmin)/width;for(var r=rmin;r<rmax;r+=rinc){var thtmp=("+jsc+");ctx.line(r*cos(thtmp),r*sin(thtmp));}ctx.stroke();";
builder+="var rinc=(rmax-rmin)/width;for(var r=rmin;r<rmax;r+=rinc){var thtmp=("+jsc+");ctx.line(r*cos(thtmp),r*sin(thtmp));}";
if(fn.type==eqtype.greaterthan){
builder+="ctx.line(boundright+2,boundtop+2);ctx.line(boundright+2,boundbottom-2);";
builder+="ctx.globalAlpha=0.2;ctx.fill();ctx.globalAlpha=1.0;";
}else if(fn.type==eqtype.lessthan){
builder+="var thtmp=("+jsc+");ctx.line(rmax*cos(thtmp),boundtop+2);ctx.line(boundleft-2,rmax*cos(thtmp),boundtop+2);ctx.line(boundright+2,boundtop+2);ctx.line(boundright+2,0);";
builder+="ctx.globalAlpha=0.2;ctx.fill();ctx.globalAlpha=1.0;";
}
builder+="ctx.stroke();";
}

}
Expand Down

0 comments on commit 21b2492

Please sign in to comment.