Debian Codegraph @

examples/adg/simsonsteiner.html

raw
1 <html>
2 <head>
3 <title>Simson Steiner | 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 <script type="text/javascript" src="../../src/Triangle.js"></script>
7 </head>
8 <body>
9 <div id="debug" style="display: none"></div>
10 <center>
11 <div style="width: 1000px;">
12 <div style="width:600px; height: 510px;">
13 <div id="jxgbox" class="jxgbox" style="width:600px; height:500px; text-align: left; float: left;"></div>
14 <div id="polynomials" style="display: none; width: 600px; height: 500px; margin-left: 10px; text-align: left; padding-left: -200px;"></div>
15 </div>
16
17 <div style="width: 800px; margin-top: 10px;">
18 <form>
19 <input type="button" onclick="calculateLocus();" value="Calculate locus of X" />
20 <input type="button" onclick="showLocusEquation();" value="Show locus equation" />
21 <input type="button" onclick="showBoard();" value="Show board" />
22 <input type="button" onclick="showLocusTime(loc)" value="Show locus time" />
23 </form>
24 </div>
25 </div>
26 </center>
27 <script type="text/javascript">
28 /* <![CDATA[ */
29
30 board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-4, 6, 8, -4], axis: true, grid: false,
31 keepaspectratio: true, showcopyright: true});
32 p1 = board.create('point', [0, 0], {name: 'A'});
33 p2 = board.create('point', [6, 0], {name: 'B'});
34 p3 = board.create('point', [4, 4], {name: 'C'});
35
36 t1 = board.create('triangle', [p1, p2, p3], {strokeWidth: '1px', withLabel: true});
37
38 m1 = board.create('point', [4, 1.5], {name:"X", color:'green'});
39
40 l1 = board.createElement('perpendicularpoint', [m1, t1.c], {name: 'L', color: 'blue'});
41 l2 = board.createElement('perpendicularpoint', [m1, t1.a], {name: 'M', color: 'blue'});
42 l3 = board.createElement('perpendicularpoint', [m1, t1.b], {name: 'N', color: 'blue'});
43
44 t2 = board.createElement('triangle', [l1, l2, l3], {strokeWidth: '1px', withLabel: true});
45
46 t1.a.setProperty({withLabel: false});
47 t1.b.setProperty({withLabel: false});
48 t1.c.setProperty({withLabel: false});
49 t2.a.setProperty({withLabel: false});
50 t2.b.setProperty({withLabel: false});
51 t2.c.setProperty({withLabel: false});
52
53 // Get area of triangle given by the three points A, B, C
54 getTriangleArea = function(A, B, C, square) {
55 var a = B.coords.distance(JXG.COORDS_BY_USER, C.coords),
56 b = A.coords.distance(JXG.COORDS_BY_USER, C.coords),
57 c = B.coords.distance(JXG.COORDS_BY_USER, A.coords),
58 s = (typeof square == 'undefined' ? true : square);
59
60 if (s)
61 return (4*a*a*c*c-(a*a+c*c-b*b)*(a*a+c*c-b*b));
62 else
63 return Math.sqrt((4*a*a*c*c-(a*a+c*c-b*b)*(a*a+c*c-b*b))/16.);
64 };
65
66 te = board.createElement('text', [-3.8, 5.5, function () { return ("Fl&auml;che des Dreiecks EDF: " + getTriangleArea(l1, l2, l3, false)); }]);
67
68 // dependency and polynomial generation hacking
69 m1.ancestors[l1.id] = l1;
70 m1.ancestors[l2.id] = l2;
71 m1.ancestors[l3.id] = l3;
72 m1.ancestors[p1.id] = p1;
73 m1.ancestors[p2.id] = p2;
74 m1.ancestors[p3.id] = p3;
75
76 m1.generatePolynomial = function () {
77 var as16 = getTriangleArea(l1, l2, l3),
78 as = '((('+l2.symbolic.x+')-('+l3.symbolic.x+'))^2+(('+l2.symbolic.y+')-('+l3.symbolic.y+'))^2)',
79 bs = '((('+l1.symbolic.x+')-('+l3.symbolic.x+'))^2+(('+l1.symbolic.y+')-('+l3.symbolic.y+'))^2)',
80 cs = '((('+l2.symbolic.x+')-('+l1.symbolic.x+'))^2+(('+l2.symbolic.y+')-('+l1.symbolic.y+'))^2)',
81 poly = '4*'+as+'*'+cs+'-('+as+'+'+cs+'-'+bs+')*('+as+'+'+cs+'-'+bs+')-('+as16+')';
82
83 return ['4*'+as+'*'+cs+'-('+as+'+'+cs+'-'+bs+')*('+as+'+'+cs+'-'+bs+')-('+as16+')'];
84 };
85
86 loc = null;
87
88 createControlElements = function () {
89 glider = board.createElement('glider', [0, 5, loc]);
90 lg1 = board.createElement('perpendicularpoint', [glider, t1.a]);
91 lg2 = board.createElement('perpendicularpoint', [glider, t1.b]);
92 lg3 = board.createElement('perpendicularpoint', [glider, t1.c]);
93
94 tecontrol = board.createElement('text', [-3.8, 5, function () { return ("Fl&auml;che des Dreiecks HIJ: " + getTriangleArea(lg1, lg2, lg3, false)); }]);
95 };
96
97
98 function calculateLocus() {
99 loc = board.create('locus', [m1], {strokeColor: 'black', strokeWidth: '2px'});
100 }
101
102 function showLocusEquation() {
103 var out = document.getElementById('polynomials');
104
105 out.innerHTML = '<ul>';
106 for(i=0; i<loc.eq.length; i++)
107 out.innerHTML += '<li>' + loc.eq[i] + ' = 0</li>';
108 out.innerHTML += '</ul>';
109 out.style.display = 'block';
110 document.getElementById('jxgbox').style.display = 'none';
111 }
112
113 function showBoard() {
114 document.getElementById('polynomials').style.display = 'none';
115 document.getElementById('jxgbox').style.display = 'block';
116 }
117
118 function dimConstruction() {
119 var c = [p3, p4, c1, g, p6, c2, p14_1], i, o = getDim();
120
121 if(p3.visProp['strokeOpacity'] == o)
122 o = 1.0;
123
124 for(i=0; i<c.length; i++) {
125 c[i].setProperty({strokeOpacity: o, fillOpacity: o});
126 }
127 }
128
129 function showLocusTime(l) {
130 document.getElementById('polynomials').style.display = 'block';
131 document.getElementById('jxgbox').style.display = 'none';
132
133 document.getElementById('polynomials').innerHTML = l.ctime;
134 }
135
136 function toggleOptimize() {
137 if(opt) {
138 board.options.locus.translateToOrigin = false;
139 board.options.locus.translateTo10 = false;
140 opt = false;
141 document.getElementById('opt').value = "Optimization is off";
142 } else {
143 board.options.locus.translateToOrigin = true;
144 board.options.locus.translateTo10 = true;
145 opt = true;
146 document.getElementById('opt').value = "Optimization is on";
147 }
148 }
149
150 /* ]]> */
151 </script>
152 <br/>
153 </body>
154 </html>