<\/div>","number_of_boards":1,"description":"At construction time each point receives a function pair as coordinates. In each update, these functions (which call `Math.random()`) are called. Thus, in each update each point receives new random coordinates. The 50 points are updated on `move` events.\n\nThis can be used to calculate $\\pi$ using statistics. In each update we count the number of points inside the circle (with midpoint [0,0] and radius 1) and outside the circle. The points are restricted to the square with midpoint [0,0] and edges of length 2.\n\nWe add a `mouseover` event listener to the JSXGraph to trigger the repositioning of the points on every mouse move.\n","dimensions":[{"width":"100%","height":"","aspect-ratio":"1 \/ 1"}],"large_in_db":0,"license":{"title":"Creative Commons Attribution ShareAlike 4.0 International","identifier":"CC BY-SA 4.0","free":"- Share\r\n- Adapt","restrictions":"- Attribution\r\n- ShareAlike\r\n- No additional restrictions","with_attribution":1,"link":"https:\/\/creativecommons.org\/licenses\/by-sa\/4.0\/","image":"https:\/\/i.creativecommons.org\/l\/by-sa\/4.0\/88x31.png","rank":1},"timestamp":"2023-01-24 15:25:33","draft":0,"deleted":0,"tags":[{"id":131,"alias":"animation","name":"Animation"},{"id":108,"alias":"basic-calculus","name":"Basic calculus"},{"id":106,"alias":"calculus","name":"Calculus"},{"id":102,"alias":"famous-theorems","name":"Famous theorems"},{"id":120,"alias":"statistics","name":"Statistics"}],"groups":[],"refers_to":[],"authors":[],"unique_ids":["jxgbox-66383f5a4edb9"],"code_display":"\/\/ Define the id of your board in BOARDID\n\nconst board = JXG.JSXGraph.initBoard(BOARDID, {\n boundingbox: [-1, 1, 1, -1],\n axis: true,\n pan: { needTwoFingers: true }\n});\n\nvar c, i, count = 0,\n tin = 0,\n tout = 0,\n p = [],\n updateText;\nvar c = board.create('circle', [\n [0, 0], 1\n]);\n\np = [];\nfor (var i = 0; i < 50; i++) {\n p[i] = board.create('point',\n [function() {\n return 2 * Math.random() - 1;\n }, function() {\n return 2 * Math.random() - 1;\n }], {\n name: ' ',\n withLabel: false\n });\n}\n\nupdateText = function() {\n var i, inp, outp, x, y, text = '';\n count++;\n\n inp = 0;\n outp = 0;\n\n for (i = 0; i < p.length; i++) {\n x = p[i].X();\n y = p[i].Y();\n\n if (x * x + y * y <= 1) {\n inp++;\n } else {\n outp++;\n }\n }\n tin += inp;\n tout += outp;\n\n text += '
Current:<\/b>
in: ' + inp + ', out: ' + outp + ', total: ' + (inp + outp) +\n '; ratio: ' + (inp \/ (inp + outp)) + ', ratio*4: ' + (4 * inp \/ (inp + outp)) +\n '.
Total:<\/b> (' + count + ' updates in total)
I\u00b4in: ' + tin + ', out: ' + tout +\n ', total: ' + (tin + tout) + ';
ratio: ' + (tin \/ (tin + tout)) + ',
ratio*4: ' + (4 * tin \/ (tin + tout));\n\n document.getElementById('resulttext').innerHTML = text;\n}\n\nboard.on('update', updateText);\n\nJXG.addEvent(document.getElementById(BOARDID), 'mousemove', function() {\n this.update();\n}, board);","code_execute_html":"<\/div>\n