Difference between revisions of "Bearing"

From JSXGraph Wiki
Jump to navigationJump to search
Line 22: Line 22:
===The underlying JavaScript code===
===The underlying JavaScript code===
<code html4strict">
<source lang="html4strict">
<input type="text" id="degrees">
<input type="text" id="degrees">

Revision as of 17:21, 16 June 2010

The underlying JavaScript code

<input type="text" id="degrees">
<input type="button" value="set direction" onclick="setDirection()">
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
                  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();