1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
<html>
<head>
<title>JSXGraph example</title>
<link rel="stylesheet" type="text/css" href="../distrib/jsxgraph.css" />
<script type="text/javascript" src="../distrib/jsxgraphcore.js"></script>
<script type="text/javascript" src="/javascript/jquery/jquery.js"></script>
<script id="shader-fs" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endifhandleAt
void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
</script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
void main(void) {
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>
</head>
<body>
<h2>Playground to test things temporarily. May change very often.</h2>
<!--a href="javascript:zoomPoints();">Zoom all points (new)</a><br />
<a href="javascript:brd.zoomAllPoints();">Zoom all points (old)</a><br />
<a href="javascript:zoomAll();">Zoom all elements (new)</a-->
<input type="text" id="input" value="sin(x)*x">
<input type="button" value="plot" onClick="plotter()">
<input type="button" value="clear all" onClick="clearAll()">
<div style="width:800px">
<div id="jxgbox" class="jxgbox" style="width:800px; height:800px; float:left;"></div>
<!--div id="jxgbox2" class="jxgbox" style="width:800px; height:800px; float:left"></div-->
</div>
<div id="debug" style="display:block;">DEBUG</div>
<a href="javascript:gJSX();" id="hideaxis">gJSX</a>
<img id="snapshot" />
<script type="text/javascript">
/* <![CDATA[ */
var rotate = (function () {
JXG.Options.text.display = 'internal';
var board = JXG.JSXGraph.initBoard('jxgbox', {axis: false, boundingbox: [-10,10,10,-10], grid: true, keepaspectratio: true}),
p = board.create('point', [1, 2]);
//p.label.content.addRotation(30);
//board.update();
// OR
p.label.content.setProperty({rotate: 30});
}());
var setprop = (function () {
var board = JXG.JSXGraph.initBoard('jxgbox', {axis: false, boundingbox: [-10,10,10,-10], grid: true, keepaspectratio: true}),
line, lines = ['Math.sin(x)', 'Math.cos(x)', 'Math.tan(x)'], funcs = {};
for (line in lines) {
var fname = 'f_'.concat(line);
funcs[fname] = (function (fun) {
return new Function ('x', 'return (' + fun + ');');
})(lines[line]);
board.create('functiongraph', [funcs['f_'.concat(line)]],{name: fname, strokeWidth: 2, dash:2, strokeColor : 'green', doAdvancedPlot:false});
}
board.create('axis', [[0, 0], [1, 0]], {ticks: {drawZero: false}});
});
var spline = (function () {
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 10, 7, -5], axis:true});
var p = [];
p[0] = board.create('point', [-1,2], {size: 4, face: 'o'});
p[1] = board.create('point', [0,-1], {size: 4, face: 'o'});
p[2] = board.create('point', [1,0], {size: 4, face: 'o'});
p[3] = board.create('point', [2,1], {size: 4, face: 'o'});
var c = board.create('spline', p, {strokeWidth:3});
});
var alex_integral = (function () {
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-5,8,8,-5], axis: {ticks: {scale: 3.14, scaleSymbol: 'π'}}, zoom: false, /*pan: false,*/ grid: false});
var p = board.create('plot', [Math.sin]);
var i = board.create('integral', [p, [-2, 2]], {label: {visible: false}, curveLeft: {color: 'green', size: 20, strokeWidth: 7}, color: 'blue'});
});
var simple = (function () {
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox:[-5,8,8,-5], axis: {ticks: {scale: 3.14, scaleSymbol: 'π'}}, zoom: false, /*pan: false,*/ grid: false});
var p = board.create('point', [0, 0], {label: {offset: [10,10]}});
var q = board.create('point', [3.14, 0], {label: {offset: [10,10]}});
var r = board.create('point', [0, 1], {label: {offset: [10,10]}});
var a = board.create('angle', [p, q, r]);
var t = board.create('text', [2, 2, '<button onclick="alert(\'Hello!\');">Click</button>'], {fixed: true});
});
var drei = (function () {
JXG.Options.renderer = 'svg';
var board = JXG.JSXGraph.initBoard('jxgbox', {boundingbox: [-5, 5, 5, -5]}),
cs = [
[-2, 2, 2, 1], [2, 2, 2, 1], [-2, 2, -2, 1], [2, 2, -2, 1],
//[0, -2, 0, 1], [0, -2, 0, 1], [0, -2, 0, 1], [0, -2, 0, 1]
[-2, -2, 2, 1], [2, -2, 2, 1], [-2, -2, -2, 1], [2, -2, -2, 1]
],
ps = [],
init = function () {
for (i = 0; i < cs.length; i++) {
//co = render(cs[i]);
ps[i] = board.create('point', [0, 0], {withLabel: false, trace: false});
ps[i].threeD = JXG.Math.Statistics.add(cs[i], [3, 0, 0]);
}
// back
board.create('segment', [ps[0], ps[1]]);
board.create('segment', [ps[2], ps[3]]);
board.create('segment', [ps[0], ps[2]]);
board.create('segment', [ps[1], ps[3]]);
// front
board.create('segment', [ps[4], ps[5]]);
board.create('segment', [ps[6], ps[7]]);
board.create('segment', [ps[4], ps[6]]);
board.create('segment', [ps[5], ps[7]]);
// left
board.create('segment', [ps[0], ps[4]]);
board.create('segment', [ps[2], ps[6]]);
// right
board.create('segment', [ps[1], ps[5]]);
board.create('segment', [ps[3], ps[7]]);
},
render = function (camera, points) {
var c = camera.position,//[6, 0, 6],
n = camera.normal,//[-2, 0, -2],
i, b, nt,
nl = Math.sqrt(JXG.Math.innerProduct(n, n)),
sgny = Math.abs(n[1]) < JXG.Math.eps ? 0 : (n[1] > 0 ? 1 : -1),
phi, theta,
rotx, roty, transform;
theta = 0;//-Math.atan2(n[1], n[2]);
phi = 0;//-Math.atan2(n[0], n[2]);
/*if (n[0] > 0) {
phi = Math.atan2(n[1], n[0]);
} else if (Math.abs(n[0]) < JXG.Math.eps) {
phi = sgny*Math.PI/2;
} else {
phi = Math.atan2(n[1], n[0]) + sgny*Math.PI;
}
theta = Math.acos(n[2]/nl);*/
rotx = [
[1, 0, 0, 0],
[0, Math.cos(theta), -Math.sin(theta), 0],
[0, Math.sin(theta), Math.cos(theta), 0],
[0, 0, 0, 1]
];
roty = [
[Math.cos(phi), 0, Math.sin(phi), 0],
[0, 1, 0, 0],
[-Math.sin(phi), 0, Math.cos(phi), 0],
[0, 0, 0, 1]
];
//transform = JXG.Math.matMatMult(JXG.Math.projection(Math.PI/4, 1, 0.1, 100), JXG.Math.matMatMult(rotx, roty));
transform = JXG.Math.matMatMult(rotx, roty);
nt = JXG.Math.matVecMult(transform, JXG.Math.Statistics.subtract(n, c));
console.log(nt);
for (i = 0; i < points.length; i++) {
b = JXG.Math.matVecMult(transform, JXG.Math.Statistics.subtract(points[i].threeD, c));
//points[i].moveTo(b[0], b[1]);
points[i].moveTo([Math.abs(nt[2])*b[0]/b[2], Math.abs(nt[2])*b[1]/b[2]]);
//points[i].moveTo([nl*b[0]/b[2], nl*b[1]/b[2]]);
}
//return ;
},
animate = function () {
render({
position: [12*Math.sin(t), 3, 12*Math.cos(t)],
normal: [-1*Math.sin(t), 0, -1*Math.cos(t)]
//normal: [-1*Math.sin(t)*(2+Math.sin(t)), 0, -1*Math.cos(t)*(2+Math.sin(t))]
}, ps);
t += 0.1;
//if (t > 2*Math.PI) {
// t = 0;
// }
setTimeout(animate, 100);
//document.getElementById('debug').innerHTML = t/Math.PI;
},
i, co, t = 0;
init();
/*render({
position: [6, 0, 6],
normal: [-2, 0, -2]
}, ps);*/
setTimeout(animate, 100);
var pmat = JXG.Math.transpose(JXG.Math.projection(Math.PI/4, 1, 0.1, 100));
var d = document.getElementById("debug");
d.innerHTML = '';
for (i = 0; i < pmat.length; i++) {
for (var j = 0; j < pmat[i].length; j++) {
d.innerHTML += pmat[i][j];
d.innerHTML += ', ';
}
d.innerHTML += '<br />';
}
//board.options.axis.majorHeight = 5;
//console.log(project([0, 0, 0]), project([1, 0, 0]), project([0, 1, 0]), project([0, 0, 1]));
// axes
/*var axp = {
visible: true,
withLabel: true,
face: 'x',
size: 5,
strokeWidth: 2,
strokeColor: 'green'
},
axl = {
withLabel: false,
strokeColor: 'black',
strokeWidth: 1,
lastArrow: true
},
o = board.create('point', render([0, 0, 0]), axp),
p100 = board.create('point', render([2, 0, 0]), axp),
p010 = board.create('point', render([0, 2, 0]), axp),
p001 = board.create('point', render([0, 0, 2]), axp),
xax = board.create('line', [o, p100], axl),
yax = board.create('line', [o, p010], axl),
zax = board.create('line', [o, p001], axl);*/
});
/* ]]> */
</script>
</body>
</html>
|