// 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": [{"variables": {"data": {"description": "
Some interesting-looking data: sum a few 2D normal distributions with different centres.
", "group": "Ungrouped variables", "definition": "gatherpoints(listsum(map(sample_peak(c[0],c[1],c[2],c[3]),c,centres)))", "templateType": "anything", "name": "data"}, "centres": {"description": "", "group": "Ungrouped variables", "definition": "repeat(let(d,random(2..4),[random(-5..5),d,random(-5..5),d]),3)", "templateType": "anything", "name": "centres"}}, "showQuestionGroupNames": false, "functions": {"listsum": {"parameters": [["lists", "list"]], "language": "jme", "definition": "if(len(lists)>0,lists[0]+listsum(lists[1..len(lists)]),[])", "type": "number"}, "sample_peak": {"parameters": [["x_mean", "number"], ["x_sd", "number"], ["y_mean", "number"], ["y_sd", "number"]], "language": "jme", "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 )", "type": "number"}, "gatherpoints": {"parameters": [["data", "list"]], "language": "javascript", "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;i\\[ \\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{plot3dpoints(data)}
\nThis question uses the vis.js library to plot 3D functions and data sets.
\nAs well as JME functions to make plots, you can use javascript functions to get more control over how the plots are rendered.
", "notes": ""}, "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}]}], "contributors": [{"name": "Christian Lawson-Perfect", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/7/"}]}