Circle approximation: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 8: Line 8:
var rot = brd.createElement('transform', [function() {return Math.PI*2.0/n.Value();},p0], {type:'rotate'});  // angle, rotation center
var rot = brd.createElement('transform', [function() {return Math.PI*2.0/n.Value();},p0], {type:'rotate'});  // angle, rotation center
var ptmp = brd.createElement('point',[0,0],{visible:false,withLabel:false});  // dummy point for the rotation
var ptmp = brd.createElement('point',[0,0],{visible:false,withLabel:false});  // dummy point for the rotation
var c = brd.createElement('curve',[[],[]],{fillColor:'#ff3300',fillOpacity:0.5});
var cIn = brd.createElement('curve',[[],[]],{fillColor:'#ff3300',fillOpacity:0.5});
var cOut = brd.createElement('curve',[[],[]],{fillColor:'#0033ff',fillOpacity:0.5});


c.updateDataArray = function() {
cIn.updateDataArray = function() {
   var i;
   var i;
   this.dataX = [p1.X()];
   this.dataX = [p1.X()];
Line 21: Line 22:
   }
   }
}
}
cOut.updateDataArray = function() {
  var i;
  var s = circ.getRadius()/Math.cos(Math.PI*2.0/n.Value);
  this.dataX = [p0.X()+s];
  this.dataY = [p0.Y()];
  ptmp.setPositionDirectly(JXG.COORDS_BY_USER, p0.X()+s,p0.Y());
  for (i=0;i<n.Value();i++) {
    rot.applyOnce(ptmp);
    this.dataX.push(ptmp.X());
    this.dataY.push(ptmp.Y());
  }
}
brd.update();
brd.update();



Revision as of 09:30, 24 June 2009

The underlying JavaScript code