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