Debian Codegraph @

examples/adg/cubic.html

raw
1 <html>
2 <head>
3 <title>Lima&ccedil;on | JSXGraph Example</title>
4 <link rel="stylesheet" type="text/css" href="../../distrib/jsxgraph.css" />
5 <script type="text/javascript" src="../../distrib/jsxgraphcore.js"></script>
6 </head>
7 <body>
8 <div id="debug" style="display: none"></div>
9 <center>
10 <div style="width: 1000px;">
11 <div style="width:500px; height: 510px;">
12 <div id="jxgbox" class="jxgbox" style="width:500px; height:500px; text-align: left; float: left;"></div>
13 <div id="polynomials" style="display: none; width: 500px; height: 500px; margin-left: 10px; text-align: left; padding-left: -200px;"></div>
14 </div>
15
16 <div style="width: 800px; margin-top: 10px;">
17 <form>
18 <input type="button" onclick="chooseCoordinateSystem();" value="Choose coordinate system" />
19 <input type="button" onclick="generatePolynomials();" value="Generate system of polynomial equations" />
20 <br />
21 <input type="button" onclick="calculateLocus();" value="Calculate locus of T" />
22 <input type="button" onclick="showLocusEquation();" value="Show locus equation" />
23 <input type="button" onclick="showBoard();" value="Show board" />
24 <input type="button" onclick="showLocusTime(loc)" value="Show locus time" />
25 <br />
26 <input type="button" onclick="extend();" value="Extend the construction (with glider)" />
27 <input type="button" onclick="extendedLocus();" value="Calculate extended locus (based on glider C)" />
28 <input type="button" onclick="showLocusTime(loc2)" value="Show locus time" />
29 <br />
30 <input type="button" onclick="extend2();" value="Extend the construction" />
31 <input type="button" onclick="extendedLocus2();" value="Calculate extended locus" />
32 <input type="button" onclick="showLocusTime(loc3)" value="Show locus time" />
33 <br />
34 <input type="text" value="0.2" id="dim" size="3" />
35 <input type="button" onclick="dimConstruction();" value="Dim construction" />
36 <input type="button" onclick="dimLocus();" value="Dim locus" />
37 <input type="button" onclick="dimExtension();" value="Dim extension" />
38 <input type="button" onclick="dimExtension2();" value="Dim extension 2" />
39 <input type="button" onclick="dimLocus2();" value="Dim extended loci" />
40 <br />
41 <input type="button" onclick="runComparison();" value="Run comparison">
42 <input type="button" onclick="window.location.href=window.location.href.split('?')[0]" value="Reload" />
43 <input type="button" onclick="toggleOptimize();" id="opt" value="Optimization is off">
44 </form>
45 </div>
46 </div>
47 </center>
48 <script type="text/javascript">
49 /* <![CDATA[ */
50
51 board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-11, 11, 11, -11], axis: true, grid: false,
52 keepaspectratio: true, showcopyright: false});
53
54 // board.suspendUpdate();
55 a = board.createElement('point', [8, -1]);
56 c = board.createElement('functiongraph', [function (x) { return x*x*x; }]);
57 c.generatePolynomial = function (p) {
58 return ['(' + p.symbolic.x + ')^3 - (' + p.symbolic.y + ')'];
59 };
60 b = board.create('glider', [c]);
61 d = board.createElement('circle', [a, 4]);
62 e = board.createElement('circle', [b, 5]);
63 f = board.create('intersection', [d, e, 0]);
64 z = board.create('midpoint', [b, f]);
65
66 loc = null;
67
68 tg=null;
69 tc=null;
70 ti=null;
71 tm=null;
72 loc2 = null;
73
74 tc2=null;
75 ti2=null;
76 tm2=null;
77 loc3 = null;
78
79 opt = false;
80
81 //board.options.locus.translateToOrigin = true;
82 // board.options.locus.toOrigin = ;
83 //board.options.locus.translateTo10 = true;
84 // board.options.locus.to10 = p4;
85
86 tl = board.create('locus', [z], {strokeWidth: '3px', strokeOpacity: 0.9, strokeColor: 'black'});
87
88 i = board.create('glider', [tl]);
89 j = board.create('circle', [i, 4]);
90 k = board.create('intersection', [j, e, 0]);
91 l = board.create('midpoint', [k, a]);
92 tl2 = board.create('locus', [l]);
93
94
95 function chooseCoordinateSystem() {
96 var k, o;
97 document.getElementById('polynomials').style.display = 'none';
98 document.getElementById('jxgbox').style.display = 'block';
99 JXG.Math.Symbolic.generateSymbolicCoordinatesPartial(board, p14_1, 'u', 'brace');
100
101 for(k in board.objects) {
102 o = board.objects[k];
103 if(o.elementClass == JXG.OBJECT_CLASS_POINT) {
104 o.label.content.setText(o.name + ' (' + o.symbolic.x + ', ' + o.symbolic.y + ')');
105 }
106 }
107
108 board.update();
109 JXG.Math.Symbolic.clearSymbolicCoordinates(board);
110 }
111
112 function generatePolynomials() {
113 var res = JXG.Math.Symbolic.generatePolynomials(board, p14_1, true),
114 i, out = document.getElementById('polynomials');
115
116 out.innerHTML = '<ul>';
117 for(i=0; i<res.length; i++)
118 out.innerHTML += '<li>' + res[i] + ' = 0</li>';
119 out.innerHTML += '</ul>';
120 out.style.display = 'block';
121 document.getElementById('jxgbox').style.display = 'none';
122 }
123
124 function calculateLocus() {
125 loc = board.create('locus', [p14_1], {strokeColor: 'black', strokeWidth: '2px'});
126 }
127
128 function showLocusEquation() {
129 var out = document.getElementById('polynomials');
130
131 out.innerHTML = '<ul>';
132 for(i=0; i<loc.eq.length; i++)
133 out.innerHTML += '<li>' + loc.eq[i] + ' = 0</li>';
134 out.innerHTML += '</ul>';
135 out.style.display = 'block';
136 document.getElementById('jxgbox').style.display = 'none';
137 }
138
139 function showBoard() {
140 document.getElementById('polynomials').style.display = 'none';
141 document.getElementById('jxgbox').style.display = 'block';
142 }
143
144 function dimConstruction() {
145 var c = [p3, p4, c1, g, p6, c2, p14_1], i, o = getDim();
146
147 if(p3.visProp['strokeOpacity'] == o)
148 o = 1.0;
149
150 for(i=0; i<c.length; i++) {
151 c[i].setProperty({strokeOpacity: o, fillOpacity: o});
152 }
153 }
154
155 function dimLocus() {
156 var o = getDim();
157
158 if(loc != null) {
159 if(loc.visProp['strokeOpacity'] == o)
160 o = 1.0;
161 loc.setProperty({strokeOpacity: o});
162 }
163 }
164
165 function dimLocus2() {
166 var o = getDim();
167
168 if(loc2 != null) {
169 if(loc2.visProp['strokeOpacity'] == o)
170 o = 1.0;
171 loc2.setProperty({strokeOpacity: o});
172 }
173 }
174
175 function extend() {
176 if(loc==null)
177 return;
178
179 board.suspendUpdate();
180 tg = board.create('glider', [loc]);
181
182 tc = board.create('circle', [tg, 3]);
183 ti = board.create('intersection', [tc, c1, 0], {color: 'blue'});
184 tm = board.create('midpoint', [tg, ti], {color: 'green'});
185 board.unsuspendUpdate();
186 }
187
188 function dimExtension() {
189 if(tg == null)
190 return;
191
192 var c = [tg, tc, ti, tm], i, o = getDim();
193
194 if(tg.visProp['strokeOpacity'] == o)
195 o = 1.0;
196
197 for(i=0; i<c.length; i++) {
198 c[i].setProperty({strokeOpacity: o, fillOpacity: o});
199 }
200 }
201
202 function getDim() {
203 return parseFloat(document.getElementById('dim').value);
204 }
205
206 function extendedLocus() {
207 loc2 = board.create('locus', [tm], {strokeColor: 'black', strokeWidth: '4px'});
208 }
209
210 function extend2() {
211 board.suspendUpdate();
212 tc2 = board.create('circle', [p14_1, 3]);
213 ti2 = board.create('intersection', [tc2, c1, 0], {color: 'blue'});
214 tm2 = board.create('midpoint', [p14_1, ti2], {color: 'green'});
215 board.unsuspendUpdate();
216 }
217
218 function dimExtension2() {
219 if(tg == null)
220 return;
221
222 var c = [tc2, ti2, tm2], i, o = getDim();
223
224 if(tc2.visProp['strokeOpacity'] == o)
225 o = 1.0;
226
227 for(i=0; i<c.length; i++) {
228 c[i].setProperty({strokeOpacity: o, fillOpacity: o});
229 }
230 }
231
232 function extendedLocus2() {
233 loc3 = board.create('locus', [tm2], {strokeColor: 'green', strokeWidth: '2px'});
234 }
235
236 function showLocusTime(l) {
237 document.getElementById('polynomials').style.display = 'block';
238 document.getElementById('jxgbox').style.display = 'none';
239
240 document.getElementById('polynomials').innerHTML = l.ctime;
241 }
242
243 function toggleOptimize() {
244 if(opt) {
245 board.options.locus.translateToOrigin = false;
246 board.options.locus.translateTo10 = false;
247 opt = false;
248 document.getElementById('opt').value = "Optimization is off";
249 } else {
250 board.options.locus.translateToOrigin = true;
251 board.options.locus.translateTo10 = true;
252 opt = true;
253 document.getElementById('opt').value = "Optimization is on";
254 }
255 }
256
257 function runComparison() {
258 calculateLocus();
259 extend();
260 extendedLocus();
261
262 window.location.href = window.location.href+'?time0='+loc.ctime+'&time1='+loc2.ctime;
263 }
264
265 function runComparison2() {
266 extend2();
267 extendedLocus2();
268
269 window.location.href = window.location.href+'&time2='+loc3.ctime;
270 }
271
272 (function(window, document, undefined) {
273 var r, time0, time1, time2, i;
274 if(window.location.href.indexOf('time1')>-1) {
275 r = window.location.href.split('?')[1].split('&');
276 for(i=0; i<r.length; i++) {
277 if(r[i].split('=')[0] == 'time0')
278 time0 = r[i].split('=')[1];
279
280 if(r[i].split('=')[0] == 'time1')
281 time1 = r[i].split('=')[1];
282
283 if(r[i].split('=')[0] == 'time2')
284 time2 = r[i].split('=')[1];
285 }
286
287 if(time1 === undefined)
288 return;
289
290 if(time2 === undefined) {
291 runComparison2();
292 return;
293 }
294
295 document.getElementById('polynomials').style.display = 'block';
296 document.getElementById('jxgbox').style.display = 'none';
297
298 document.getElementById('polynomials').innerHTML = 'chaining: ' + (parseFloat(time1)+parseFloat(time0)) + '<br />direct: ' + time2;
299 }
300 })(window, document);
301
302
303 /* ]]> */
304 </script>
305 <br/>
306 </body>
307 </html>