// Numbas version: exam_results_page_options {"name": "Draw a 3d plot with vis.js", "extensions": ["visjs", "stats"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"name": "Draw a 3d plot with vis.js", "parts": [], "extensions": ["stats", "visjs"], "functions": {"listsum": {"parameters": [["lists", "list"]], "language": "jme", "type": "number", "definition": "if(len(lists)>0,lists[0]+listsum(lists[1..len(lists)]),[])"}, "sample_peak": {"parameters": [["x_mean", "number"], ["x_sd", "number"], ["y_mean", "number"], ["y_sd", "number"]], "language": "jme", "type": "number", "definition": "// generate a load of samples from a 2D normal distribution\nrepeat(\n [round(normalsample(x_mean,x_sd)),round(normalsample(y_mean,y_sd))],\n 10000\n )"}, "gatherpoints": {"parameters": [["data", "list"]], "language": "javascript", "type": "list", "definition": "// count the number of points at each coordinate\n// takes a list of [x,y] coordinates representing points\n// returns a list of data of the form [x,y,count]\n\ndata = data.sort(function(a,b){return a[0]b[0] ? 1 : a[1]b[1] ? 1 : 0});\nvar out = [];\nfor(var i=0;iA plot of a function\n

\\[ \\simplify{sin(x/50)*cos(x/50)*50+50} \\]

\n

{plot3dfunction(sin(x/50) * cos(y/50) * 50 + 50,x,0..300#6,y,0..300#6)}

\n

Some random data

\n

{plot3dpoints(data)}

\n

Boxes instead of a surface

\n
Boxes go here
", "rulesets": {}, "variables": {"centres": {"name": "centres", "templateType": "anything", "description": "", "definition": "repeat(let(d,random(2..4),[random(-5..5),d,random(-5..5),d]),3)", "group": "Ungrouped variables"}, "data": {"name": "data", "templateType": "anything", "description": "

Some interesting-looking data: sum a few 2D normal distributions with different centres.

", "definition": "gatherpoints(listsum(map(sample_peak(c[0],c[1],c[2],c[3]),c,centres)))", "group": "Ungrouped variables"}}, "tags": [], "preamble": {"css": "", "js": "question.onHTMLAttached(function() {\n var expr = Numbas.jme.compile('x*x-y*y');\n var xvals = (new Numbas.jme.types.range([-5,5,1])).value.slice(3);\n var yvals = (new Numbas.jme.types.range([-5,5,1])).value.slice(3);\n var options = {\n verticalRatio: 0.5,\n style: 'bar-size'\n }\n var graph = Numbas.extensions.visjs.plot3dfunction(expr,question.scope,'x',xvals,'y',yvals,options);\n $(question.display.html).find('#boxes').html(graph.containerElement);\n})"}, "variable_groups": [], "variablesTest": {"maxRuns": 100, "condition": ""}, "metadata": {"licence": "Creative Commons Attribution 4.0 International", "description": "

This question uses the vis.js library to plot 3D functions and data sets.

\n

As well as JME functions to make plots, you can use javascript functions to get more control over how the plots are rendered.

"}, "type": "question", "contributors": [{"name": "Hina Ahmed", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1160/"}]}]}], "contributors": [{"name": "Hina Ahmed", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1160/"}]}