Difference between revisions of "Line"

From JSXGraph Wiki
Jump to navigationJump to search
Line 21: Line 21:
 
  var p2 = brd.createElement('point',[2,-1], {name:'B',style:6});
 
  var p2 = brd.createElement('point',[2,-1], {name:'B',style:6});
 
  var li = brd.createElement('line',["A","B"], {strokeColor:'#00ff00',strokeWidth:2});
 
  var li = brd.createElement('line',["A","B"], {strokeColor:'#00ff00',strokeWidth:2});
 +
</script>
 +
</html>
 +
 +
Generally it is better to use JavaScript variables and not Geometry-Element names when constructing.
 +
Now, we do the same examples with JavaScript variables. Further, we don't show the whole line, but only a segment.
 +
 +
<source lang="javascript">
 +
var li2 = brd2.createElement('line',[p1,p2], {straightFirst:false, straigtLast:false, strokeWidth:2});
 +
</source>
 +
 +
<html>
 +
<div id="jxgbox2" class="jxgbox" style="width:500px; height:200px;"></div>
 +
<script type="text/javascript">
 +
var brd2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 200, originY: 100, unitX: 50, unitY: 50});
 +
var p1 = brd2.createElement('point',[-1,1], {name:'A',style:6});
 +
var p2 = brd2.createElement('point',[2,-1], {name:'B',style:6});
 +
var li2 = brd2.createElement('line',[p1,p2], {straightFirst:false, straigtLast:false, strokeWidth:2});
 
</script>
 
</script>
 
</html>
 
</html>

Revision as of 17:42, 17 September 2008

Construction of a line

A line needs two points. Lets construct two points "A" and "B".

var b = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 100, unitX: 50, unitY: 50});
var p1 = board.createElement('point',[-1,1], {name:'A',style:6});
var p2 = board.createElement('point',[2,-1], {name:'B',style:6});

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

var li = brd.createElement('line',["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. Further, we don't show the whole line, but only a segment.

var li2 = brd2.createElement('line',[p1,p2], {straightFirst:false, straigtLast:false, strokeWidth:2});