Difference between revisions of "Circle"

From JSXGraph Wiki
Jump to: navigation, search
m
 
(One intermediate revision by one other user not shown)
Line 3: Line 3:
 
Lets construct two points "A" and "B".  
 
Lets construct two points "A" and "B".  
 
<source lang="javascript">
 
<source lang="javascript">
var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 100, unitX: 50, unitY: 50});
+
var b = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 2, 5, -2]});
var p1 = b.createElement('point',[0,0], {name:'A',style:6});
+
var p1 = b.createElement('point',[0,0], {name:'A',size: 4, face: 'o'});
var p2 = b.createElement('point',[2,-1], {name:'B',style:6});
+
var p2 = b.createElement('point',[2,-1], {name:'B',size: 4, face: 'o'});
 
</source>
 
</source>
 
Then we construct a circle through "A" and "B". The setting of a new color and changing the stroke-width is not necessary.
 
Then we construct a circle through "A" and "B". The setting of a new color and changing the stroke-width is not necessary.
Line 12: Line 12:
 
</source>
 
</source>
  
<html>
+
<jsxgraph box="jxgbox" width="500" height="200">
<link rel="stylesheet" type="text/css" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css" />
+
  var brd = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 2, 5, -2]});
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
+
  var p1 = brd.createElement('point',[0,0], {name:'A',size: 4, face: 'o'});
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
+
  var p2 = brd.createElement('point',[2,-1], {name:'B',size: 4, face: 'o'});
<div id="jxgbox" class="jxgbox" style="width:500px; height:200px;"></div>
 
<script type="text/javascript">
 
  var brd = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 100, unitX: 50, unitY: 50});
 
  var p1 = brd.createElement('point',[0,0], {name:'A',style:6});
 
  var p2 = brd.createElement('point',[2,-1], {name:'B',style:6});
 
 
  var ci = brd.createElement('circle',["A","B"], {strokeColor:'#00ff00',strokeWidth:2});
 
  var ci = brd.createElement('circle',["A","B"], {strokeColor:'#00ff00',strokeWidth:2});
</script>
+
</jsxgraph>
</html>
 
  
 
Generally it is better to use JavaScript variables and not Geometry-Element names when constructing.
 
Generally it is better to use JavaScript variables and not Geometry-Element names when constructing.
Line 33: Line 27:
 
</source>
 
</source>
  
<html>
+
<jsxgraph box="jxgbox2" width="500" height="200">
<div id="jxgbox2" class="jxgbox" style="width:500px; height:200px;"></div>
+
  var brd2 = JXG.JSXGraph.initBoard('jxgbox2', {boundingbox: [-5, 2, 5, -2]});
<script type="text/javascript">
+
  var p1 = brd2.createElement('point',[0,0], {name:'A',size: 4, face: 'o'});
  var brd2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 200, originY: 100, unitX: 50, unitY: 50});
+
  var p2 = brd2.createElement('point',[2,-1], {name:'B',size: 4, face: 'o'});
  var p1 = brd2.createElement('point',[0,0], {name:'A',style:6});
 
  var p2 = brd2.createElement('point',[2,-1], {name:'B',style:6});
 
 
  var ci2 = brd2.createElement('circle',[p1,p2],  
 
  var ci2 = brd2.createElement('circle',[p1,p2],  
 
   {strokeWidth:3, dash:2, fillColor:'#ffff00', fillOpacity:0.3});
 
   {strokeWidth:3, dash:2, fillColor:'#ffff00', fillOpacity:0.3});
</script>
+
</jsxgraph>
</html>
 
  
 
=== Dynamic fill-opacity ===
 
=== Dynamic fill-opacity ===
Line 48: Line 39:
  
 
<source lang="javascript">
 
<source lang="javascript">
var ci3 = b.createElement('circle',[p1,p2],  
+
var ci3 = b.create('circle',[p1,p2],  
 
     {strokeWidth:1, fillColor:'#555500', fillOpacity:function(){ return p2.X()*0.25;} });
 
     {strokeWidth:1, fillColor:'#555500', fillOpacity:function(){ return p2.X()*0.25;} });
 
</source>
 
</source>
  
<html>
+
<jsxgraph box="jxgbox3" width="500" height="200">
<div id="jxgbox3" class="jxgbox" style="width:500px; height:200px;"></div>
+
  var brd3 = JXG.JSXGraph.initBoard('jxgbox3', {boundingbox: [-5, 2, 5, -2]});
<script type="text/javascript">
+
  var p1 = brd3.create('point',[0,0], {name:'A',size: 4, face: 'o'});
  var brd3 = JXG.JSXGraph.initBoard('jxgbox3', {originX: 200, originY: 100, unitX: 50, unitY: 50});
+
  var p2 = brd3.create('point',[2,0], {name:'B',size: 4, face: 'o'});
  var p1 = brd3.createElement('point',[0,0], {name:'A',style:6});
+
  var ci3 = brd3.create('circle',[p1,p2],  
  var p2 = brd3.createElement('point',[2,0], {name:'B',style:6});
 
  var ci3 = brd3.createElement('circle',[p1,p2],  
 
 
   {strokeWidth:1, fillColor:'#555500', fillOpacity:function(){ return p2.X()*0.25;} });
 
   {strokeWidth:1, fillColor:'#555500', fillOpacity:function(){ return p2.X()*0.25;} });
</script>
+
</jsxgraph>
</html>
 
  
  
 
[[Category:Examples]]
 
[[Category:Examples]]

Latest revision as of 13:41, 7 June 2011

Circle through two points

One possibility to construct a circle is to give its center and a point defining its radius. Lets construct two points "A" and "B".

var b = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 2, 5, -2]});
var p1 = b.createElement('point',[0,0], {name:'A',size: 4, face: 'o'});
var p2 = b.createElement('point',[2,-1], {name:'B',size: 4, face: 'o'});

Then we construct a circle through "A" and "B". The setting of a new color and changing the stroke-width is not necessary.

var ci = b.createElement('circle',["A","B"], {strokeColor:'#00ff00',strokeWidth:2});

Generally it is better to use JavaScript variables and not Geometry-Element names when constructing. Now, we do the same examples with JavaScript variables. To show other variations, we use a dashed stroke style and set a fill color.

var ci2 = b.createElement('circle',[p1,p2], 
    {strokeWidth:3, dash:2, fillColor:'#ffff00', fillOpacity:0.3});

Dynamic fill-opacity

We can make the fill-opacity dynamic and make it dependent on the position of "B", i.e. the JavaScript variable "p2".

var ci3 = b.create('circle',[p1,p2], 
    {strokeWidth:1, fillColor:'#555500', fillOpacity:function(){ return p2.X()*0.25;} });