Jsxgraph角度根据条件更新

时间:2016-06-20 10:34:19

标签: jsxgraph

<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id="jxgbox" class="jxgbox" style="width:600px; height:600px;"></div>
<script type="text/javascript">
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-5,5,5,-5], grid:false, axis:false, keepaspectratio: true, showcopyright:false});
s1= board.create('slider',[[2,-4],[4,-4],[1,3,5]]);
var p=[];
var a=[];
var f=[];
p[1]=board.create('point',[0,0], {withlabel:false, visible:true, fixed:true, color:'#000000', size:2, name:'O'});
p[0]= board.create('point',[0,function(){return p[1].Y()+s1.Value();}], {visible:false, name:'X'});
c= board.create('circle',[p[1],p[0]], {strokeWidth:2, dash:0, fillColor:'#2ECCFA', strokeColor:'#0080FF', fillOpacity:0});
f[0]=function(x){return Math.pow(-1,x)*Math.sqrt(s1.Value()*s1.Value()-x*x);}
for (i=2; i<5; i++)
{p[i]=board.create('glider',[i-4,f[0](i-4),c], {withLabel:true, color:'#000000', size:2})}
poly1=board.create('polygon',[p[4],p[2],p[3],p[1]]);
a[0]=board.create('nonreflexangle',[p[3],p[2],p[4]],{visible:true});
a[1]=board.create('angle',[p[4],p[1],p[3]],{visible:false});
a[2]=board.create('angle',[p[3],p[1],p[4]],{visible:true});
a[0].label.setText('&theta;');
a[1].label.setText(2+'&theta;');
a[2].label.setText(2+'&theta;');
displayangle = function(){
for (i=1; i<3; i++)
{a[i].setAttribute({visible:false});
}
for (i=1; i<3; i++)
{if (a[i].Value().toFixed(3)/a[0].Value().toFixed(3)==2){
a[i].setAttribute({visible:true, withLabel:true});}}
}
for (i=0; i<5; i++)
{p[i].on('drag',displayangle);}
</script>

我试图用JSXgraph绘制一个图来演示圆的简单几何属性,即  中心角度在圆周处的两倍角度 我没有发现任何错误。现在的问题是。当我独自拖动圆圈上的那些自由点时,偶尔会看到角度。

我的直觉告诉我,我做错了什么。请帮我看看。

1 个答案:

答案 0 :(得分:0)

函数success中的测试角度res.sendStatus(200)是两倍角度displayangle()在数值上是不稳定的。我的建议是用以下内容替换测试:

a[i]