Bearing: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs) No edit summary  | 
				A WASSERMANN (talk | contribs) No edit summary  | 
				||
| Line 44: | Line 44: | ||
}  | }  | ||
</source>  | </source>  | ||
===Version 2===  | |||
<html>  | |||
<form>  | |||
<input type="text" id="degrees">  | |||
<input type="button" value="set direction" onclick="setDirection()">  | |||
</form>  | |||
</html>  | |||
<jsxgraph width="600" height="500">  | |||
var brd = JXG.JSXGraph.initBoard('jxgbox',{axis:true,boundingbox:[-2,1.5,2,-1.5],keepaspectratio:true});  | |||
var c = brd.create('arc',[[1,0],[0,0],[0,1]]);  | |||
var p = brd.create('glider',[-1,0.5,c],{name:'drag me'}); // global variable  | |||
brd.addHook(function(){  | |||
                  document.getElementById('degrees').value = (Math.atan2(p.Y(),p.X())*180/Math.PI).toFixed(0);  | |||
            });  | |||
var setDirection = function() {  | |||
   var phi = 1*document.getElementById('degrees').value*Math.PI/180.0;  | |||
   var r = c.Radius();  | |||
   p.moveTo([r*Math.cos(phi),r*Math.sin(phi)]);  | |||
}  | |||
</jsxgraph>  | |||
[[Category:Examples]]  | [[Category:Examples]]  | ||
Revision as of 16:24, 16 June 2010
The underlying JavaScript code
<form>
<input type="text" id="degrees">
<input type="button" value="set direction" onclick="setDirection()">
</form>
var brd = JXG.JSXGraph.initBoard('jxgbox',{axis:true,boundingbox:[-2,1.5,2,-1.5],keepaspectratio:true});
var c = brd.create('circle',[[0,0],1]);
var p = brd.create('glider',[-1,0.5,c],{name:'drag me'}); // global variable
brd.addHook(function(){
                  document.getElementById('degrees').value = (Math.atan2(p.Y(),p.X())*180/Math.PI).toFixed(0);
            });
var setDirection = function() {
   var phi = 1*document.getElementById('degrees').value*Math.PI/180.0;
   var r = c.Radius();
   p.moveTo([r*Math.cos(phi),r*Math.sin(phi)]);
}
Version 2