// Numbas version: exam_results_page_options {"name": "David's copy of Randomly give two of hypotenuse, opposite, and adjacent side of a triangle", "extensions": ["jsxgraph"], "custom_part_types": [], "resources": [], "navigation": {"allowregen": true, "showfrontpage": false, "preventleave": false, "typeendtoleave": false}, "question_groups": [{"pickingStrategy": "all-ordered", "questions": [{"advice": "

We are given the {first_given} and the {second_given}.

\n

We can use Pythagoras' theorem to work out the {missing}.

\n

Pythagoras' theorem states that

\n

\\[ a^2 + b^2 = c^2 \\text{,} \\]

\n

where $a$ is the opposite side, $b$ is the adjacent side, and $c$ is the hypotenuse.

\n

Substituting the values into this equation, we have

\n

\\[ \\var{opposite}^2 + \\var{adjacent}^2 = c^2 \\]\\[ \\var{opposite}^2 + b^2 = \\var{hypotenuse}^2 \\]\\[ a^2 + \\var{adjacent}^2 = \\var{hypotenuse}^2 \\]

\n

So the {missing} is

\n

\\[ \\simplify[noleadingminus,unitfactor]{ sqrt({signs[second_given]}*{sides[first_given]}^2 + {sides[second_given]}^2)} = \\sqrt{\\var{sides[missing]^2}} = \\var{sides[missing]}\\text{m} \\]

", "statement": "

You are told that a triangle has {first_given} side {sides[first_given]}m, and {second_given} side {sides[second_given]}m.

", "variablesTest": {"condition": "", "maxRuns": 100}, "metadata": {"description": "

Some clever variable-substitution trickery to randomly pick two sides of a right-angled triangle to give to a student, and ask for the other.

\n

The sides are set up so they're always Pythagorean triples, and the opposite side is always odd.

\n

As ever, most of the tricky stuff is in the advice. 

\n

Because this was created quickly to show how to set up the randomisation, there's no diagram. It would benefit greatly from a diagram.

", "licence": "Creative Commons Attribution 4.0 International"}, "functions": {"triangle": {"definition": "// This functions plots a right angled triangle based on two lengths\n\n//Set text and graph offsets to appear uniform\nvar xOffset = Math.ceil(opposite/10)+1;\nvar yOffset = (adjacent/4+(xOffset-opposite)/2)\n\n//Consider removing scale once all adjusted correctly\nvar offset = 1;\nvar textHeight =15;\nvar scale = opposite /5;\nvar scaleOffset = offset*scale;\nvar scaleText = textHeight*scale;\n// This functions plots two dimensioned lines \n// Max and min x and y values for the axis.\nvar x_min = 0;\nvar x_max = (adjacent+2*xOffset);\nvar y_min = 0;\nvar y_max = 0.5*(adjacent+2*xOffset);\n\n//Browser compatibility\nJXG.Options.text.display = 'internal';\n//Use MathJax for LaTeX display\nJXG.Options.text.useMathJax = true;\n\n// Make the JSXGraph board.\nvar div = Numbas.extensions.jsxgraph.makeBoard(\n '800px',\n '400px',\n {\n boundingBox: [0,y_max,x_max,0],\n//Change to false after testing\n axis: false,\n }\n);\n\n// div.board is the object created by JSXGraph, which you use to \n// manipulate elements\nvar board = div.board; \n\n//Draw three points \nvar A = board.create('point', [xOffset, yOffset], \n {size:0, fixed:true,\n label:{offset: [-10,-10]}});\nvar B = board.create('point', [(adjacent+xOffset), (opposite+yOffset)],\n {size:0, fixed:true,\n label:{offset: [0,10]}});\nvar C = board.create('point', [(adjacent+xOffset), yOffset],\n {size:0, fixed:true,\n label:{offset: [10,0]}});\n\n//Draw a line between them\nvar AB = board.create('line',[A,B],{fixed:false, straightFirst:false, straightLast:false, strokeWidth: 1});\nvar BC = board.create('line',[B,C],{fixed:false, straightFirst:false, straightLast:false, strokeWidth: 1});\nvar AC = board.create('line',[A,C],{fixed:false, straightFirst:false, straightLast:false, strokeWidth: 1});\n\nvar BCA = board.create('nonreflexangle', [B,C,A], {type:'sector', orthoType:'square', orthoSensitivity:0.4, \nradius:function() { return scale;} \n});\nvar BCALabel = BCA.label.setText(function () {\n var angle = 180.0 * BCA.Value() / Math.PI;\n if ((angle > 90.4) || (angle < 89.6)) {\n return ''+angle.toFixed(1) + '\\u00B0';\n } else {\n return '';\n }\n});\nBCALabel.setAttribute({anchorX:'middle'});\n\n//Set up dimension labels to be properly aligned\nif(missing!='hypotenuse') {\ntextAB = board.create('text', \n [function () {return (A.X() + B.X())/2},\n function () {return ((A.Y() + B.Y())/2)+(scaleOffset/2)},\n function () {return +A.Dist(B).toFixed(1) + ' m'}],\n {fontSize:15, anchorX:'middle'});\nvar tABRot = board.create('transform', \n [function () {return AB.getAngle()}, \n function () {return (A.X() + B.X())/2}, \n function () {return (A.Y() + B.Y())/2}],\n {type:'rotate'});\ntABRot.bindTo(textAB);\n}\n\nif(missing!='opposite side') {\ntextBC = board.create('text', \n [function () {return (B.X() + C.X())/2},\n function () {return ((B.Y() + C.Y())/2)+(scaleOffset/2)},\n function () {return +B.Dist(C).toFixed(1) + ' m'}],\n {fontSize:15, anchorX:'middle'});\nvar tBCRot = board.create('transform', \n [function () {return BC.getAngle()}, \n function () {return (B.X() + C.X())/2}, \n function () {return (B.Y() + C.Y())/2}],\n {type:'rotate'});\ntBCRot.bindTo(textBC); \n}\n\nif(missing!='adjacent side') {\ntextAC = board.create('text', \n [function () {return (A.X() + C.X())/2},\n function () {return ((A.Y() + C.Y())/2)-scaleOffset/2},\n function () {return +A.Dist(C).toFixed(1) + ' m'}],\n {fontSize:15, anchorX:'middle'});\n}\nboard.update();\n\nreturn div;", "parameters": [["adjacent", "number"], ["opposite", "number"], ["missing", "string"]], "type": "html", "language": "javascript"}}, "tags": [], "rulesets": {}, "ungrouped_variables": ["opposite", "adjacent", "hypotenuse", "sides", "missing", "first_given", "second_given", "signs"], "variables": {"sides": {"description": "

A dictionary giving the lengths of the sides. Used in the statement and to set the correct answer.

", "group": "Ungrouped variables", "name": "sides", "templateType": "anything", "definition": "[\"opposite side\":opposite,\"adjacent side\":adjacent,\"hypotenuse\":hypotenuse]"}, "adjacent": {"description": "

The length of the adjacent side. The sides will always form a Pythagorean triple.

", "group": "Ungrouped variables", "name": "adjacent", "templateType": "anything", "definition": "(opposite^2-1)/2"}, "opposite": {"description": "

The length of the opposite side.

", "group": "Ungrouped variables", "name": "opposite", "templateType": "anything", "definition": "random(3..13#2)"}, "second_given": {"description": "

The name of the second side given to the student.

", "group": "Ungrouped variables", "name": "second_given", "templateType": "anything", "definition": "if(missing=\"hypotenuse\",\"adjacent side\",\"hypotenuse\")"}, "missing": {"description": "

The name of the side which the student has to work out.

", "group": "Ungrouped variables", "name": "missing", "templateType": "anything", "definition": "random(keys(sides))"}, "first_given": {"description": "

The name of the first side given to the student.

", "group": "Ungrouped variables", "name": "first_given", "templateType": "anything", "definition": "if(missing=\"opposite side\",\"adjacent side\",\"opposite side\")"}, "signs": {"description": "

Signs of each of the components in the equation $a^2 + b^2 - c^2 = 0$. Used in the working-out in the advice.

\n

In the equation $\\text{missing} = \\sqrt{ \\pm \\text{first}^2 \\pm \\text{second}^2}$, note that:

\n\n

So, only the first side in the square root changes sign depending on the missing side.

", "group": "Ungrouped variables", "name": "signs", "templateType": "anything", "definition": "[\"opposite side\": 1, \"adjacent side\": 1, \"hypotenuse\": -1]"}, "hypotenuse": {"description": "

The length of the hypotenuse.

", "group": "Ungrouped variables", "name": "hypotenuse", "templateType": "anything", "definition": "adjacent+1"}}, "extensions": ["jsxgraph"], "parts": [{"showCorrectAnswer": true, "scripts": {}, "prompt": "

{triangle(adjacent,opposite,missing)}

\n

What is the length of the {missing}?

\n

[[0]]m

", "marks": 0, "showFeedbackIcon": true, "variableReplacementStrategy": "originalfirst", "variableReplacements": [], "gaps": [{"showCorrectAnswer": true, "marks": 1, "mustBeReduced": false, "showFeedbackIcon": true, "minValue": "sides[missing]", "allowFractions": false, "variableReplacements": [], "mustBeReducedPC": 0, "notationStyles": ["plain", "en", "si-en"], "scripts": {}, "maxValue": "sides[missing]", "type": "numberentry", "variableReplacementStrategy": "originalfirst", "correctAnswerStyle": "plain", "correctAnswerFraction": false}], "type": "gapfill"}], "variable_groups": [], "name": "David's copy of Randomly give two of hypotenuse, opposite, and adjacent side of a triangle", "preamble": {"js": "", "css": ""}, "type": "question", "contributors": [{"name": "David Wishart", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1461/"}]}]}], "contributors": [{"name": "David Wishart", "profile_url": "https://numbas.mathcentre.ac.uk/accounts/profile/1461/"}]}