Bezier curves: Difference between revisions

From JSXGraph Wiki
No edit summary
No edit summary
Line 8: Line 8:
p.push(brd.createElement('point',[2,1],{strokeColor:col,fillColor:col}));        // data point
p.push(brd.createElement('point',[2,1],{strokeColor:col,fillColor:col}));        // data point
col = 'blue';  
col = 'blue';  
p.push(brd.createElement('point',[0.75,2.5],{strokeColor:col,fillColor:col})); // control point
p.push(brd.createElement('point',[0.75,2.5],{strokeColor:col,fillColor:col}));   // control point
p.push(brd.createElement('point',[-0.3,0.3],{strokeColor:col,fillColor:col}));  // control point
p.push(brd.createElement('point',[-0.3,0.3],{strokeColor:col,fillColor:col}));  // control point


Line 15: Line 15:
col = 'blue';  
col = 'blue';  
p.push(brd.createElement('point',[-0.75,-2.5],{strokeColor:col,fillColor:col})); // control point
p.push(brd.createElement('point',[-0.75,-2.5],{strokeColor:col,fillColor:col})); // control point
p.push(brd.createElement('point',[1.5,-2.8],{strokeColor:col,fillColor:col}));     // control point
p.push(brd.createElement('point',[1.5,-2.8],{strokeColor:col,fillColor:col}));   // control point


col = 'red';  
col = 'red';  
p.push(brd.createElement('point',[2,-0.5],{strokeColor:col,fillColor:col}));     // data point
p.push(brd.createElement('point',[2,-0.5],{strokeColor:col,fillColor:col}));     // data point


var c = brd.createElement('curve', JXG.Math.Numerics.bezier(p),{strokecolor:'blue', strokeOpacity:0.6, strokeWidth:5});  
var c = brd.createElement('curve', JXG.Math.Numerics.bezier(p), {strokecolor:'blue', strokeOpacity:0.6, strokeWidth:5});  
</jsxgraph>
</jsxgraph>


Line 32: Line 32:
p.push(brd.createElement('point',[2,1],{strokeColor:col,fillColor:col}));        // data point
p.push(brd.createElement('point',[2,1],{strokeColor:col,fillColor:col}));        // data point
col = 'blue';  
col = 'blue';  
p.push(brd.createElement('point',[0.75,2.5],{strokeColor:col,fillColor:col})); // control point
p.push(brd.createElement('point',[0.75,2.5],{strokeColor:col,fillColor:col}));   // control point
p.push(brd.createElement('point',[-0.3,0.3],{strokeColor:col,fillColor:col}));  // control point
p.push(brd.createElement('point',[-0.3,0.3],{strokeColor:col,fillColor:col}));  // control point


Line 39: Line 39:
col = 'blue';  
col = 'blue';  
p.push(brd.createElement('point',[-0.75,-2.5],{strokeColor:col,fillColor:col})); // control point
p.push(brd.createElement('point',[-0.75,-2.5],{strokeColor:col,fillColor:col})); // control point
p.push(brd.createElement('point',[1.5,-2.8],{strokeColor:col,fillColor:col}));     // control point
p.push(brd.createElement('point',[1.5,-2.8],{strokeColor:col,fillColor:col}));   // control point


col = 'red';  
col = 'red';  
p.push(brd.createElement('point',[2,-0.5],{strokeColor:col,fillColor:col}));     // data point
p.push(brd.createElement('point',[2,-0.5],{strokeColor:col,fillColor:col}));     // data point


var c = brd.createElement('curve', JXG.Math.Numerics.bezier(p),{strokecolor:'blue', strokeOpacity:0.6, strokeWidth:5});  
var c = brd.createElement('curve', JXG.Math.Numerics.bezier(p), {strokecolor:'blue', strokeOpacity:0.6, strokeWidth:5});  
</source>
</source>


[[Category:Examples]]
[[Category:Examples]]
[[Category:Curves]]
[[Category:Curves]]

Revision as of 08:56, 28 September 2009

The red points are connected by a cubic Bezier curve. The blue points are the control points.

The underlying JavaScript code

var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-4,4,4,-4],keepaspectratio:true,axis:true});

var p = [];

col = 'red'; 
p.push(brd.createElement('point',[2,1],{strokeColor:col,fillColor:col}));        // data point
col = 'blue'; 
p.push(brd.createElement('point',[0.75,2.5],{strokeColor:col,fillColor:col}));   // control point
p.push(brd.createElement('point',[-0.3,0.3],{strokeColor:col,fillColor:col}));   // control point

col = 'red'; 
p.push(brd.createElement('point',[-3,1],{strokeColor:col,fillColor:col}));       // data point
col = 'blue'; 
p.push(brd.createElement('point',[-0.75,-2.5],{strokeColor:col,fillColor:col})); // control point
p.push(brd.createElement('point',[1.5,-2.8],{strokeColor:col,fillColor:col}));   // control point

col = 'red'; 
p.push(brd.createElement('point',[2,-0.5],{strokeColor:col,fillColor:col}));     // data point

var c = brd.createElement('curve', JXG.Math.Numerics.bezier(p), {strokecolor:'blue', strokeOpacity:0.6, strokeWidth:5});