Line: Difference between revisions

From JSXGraph Wiki
mNo edit summary
Line 15: Line 15:
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/prototype.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<script type="text/javascript" src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id="jxgbox" class="jxgbox" style="width:500px; height:200px;"></div>
<div id="jxgbox" class="jxgbox" style="width:500px; height:200px; position:relative;"></div>
<script type="text/javascript">
<script type="text/javascript">
  var brd = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 100, unitX: 50, unitY: 50});
  var brd = JXG.JSXGraph.initBoard('jxgbox', {originX: 200, originY: 100, unitX: 50, unitY: 50});
Line 33: Line 33:


<html>
<html>
<div id="jxgbox2" class="jxgbox" style="width:500px; height:200px;"></div>
<div id="jxgbox2" class="jxgbox" style="width:500px; height:200px; position:relative;"></div>
<script type="text/javascript">
<script type="text/javascript">
  var brd2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 200, originY: 100, unitX: 50, unitY: 50});
  var brd2 = JXG.JSXGraph.initBoard('jxgbox2', {originX: 200, originY: 100, unitX: 50, unitY: 50});

Revision as of 14:00, 24 November 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 = b.createElement('point',[-1,1], {name:'A',style:6});
var p2 = b.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 = b.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. To show another variation, we use a dashed line style.

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