Rolling circle on line: Difference between revisions
From JSXGraph Wiki
A WASSERMANN (talk | contribs)  New page: <jsxgraph width="0" height="0" box="nix"></jsxgraph> <html> <script type="text/javascript" src="/~alfred/jsxgraph/trunk/src/Roulette.js"></script> <form> <input type="button" value="start"...  | 
				A WASSERMANN (talk | contribs) No edit summary  | 
				||
| (11 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
<html>  | <html>  | ||
<form>  | <form>  | ||
<input type="button" value="start" onclick="rol.start()">  | <input type="button" value="start" onclick="rol.start()">  | ||
| Line 8: | Line 6: | ||
</form></html>  | </form></html>  | ||
<jsxgraph width="600" height="  | <jsxgraph width="600" height="300" box="jxgbox">  | ||
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-  | var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-1,5,20,-1], keepaspectratio:true});  | ||
brd.suspendUpdate();  | brd.suspendUpdate();  | ||
| Line 19: | Line 17: | ||
var C = brd.create('point',[0,2],{name:'C'});  | var C = brd.create('point',[0,2],{name:'C'});  | ||
var circle = brd.create('curve',[  | var circle = brd.create('curve',[  | ||
                     function(t){var d = P.Dist(C);  |                      function(t){var d = P.Dist(C),  | ||
                                    beta = JXG.Math.Geometry.rad([C.X()+1,C.Y()],C,P);  | |||
                                t += beta;  | |||
                                 return C.X()+d*Math.cos(t);  |                                  return C.X()+d*Math.cos(t);  | ||
                     },  |                      },  | ||
                     function(t){var d = P.Dist(C);  |                      function(t){var d = P.Dist(C),  | ||
                                    beta = JXG.Math.Geometry.rad([C.X()+1,C.Y()],C,P);  | |||
                                t += beta;  | |||
                                 return C.Y()+d*Math.sin(t);  |                                  return C.Y()+d*Math.sin(t);  | ||
                     },  |                      },  | ||
| Line 32: | Line 34: | ||
brd.create('segment',[C,B],{color:'black'});    | brd.create('segment',[C,B],{color:'black'});    | ||
brd.unsuspendUpdate();  | brd.unsuspendUpdate();  | ||
var rol =   | var rol = brd.createRoulette(line, circle, 0, Math.PI/20, 1, 100, [C,P,B]);    | ||
</jsxgraph>  | </jsxgraph>  | ||
| Line 38: | Line 40: | ||
===The underlying JavaScript code===  | ===The underlying JavaScript code===  | ||
<source lang="javascript">  | <source lang="javascript">  | ||
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-1,5,20,-1], keepaspectratio:true});  | |||
brd.suspendUpdate();  | |||
// Line  | |||
var line = brd.create('curve', [function(t) { return t;}, function(t){ return 1;}], {strokeWidth:6});  | |||
// Circle  | |||
var P = brd.create('point',[0,1],{name:'P', trace:true});  | |||
var C = brd.create('point',[0,2],{name:'C'});  | |||
var circle = brd.create('curve',[  | |||
                    function(t){var d = P.Dist(C),  | |||
                                    beta = JXG.Math.Geometry.rad([C.X()+1,C.Y()],C,P);  | |||
                                t += beta;  | |||
                                return C.X()+d*Math.cos(t);  | |||
                    },  | |||
                    function(t){var d = P.Dist(C),  | |||
                                    beta = JXG.Math.Geometry.rad([C.X()+1,C.Y()],C,P);  | |||
                                t += beta;  | |||
                                return C.Y()+d*Math.sin(t);  | |||
                    },  | |||
                    0,2*Math.PI],  | |||
                    {strokeWidth:6, strokeColor:'green'});  | |||
// Point on circle  | |||
var B = brd.create('glider',[0,2,circle],{name:'B', color:'blue',trace:false});  | |||
brd.create('segment',[C,B],{color:'black'});   | |||
brd.unsuspendUpdate();  | |||
var rol = brd.createRoulette(line, circle, 0, Math.PI/20, 1, 100, [C,P,B]);   | |||
</source>  | </source>  | ||
Latest revision as of 17:20, 23 November 2010
The underlying JavaScript code
var brd = JXG.JSXGraph.initBoard('jxgbox',{boundingbox:[-1,5,20,-1], keepaspectratio:true});
brd.suspendUpdate();
// Line
var line = brd.create('curve', [function(t) { return t;}, function(t){ return 1;}], {strokeWidth:6});
// Circle
var P = brd.create('point',[0,1],{name:'P', trace:true});
var C = brd.create('point',[0,2],{name:'C'});
var circle = brd.create('curve',[
                    function(t){var d = P.Dist(C),
                                    beta = JXG.Math.Geometry.rad([C.X()+1,C.Y()],C,P);
                                t += beta;
                                return C.X()+d*Math.cos(t);
                    },
                    function(t){var d = P.Dist(C),
                                    beta = JXG.Math.Geometry.rad([C.X()+1,C.Y()],C,P);
                                t += beta;
                                return C.Y()+d*Math.sin(t);
                    },
                    0,2*Math.PI],
                    {strokeWidth:6, strokeColor:'green'});
// Point on circle
var B = brd.create('glider',[0,2,circle],{name:'B', color:'blue',trace:false});
brd.create('segment',[C,B],{color:'black'}); 
brd.unsuspendUpdate();
var rol = brd.createRoulette(line, circle, 0, Math.PI/20, 1, 100, [C,P,B]);