diff options
author | brynnchernosky <56202540+brynnchernosky@users.noreply.github.com> | 2023-05-01 20:37:14 -0400 |
---|---|---|
committer | brynnchernosky <56202540+brynnchernosky@users.noreply.github.com> | 2023-05-01 20:37:14 -0400 |
commit | da534b9792907492e2287fbe4b4f932fde994fa0 (patch) | |
tree | 8daf9ad0d68bbc93effde92e9e83b928a2ab468a | |
parent | c93e1dc281c831ab08cf0ce29420df845323b0be (diff) |
debugging
-rw-r--r-- | src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx | 888 | ||||
-rw-r--r-- | src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx | 19 |
2 files changed, 456 insertions, 451 deletions
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx index 56c61c4f1..21cef297a 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx @@ -33,12 +33,18 @@ import { import Typography from "@mui/material/Typography"; import "./PhysicsSimulationBox.scss"; import InputField from "./PhysicsSimulationInputField"; -import questions from "./PhysicsSimulationQuestions.json"; -import tutorials from "./PhysicsSimulationTutorial.json"; +// import questions from "./PhysicsSimulationQuestions.json"; +// import tutorials from "./PhysicsSimulationTutorial.json"; import Wall from "./PhysicsSimulationWall"; import IWall from "./PhysicsSimulationWall"; import Weight from "./PhysicsSimulationWeight"; +interface IWallProps { + length: number; + xPos: number; + yPos: number; + angleInDegrees: number; +} interface IForce { description: string; magnitude: number; @@ -143,10 +149,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi this.dataDoc.velocityYDisplay = this.dataDoc.velocityYDisplay ?? 0; // Used for review mode - this.dataDoc.answerInputFields = this.dataDoc.answerInputFields ?? <div></div>; - this.dataDoc.currentForceSketch = this.dataDoc.currentForceSketch ?? null; - this.dataDoc.deleteMode = this.dataDoc.deleteMode ?? false; - this.dataDoc.forceSketches = this.dataDoc.forceSketches ?? []; + // this.dataDoc.answerInputFields = this.dataDoc.answerInputFields ?? <div></div>; + // this.dataDoc.currentForceSketch = this.dataDoc.currentForceSketch ?? null; + // this.dataDoc.deleteMode = this.dataDoc.deleteMode ?? false; + // this.dataDoc.forceSketches = this.dataDoc.forceSketches ?? []; this.dataDoc.hintDialogueOpen = this.dataDoc.hintDialogueOpen ?? false; this.dataDoc.noMovement = this.dataDoc.noMovement ?? false; this.dataDoc.questionNumber = this.dataDoc.questionNumber ?? 0; @@ -159,11 +165,11 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi this.dataDoc.reviewStaticAngle = this.dataDoc.reviewStaticAngle ?? 0; this.dataDoc.reviewStaticMagnitude = this.dataDoc.reviewStaticMagnitude ?? 0; this.dataDoc.selectedSolutions = this.dataDoc.selectedSolutions ?? []; - this.dataDoc.selectedQuestion = this.dataDoc.selectedQuestion ?? questions.inclinePlane[0]; - this.dataDoc.sketching = this.dataDoc.sketching ?? false; + // this.dataDoc.selectedQuestion = this.dataDoc.selectedQuestion ?? questions.inclinePlane[0]; + // this.dataDoc.sketching = this.dataDoc.sketching ?? false; - // Used for tutorial mode - this.dataDoc.selectedTutorial = this.dataDoc.selectedTutorial ?? tutorials.inclinePlane; + // // Used for tutorial mode + // this.dataDoc.selectedTutorial = this.dataDoc.selectedTutorial ?? tutorials.inclinePlane; // Used for uniform circular motion this.dataDoc.circularMotionRadius = this.dataDoc.circularMotionRadius ?? 150; @@ -260,7 +266,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi this.dataDoc.showAcceleration = (false); this.dataDoc.showVelocity = (false); this.dataDoc.showForces= (true); - this.generateNewQuestion(); + // this.generateNewQuestion(); if (this.dataDoc.simulationType == "One Weight") { // TODO - one weight review problems } else if (this.dataDoc.simulationType == "Spring") { @@ -286,75 +292,75 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi this.dataDoc.showComponentForces = (false); this.dataDoc.stepNumber = (0); this.dataDoc.showAcceleration = (false); - if (this.dataDoc.simulationType != "Circular Motion") { - this.dataDoc.velocityXDisplay = (0); - this.dataDoc.velocityYDisplay = (0); - this.dataDoc.showVelocity = (false); - } else { - this.dataDoc.velocityXDisplay = (20); - this.dataDoc.velocityYDisplay = (0); - this.dataDoc.showVelocity = (true); - } + // if (this.dataDoc.simulationType != "Circular Motion") { + // this.dataDoc.velocityXDisplay = (0); + // this.dataDoc.velocityYDisplay = (0); + // this.dataDoc.showVelocity = (false); + // } else { + // this.dataDoc.velocityXDisplay = (20); + // this.dataDoc.velocityYDisplay = (0); + // this.dataDoc.showVelocity = (true); + // } - if (this.dataDoc.simulationType == "One Weight") { - this.dataDoc.showForces = (true); - this.dataDoc.startPosY = (this.yMax - 100); - this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - this.radius); - this.dataDoc.selectedTutorial = (tutorials.freeWeight); - this.dataDoc.startForces = (this.getForceFromJSON(tutorials.freeWeight.steps[0].forces)); - this.dataDoc.showForceMagnitudes = (tutorials.freeWeight.steps[0].showMagnitude); - } else if (this.dataDoc.simulationType == "Spring") { - this.dataDoc.showForces = (true); - this.setupSpring(); - this.dataDoc.startPosY = (this.yMin + 200 + 19.62); - this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - this.radius); - this.dataDoc.selectedTutorial = (tutorials.spring); - this.dataDoc.startForces = (this.getForceFromJSON(tutorials.spring.steps[0].forces)); - this.dataDoc.showForceMagnitudes = (tutorials.spring.steps[0].showMagnitude); - } else if (this.dataDoc.simulationType == "Pendulum") { - this.dataDoc.showForces = (true); - const length = 300; - const angle = 30; - const x = length * Math.cos(((90 - angle) * Math.PI) / 180); - const y = length * Math.sin(((90 - angle) * Math.PI) / 180); - const xPos = this.xMax / 2 - x - this.radius; - const yPos = y - this.radius - 5; - this.dataDoc.startPosX = (xPos); - this.dataDoc.startPosY = (yPos); - this.dataDoc.selectedTutorial = (tutorials.pendulum); - this.dataDoc.startForces = (this.getForceFromJSON(tutorials.pendulum.steps[0].forces)); - this.dataDoc.showForceMagnitudes = (tutorials.pendulum.steps[0].showMagnitude); - this.dataDoc.pendulumAngle = (30); - this.dataDoc.pendulumLength = (300); - this.dataDoc.adjustPendulumAngle = ({ angle: 30, length: 300 }); - } else if (this.dataDoc.simulationType == "Inclined Plane") { - this.dataDoc.showForces = (true); - this.dataDoc.wedgeAngle = (26); - this.changeWedgeBasedOnNewAngle(26); - this.dataDoc.selectedTutorial = (tutorials.inclinePlane); - this.dataDoc.startForces = ( - this.getForceFromJSON(tutorials.inclinePlane.steps[0].forces) - ); - this.dataDoc.showForceMagnitudes = (tutorials.inclinePlane.steps[0].showMagnitude); - } else if (this.dataDoc.simulationType == "Circular Motion") { - this.dataDoc.showForces = (true); - this.setupCircular(40); - this.dataDoc.selectedTutorial = (tutorials.circular); - this.dataDoc.startForces = (this.getForceFromJSON(tutorials.circular.steps[0].forces)); - this.dataDoc.showForceMagnitudes = (tutorials.circular.steps[0].showMagnitude); - } else if (this.dataDoc.simulationType == "Pulley") { - this.dataDoc.showForces = (true); - this.setupPulley(); - this.dataDoc.selectedTutorial = (tutorials.pulley); - this.dataDoc.startForces = (this.getForceFromJSON(tutorials.pulley.steps[0].forces)); - this.dataDoc.showForceMagnitudes = (tutorials.pulley.steps[0].showMagnitude); - } else if (this.dataDoc.simulationType == "Suspension") { - this.dataDoc.showForces = (true); - this.setupSuspension(); - this.dataDoc.selectedTutorial = (tutorials.suspension); - this.dataDoc.startForces = (this.getForceFromJSON(tutorials.suspension.steps[0].forces)); - this.dataDoc.showForceMagnitudes = (tutorials.suspension.steps[0].showMagnitude); - } + // if (this.dataDoc.simulationType == "One Weight") { + // this.dataDoc.showForces = (true); + // this.dataDoc.startPosY = (this.yMax - 100); + // this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - this.radius); + // this.dataDoc.selectedTutorial = (tutorials.freeWeight); + // this.dataDoc.startForces = (this.getForceFromJSON(tutorials.freeWeight.steps[0].forces)); + // this.dataDoc.showForceMagnitudes = (tutorials.freeWeight.steps[0].showMagnitude); + // } else if (this.dataDoc.simulationType == "Spring") { + // this.dataDoc.showForces = (true); + // this.setupSpring(); + // this.dataDoc.startPosY = (this.yMin + 200 + 19.62); + // this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - this.radius); + // this.dataDoc.selectedTutorial = (tutorials.spring); + // this.dataDoc.startForces = (this.getForceFromJSON(tutorials.spring.steps[0].forces)); + // this.dataDoc.showForceMagnitudes = (tutorials.spring.steps[0].showMagnitude); + // } else if (this.dataDoc.simulationType == "Pendulum") { + // this.dataDoc.showForces = (true); + // const length = 300; + // const angle = 30; + // const x = length * Math.cos(((90 - angle) * Math.PI) / 180); + // const y = length * Math.sin(((90 - angle) * Math.PI) / 180); + // const xPos = this.xMax / 2 - x - this.radius; + // const yPos = y - this.radius - 5; + // this.dataDoc.startPosX = (xPos); + // this.dataDoc.startPosY = (yPos); + // this.dataDoc.selectedTutorial = (tutorials.pendulum); + // this.dataDoc.startForces = (this.getForceFromJSON(tutorials.pendulum.steps[0].forces)); + // this.dataDoc.showForceMagnitudes = (tutorials.pendulum.steps[0].showMagnitude); + // this.dataDoc.pendulumAngle = (30); + // this.dataDoc.pendulumLength = (300); + // this.dataDoc.adjustPendulumAngle = ({ angle: 30, length: 300 }); + // } else if (this.dataDoc.simulationType == "Inclined Plane") { + // this.dataDoc.showForces = (true); + // this.dataDoc.wedgeAngle = (26); + // this.changeWedgeBasedOnNewAngle(26); + // this.dataDoc.selectedTutorial = (tutorials.inclinePlane); + // this.dataDoc.startForces = ( + // this.getForceFromJSON(tutorials.inclinePlane.steps[0].forces) + // ); + // this.dataDoc.showForceMagnitudes = (tutorials.inclinePlane.steps[0].showMagnitude); + // } else if (this.dataDoc.simulationType == "Circular Motion") { + // this.dataDoc.showForces = (true); + // this.setupCircular(40); + // this.dataDoc.selectedTutorial = (tutorials.circular); + // this.dataDoc.startForces = (this.getForceFromJSON(tutorials.circular.steps[0].forces)); + // this.dataDoc.showForceMagnitudes = (tutorials.circular.steps[0].showMagnitude); + // } else if (this.dataDoc.simulationType == "Pulley") { + // this.dataDoc.showForces = (true); + // this.setupPulley(); + // this.dataDoc.selectedTutorial = (tutorials.pulley); + // this.dataDoc.startForces = (this.getForceFromJSON(tutorials.pulley.steps[0].forces)); + // this.dataDoc.showForceMagnitudes = (tutorials.pulley.steps[0].showMagnitude); + // } else if (this.dataDoc.simulationType == "Suspension") { + // this.dataDoc.showForces = (true); + // this.setupSuspension(); + // this.dataDoc.selectedTutorial = (tutorials.suspension); + // this.dataDoc.startForces = (this.getForceFromJSON(tutorials.suspension.steps[0].forces)); + // this.dataDoc.showForceMagnitudes = (tutorials.suspension.steps[0].showMagnitude); + // } this.dataDoc.simulationReset = (!this.dataDoc.simulationReset); } } @@ -524,45 +530,45 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi } }; - // In review mode, update forces when coefficient of static friction changed - updateReviewForcesBasedOnCoefficient = (coefficient: number) => { - let theta: number = Number(this.dataDoc.wedgeAngle); - let index = - this.dataDoc.selectedQuestion.variablesForQuestionSetup.indexOf("theta - max 45"); - if (index >= 0) { - theta = this.dataDoc.questionVariables[index]; - } - if (isNaN(theta)) { - return; - } - this.dataDoc.reviewGravityMagnitude = (Math.abs(this.dataDoc.gravity)); - this.dataDoc.reviewGravityAngle = (270); - this.dataDoc.reviewNormalMagnitude = ( - Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180) - ); - this.dataDoc.reviewNormalAngle = (90 - theta); - let yForce = -Math.abs(this.dataDoc.gravity); - yForce += - Math.abs(this.dataDoc.gravity) * - Math.cos((theta * Math.PI) / 180) * - Math.sin(((90 - theta) * Math.PI) / 180); - yForce += - coefficient * - Math.abs(this.dataDoc.gravity) * - Math.cos((theta * Math.PI) / 180) * - Math.sin(((180 - theta) * Math.PI) / 180); - let friction = - coefficient * Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180); - if (yForce > 0) { - friction = - (-(Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180)) * - Math.sin(((90 - theta) * Math.PI) / 180) + - Math.abs(this.dataDoc.gravity)) / - Math.sin(((180 - theta) * Math.PI) / 180); - } - this.dataDoc.reviewStaticMagnitude = (friction); - this.dataDoc.reviewStaticAngle = (180 - theta); - }; + // // In review mode, update forces when coefficient of static friction changed + // updateReviewForcesBasedOnCoefficient = (coefficient: number) => { + // let theta: number = Number(this.dataDoc.wedgeAngle); + // let index = + // this.dataDoc.selectedQuestion.variablesForQuestionSetup.indexOf("theta - max 45"); + // if (index >= 0) { + // theta = this.dataDoc.questionVariables[index]; + // } + // if (isNaN(theta)) { + // return; + // } + // this.dataDoc.reviewGravityMagnitude = (Math.abs(this.dataDoc.gravity)); + // this.dataDoc.reviewGravityAngle = (270); + // this.dataDoc.reviewNormalMagnitude = ( + // Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180) + // ); + // this.dataDoc.reviewNormalAngle = (90 - theta); + // let yForce = -Math.abs(this.dataDoc.gravity); + // yForce += + // Math.abs(this.dataDoc.gravity) * + // Math.cos((theta * Math.PI) / 180) * + // Math.sin(((90 - theta) * Math.PI) / 180); + // yForce += + // coefficient * + // Math.abs(this.dataDoc.gravity) * + // Math.cos((theta * Math.PI) / 180) * + // Math.sin(((180 - theta) * Math.PI) / 180); + // let friction = + // coefficient * Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180); + // if (yForce > 0) { + // friction = + // (-(Math.abs(this.dataDoc.gravity) * Math.cos((theta * Math.PI) / 180)) * + // Math.sin(((90 - theta) * Math.PI) / 180) + + // Math.abs(this.dataDoc.gravity)) / + // Math.sin(((180 - theta) * Math.PI) / 180); + // } + // this.dataDoc.reviewStaticMagnitude = (friction); + // this.dataDoc.reviewStaticAngle = (180 - theta); + // }; // In review mode, update forces when wedge angle changed updateReviewForcesBasedOnAngle = (angle: number) => { @@ -672,84 +678,84 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi return solutions; }; - // In review mode, check if input answers match correct answers and optionally generate alert - checkAnswers = (showAlert: boolean = true) => { - let error: boolean = false; - let epsilon: number = 0.01; - if (this.dataDoc.selectedQuestion) { - for (let i = 0; i < this.dataDoc.selectedQuestion.answerParts.length; i++) { - if (this.dataDoc.selectedQuestion.answerParts[i] == "force of gravity") { - if ( - Math.abs(this.dataDoc.reviewGravityMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon - ) { - error = true; - } - } else if (this.dataDoc.selectedQuestion.answerParts[i] == "angle of gravity") { - if (Math.abs(this.dataDoc.reviewGravityAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { - error = true; - } - } else if (this.dataDoc.selectedQuestion.answerParts[i] == "normal force") { - if ( - Math.abs(this.dataDoc.reviewNormalMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon - ) { - error = true; - } - } else if (this.dataDoc.selectedQuestion.answerParts[i] == "angle of normal force") { - if (Math.abs(this.dataDoc.reviewNormalAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { - error = true; - } - } else if ( - this.dataDoc.selectedQuestion.answerParts[i] == "force of static friction" - ) { - if ( - Math.abs(this.dataDoc.reviewStaticMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon - ) { - error = true; - } - } else if ( - this.dataDoc.selectedQuestion.answerParts[i] == "angle of static friction" - ) { - if (Math.abs(this.dataDoc.reviewStaticAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { - error = true; - } - } else if ( - this.dataDoc.selectedQuestion.answerParts[i] == "coefficient of static friction" - ) { - if ( - Math.abs( - Number(this.dataDoc.coefficientOfStaticFriction) - this.dataDoc.selectedSolutions[i] - ) > epsilon - ) { - error = true; - } - } else if (this.dataDoc.selectedQuestion.answerParts[i] == "wedge angle") { - if (Math.abs(Number(this.dataDoc.wedgeAngle) - this.dataDoc.selectedSolutions[i]) > epsilon) { - error = true; - } - } - } - } - if (showAlert) { - if (!error) { - this.dataDoc.simulationPaused = (false); - setTimeout(() => { - this.dataDoc.simulationPaused = (true); - }, 3000); - } else { - this.dataDoc.simulationPaused = (false); - setTimeout(() => { - this.dataDoc.simulationPaused = (true); - }, 3000); - } - } - if (this.dataDoc.selectedQuestion.goal == "noMovement") { - if (!error) { - this.dataDoc.noMovement = (true); - } else { - this.dataDoc.roMovement = (false); - } - } - }; + // // In review mode, check if input answers match correct answers and optionally generate alert + // checkAnswers = (showAlert: boolean = true) => { + // let error: boolean = false; + // let epsilon: number = 0.01; + // if (this.dataDoc.selectedQuestion) { + // for (let i = 0; i < this.dataDoc.selectedQuestion.answerParts.length; i++) { + // if (this.dataDoc.selectedQuestion.answerParts[i] == "force of gravity") { + // if ( + // Math.abs(this.dataDoc.reviewGravityMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon + // ) { + // error = true; + // } + // } else if (this.dataDoc.selectedQuestion.answerParts[i] == "angle of gravity") { + // if (Math.abs(this.dataDoc.reviewGravityAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { + // error = true; + // } + // } else if (this.dataDoc.selectedQuestion.answerParts[i] == "normal force") { + // if ( + // Math.abs(this.dataDoc.reviewNormalMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon + // ) { + // error = true; + // } + // } else if (this.dataDoc.selectedQuestion.answerParts[i] == "angle of normal force") { + // if (Math.abs(this.dataDoc.reviewNormalAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { + // error = true; + // } + // } else if ( + // this.dataDoc.selectedQuestion.answerParts[i] == "force of static friction" + // ) { + // if ( + // Math.abs(this.dataDoc.reviewStaticMagnitude - this.dataDoc.selectedSolutions[i]) > epsilon + // ) { + // error = true; + // } + // } else if ( + // this.dataDoc.selectedQuestion.answerParts[i] == "angle of static friction" + // ) { + // if (Math.abs(this.dataDoc.reviewStaticAngle - this.dataDoc.selectedSolutions[i]) > epsilon) { + // error = true; + // } + // } else if ( + // this.dataDoc.selectedQuestion.answerParts[i] == "coefficient of static friction" + // ) { + // if ( + // Math.abs( + // Number(this.dataDoc.coefficientOfStaticFriction) - this.dataDoc.selectedSolutions[i] + // ) > epsilon + // ) { + // error = true; + // } + // } else if (this.dataDoc.selectedQuestion.answerParts[i] == "wedge angle") { + // if (Math.abs(Number(this.dataDoc.wedgeAngle) - this.dataDoc.selectedSolutions[i]) > epsilon) { + // error = true; + // } + // } + // } + // } + // if (showAlert) { + // if (!error) { + // this.dataDoc.simulationPaused = (false); + // setTimeout(() => { + // this.dataDoc.simulationPaused = (true); + // }, 3000); + // } else { + // this.dataDoc.simulationPaused = (false); + // setTimeout(() => { + // this.dataDoc.simulationPaused = (true); + // }, 3000); + // } + // } + // if (this.dataDoc.selectedQuestion.goal == "noMovement") { + // if (!error) { + // this.dataDoc.noMovement = (true); + // } else { + // this.dataDoc.roMovement = (false); + // } + // } + // }; // Reset all review values to default resetReviewValuesToDefault = () => { @@ -764,248 +770,248 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi this.dataDoc.answerInputFields = (<div></div>); }; - // In review mode, reset problem variables and generate a new question - generateNewQuestion = () => { - this.resetReviewValuesToDefault(); + // // In review mode, reset problem variables and generate a new question + // generateNewQuestion = () => { + // this.resetReviewValuesToDefault(); - const vars: number[] = []; - let question: QuestionTemplate = questions.inclinePlane[0]; + // const vars: number[] = []; + // let question: QuestionTemplate = questions.inclinePlane[0]; - if (this.dataDoc.simulationType == "Inclined Plane") { - if (this.dataDoc.questionNumber == questions.inclinePlane.length - 1) { - this.dataDoc.questionNumber = (0); - } else { - this.dataDoc.questionNumber =(this.dataDoc.questionNumber + 1); - } - question = questions.inclinePlane[this.dataDoc.questionNumber]; + // if (this.dataDoc.simulationType == "Inclined Plane") { + // if (this.dataDoc.questionNumber == questions.inclinePlane.length - 1) { + // this.dataDoc.questionNumber = (0); + // } else { + // this.dataDoc.questionNumber =(this.dataDoc.questionNumber + 1); + // } + // question = questions.inclinePlane[this.dataDoc.questionNumber]; - let coefficient = 0; - let wedgeAngle = 0; + // let coefficient = 0; + // let wedgeAngle = 0; - for (let i = 0; i < question.variablesForQuestionSetup.length; i++) { - if (question.variablesForQuestionSetup[i] == "theta - max 45") { - let randValue = Math.floor(Math.random() * 44 + 1); - vars.push(randValue); - wedgeAngle = randValue; - } else if ( - question.variablesForQuestionSetup[i] == - "coefficient of static friction" - ) { - let randValue = Math.round(Math.random() * 1000) / 1000; - vars.push(randValue); - coefficient = randValue; - } - } - this.dataDoc.wedgeAngle = (wedgeAngle); - this.changeWedgeBasedOnNewAngle(wedgeAngle); - this.dataDoc.coefficientOfStaticFriction = (coefficient); - this.dataDoc.reviewCoefficient = coefficient; - } - let q = ""; - for (let i = 0; i < question.questionSetup.length; i++) { - q += question.questionSetup[i]; - if (i != question.questionSetup.length - 1) { - q += vars[i]; - if (question.variablesForQuestionSetup[i].includes("theta")) { - q += - " degree (≈" + - Math.round((1000 * (vars[i] * Math.PI)) / 180) / 1000 + - " rad)"; - } - } - } - this.dataDoc.questionVariables = vars; - this.dataDoc.selectedQuestion = (question); - this.dataDoc.questionPartOne = (q); - this.dataDoc.questionPartTwo = (question.question); - const answers = this.getAnswersToQuestion(question, vars); - this.generateInputFieldsForQuestion(false, question, answers); - this.dataDoc.simulationReset = (!this.dataDoc.simulationReset); - }; + // for (let i = 0; i < question.variablesForQuestionSetup.length; i++) { + // if (question.variablesForQuestionSetup[i] == "theta - max 45") { + // let randValue = Math.floor(Math.random() * 44 + 1); + // vars.push(randValue); + // wedgeAngle = randValue; + // } else if ( + // question.variablesForQuestionSetup[i] == + // "coefficient of static friction" + // ) { + // let randValue = Math.round(Math.random() * 1000) / 1000; + // vars.push(randValue); + // coefficient = randValue; + // } + // } + // this.dataDoc.wedgeAngle = (wedgeAngle); + // this.changeWedgeBasedOnNewAngle(wedgeAngle); + // this.dataDoc.coefficientOfStaticFriction = (coefficient); + // this.dataDoc.reviewCoefficient = coefficient; + // } + // let q = ""; + // for (let i = 0; i < question.questionSetup.length; i++) { + // q += question.questionSetup[i]; + // if (i != question.questionSetup.length - 1) { + // q += vars[i]; + // if (question.variablesForQuestionSetup[i].includes("theta")) { + // q += + // " degree (≈" + + // Math.round((1000 * (vars[i] * Math.PI)) / 180) / 1000 + + // " rad)"; + // } + // } + // } + // this.dataDoc.questionVariables = vars; + // this.dataDoc.selectedQuestion = (question); + // this.dataDoc.questionPartOne = (q); + // this.dataDoc.questionPartTwo = (question.question); + // const answers = this.getAnswersToQuestion(question, vars); + // this.generateInputFieldsForQuestion(false, question, answers); + // this.dataDoc.simulationReset = (!this.dataDoc.simulationReset); + // }; - // Generate answerInputFields for new review question - generateInputFieldsForQuestion = ( - showIcon: boolean = false, - question: QuestionTemplate = this.dataDoc.selectedQuestion, - answers: number[] = this.dataDoc.selectedSolutions - ) => { - let answerInput = []; - const d = new Date(); - for (let i = 0; i < question.answerParts.length; i++) { - if (question.answerParts[i] == "force of gravity") { - this.dataDoc.reviewGravityMagnitude = (0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={<p>Gravity magnitude</p>} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewGravityMagnitude'} - step={0.1} - unit={"N"} - upperBound={50} - value={this.dataDoc.reviewGravityMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> - </div> - ); - } else if (question.answerParts[i] == "angle of gravity") { - this.dataDoc.reviewGravityAngle = (0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={<p>Gravity angle</p>} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewGravityAngle'} - step={1} - unit={"°"} - upperBound={360} - value={this.dataDoc.reviewGravityAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> - </div> - ); - } else if (question.answerParts[i] == "normal force") { - this.dataDoc.reviewNormalMagnitude = (0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={<p>Normal force magnitude</p>} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewNormalMagnitude'} - step={0.1} - unit={"N"} - upperBound={50} - value={this.dataDoc.reviewNormalMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> - </div> - ); - } else if (question.answerParts[i] == "angle of normal force") { - this.dataDoc.reviewNormalAngle = (0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={<p>Normal force angle</p>} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewNormalAngle'} - step={1} - unit={"°"} - upperBound={360} - value={this.dataDoc.reviewNormalAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> - </div> - ); - } else if (question.answerParts[i] == "force of static friction") { - this.dataDoc.reviewStaticMagnitude = (0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={<p>Static friction magnitude</p>} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewStaticMagnitude'} - step={0.1} - unit={"N"} - upperBound={50} - value={this.dataDoc.reviewStaticMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> - </div> - ); - } else if (question.answerParts[i] == "angle of static friction") { - this.dataDoc.reviewStaticAngle = (0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={<p>Static friction angle</p>} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'reviewStaticAngle'} - step={1} - unit={"°"} - upperBound={360} - value={this.dataDoc.reviewStaticAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - labelWidth={"7em"} - /> - </div> - ); - } else if (question.answerParts[i] == "coefficient of static friction") { - this.updateReviewForcesBasedOnCoefficient(0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={ - <Box> - μ<sub>s</sub> - </Box> - } - lowerBound={0} - dataDoc={this.dataDoc} - prop={'coefficientOfStaticFriction'} - step={0.1} - unit={""} - upperBound={1} - value={this.dataDoc.coefficientOfStaticFriction} - effect={this.updateReviewForcesBasedOnCoefficient} - showIcon={showIcon} - correctValue={answers[i]} - /> - </div> - ); - } else if (question.answerParts[i] == "wedge angle") { - this.updateReviewForcesBasedOnAngle(0); - answerInput.push( - <div key={i + d.getTime()}> - <InputField - label={<Box>θ</Box>} - lowerBound={0} - dataDoc={this.dataDoc} - prop={'wedgeAngle'} - step={1} - unit={"°"} - upperBound={49} - value={this.dataDoc.wedgeAngle} - effect={(val: number) => { - this.changeWedgeBasedOnNewAngle(val); - this.updateReviewForcesBasedOnAngle(val); - }} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - /> - </div> - ); - } - } + // // Generate answerInputFields for new review question + // generateInputFieldsForQuestion = ( + // showIcon: boolean = false, + // question: QuestionTemplate = this.dataDoc.selectedQuestion, + // answers: number[] = this.dataDoc.selectedSolutions + // ) => { + // let answerInput = []; + // const d = new Date(); + // for (let i = 0; i < question.answerParts.length; i++) { + // if (question.answerParts[i] == "force of gravity") { + // this.dataDoc.reviewGravityMagnitude = (0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={<p>Gravity magnitude</p>} + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'reviewGravityMagnitude'} + // step={0.1} + // unit={"N"} + // upperBound={50} + // value={this.dataDoc.reviewGravityMagnitude} + // showIcon={showIcon} + // correctValue={answers[i]} + // labelWidth={"7em"} + // /> + // </div> + // ); + // } else if (question.answerParts[i] == "angle of gravity") { + // this.dataDoc.reviewGravityAngle = (0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={<p>Gravity angle</p>} + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'reviewGravityAngle'} + // step={1} + // unit={"°"} + // upperBound={360} + // value={this.dataDoc.reviewGravityAngle} + // radianEquivalent={true} + // showIcon={showIcon} + // correctValue={answers[i]} + // labelWidth={"7em"} + // /> + // </div> + // ); + // } else if (question.answerParts[i] == "normal force") { + // this.dataDoc.reviewNormalMagnitude = (0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={<p>Normal force magnitude</p>} + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'reviewNormalMagnitude'} + // step={0.1} + // unit={"N"} + // upperBound={50} + // value={this.dataDoc.reviewNormalMagnitude} + // showIcon={showIcon} + // correctValue={answers[i]} + // labelWidth={"7em"} + // /> + // </div> + // ); + // } else if (question.answerParts[i] == "angle of normal force") { + // this.dataDoc.reviewNormalAngle = (0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={<p>Normal force angle</p>} + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'reviewNormalAngle'} + // step={1} + // unit={"°"} + // upperBound={360} + // value={this.dataDoc.reviewNormalAngle} + // radianEquivalent={true} + // showIcon={showIcon} + // correctValue={answers[i]} + // labelWidth={"7em"} + // /> + // </div> + // ); + // } else if (question.answerParts[i] == "force of static friction") { + // this.dataDoc.reviewStaticMagnitude = (0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={<p>Static friction magnitude</p>} + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'reviewStaticMagnitude'} + // step={0.1} + // unit={"N"} + // upperBound={50} + // value={this.dataDoc.reviewStaticMagnitude} + // showIcon={showIcon} + // correctValue={answers[i]} + // labelWidth={"7em"} + // /> + // </div> + // ); + // } else if (question.answerParts[i] == "angle of static friction") { + // this.dataDoc.reviewStaticAngle = (0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={<p>Static friction angle</p>} + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'reviewStaticAngle'} + // step={1} + // unit={"°"} + // upperBound={360} + // value={this.dataDoc.reviewStaticAngle} + // radianEquivalent={true} + // showIcon={showIcon} + // correctValue={answers[i]} + // labelWidth={"7em"} + // /> + // </div> + // ); + // } else if (question.answerParts[i] == "coefficient of static friction") { + // this.updateReviewForcesBasedOnCoefficient(0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={ + // <Box> + // μ<sub>s</sub> + // </Box> + // } + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'coefficientOfStaticFriction'} + // step={0.1} + // unit={""} + // upperBound={1} + // value={this.dataDoc.coefficientOfStaticFriction} + // effect={this.updateReviewForcesBasedOnCoefficient} + // showIcon={showIcon} + // correctValue={answers[i]} + // /> + // </div> + // ); + // } else if (question.answerParts[i] == "wedge angle") { + // this.updateReviewForcesBasedOnAngle(0); + // answerInput.push( + // <div key={i + d.getTime()}> + // <InputField + // label={<Box>θ</Box>} + // lowerBound={0} + // dataDoc={this.dataDoc} + // prop={'wedgeAngle'} + // step={1} + // unit={"°"} + // upperBound={49} + // value={this.dataDoc.wedgeAngle} + // effect={(val: number) => { + // this.changeWedgeBasedOnNewAngle(val); + // this.updateReviewForcesBasedOnAngle(val); + // }} + // radianEquivalent={true} + // showIcon={showIcon} + // correctValue={answers[i]} + // /> + // </div> + // ); + // } + // } - this.dataDoc.answerInputFields = ( - <div - style={{ display: "flex", flexDirection: "column", alignItems: "left" }} - > - {answerInput} - </div> - ); - }; + // this.dataDoc.answerInputFields = ( + // <div + // style={{ display: "flex", flexDirection: "column", alignItems: "left" }} + // > + // {answerInput} + // </div> + // ); + // }; // Default setup for uniform circular motion simulation setupCircular = (value: number) => { @@ -1393,7 +1399,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi </div> <div> {(this.dataDoc.simulationType == "One Weight" || - this.dataDoc.simulationType == "Inclined Plane") && + this.dataDoc.simulationType == "Inclined Plane") && this.wallPositions && this.wallPositions.map((element, index) => { return ( <Wall @@ -1455,7 +1461,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi </select> </div> </div> - {this.dataDoc.mode == "Review" && this.dataDoc.simulationType != "Inclined Plane" && ( + {/* {this.dataDoc.mode == "Review" && this.dataDoc.simulationType != "Inclined Plane" && ( <div className="wordProblemBox"> <p>{this.dataDoc.simulationType} review problems in progress!</p> </div> @@ -1484,7 +1490,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi > <DialogTitle>Hints</DialogTitle> <DialogContent> - {this.dataDoc.selectedQuestion.hints.map((hint, index) => { + {this.dataDoc.selectedQuestion.hints && (this.dataDoc.selectedQuestion.hints.map((hint, index) => { return ( <div key={index}> <DialogContentText> @@ -1499,7 +1505,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi </DialogContentText> </div> ); - })} + }))} </DialogContent> <DialogActions> <Button @@ -1519,8 +1525,8 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi <div className="answer">{this.dataDoc.answerInputFields}</div> </div> </div> - )} - {this.dataDoc.mode == "Tutorial" && ( + )} */} + {/* {this.dataDoc.mode == "Tutorial" && ( <div className="wordProblemBox"> <div className="question"> <h2>Problem</h2> @@ -1664,8 +1670,8 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi )} </div> </div> - )} - {this.dataDoc.mode == "Review" && this.dataDoc.simulationType == "Inclined Plane" && ( + )} */} + {/* {this.dataDoc.mode == "Review" && this.dataDoc.simulationType == "Inclined Plane" && ( <div style={{ display: "flex", @@ -1703,7 +1709,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi </Button> </div> </div> - )} + )} */} {this.dataDoc.mode == "Freeform" && ( <div className="vars"> <FormControl component="fieldset"> diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx index ed219652a..3b2c2e270 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx @@ -65,13 +65,12 @@ interface IState { kineticFriction: boolean, maxPosYConservation: number, timer: number, - update: boolean, - updatedStartPosX: number, - updatedStartPosY: number, + updatedStartPosX: any, + updatedStartPosY: any, walls: IWallProps[], - xPosition: number, + xPosition: any, xVelocity: number, - yPosition: number, + yPosition: any, yVelocity: number, xAccel: number, yAccel: number, @@ -584,7 +583,7 @@ export default class Weight extends React.Component<IWeightProps, IState> { if (this.state.xVelocity != 0) { this.state.walls.forEach((wall) => { if (wall.angleInDegrees == 90) { - const wallX = (wall.xPos / 100) * this.props.layoutDoc._width ?? 500; + const wallX = (wall.xPos / 100) * this.props.layoutDoc._width; if (wall.xPos < 0.35) { if (minX <= wallX) { this.setState({xPosition: wallX+0.01}); @@ -620,7 +619,7 @@ export default class Weight extends React.Component<IWeightProps, IState> { if (this.state.yVelocity > 0) { this.state.walls.forEach((wall) => { if (wall.angleInDegrees == 0 && wall.yPos > 0.4) { - const groundY = (wall.yPos / 100) * this.props.layoutDoc._height ?? 500; + const groundY = (wall.yPos / 100) * this.props.layoutDoc._height; if (maxY > groundY) { this.setState({yPosition: groundY- 2 * this.props.radius-0.01}); if (this.props.elasticCollisions) { @@ -666,7 +665,7 @@ export default class Weight extends React.Component<IWeightProps, IState> { if (this.state.yVelocity < 0) { this.state.walls.forEach((wall) => { if (wall.angleInDegrees == 0 && wall.yPos < 0.4) { - const groundY = (wall.yPos / 100) * this.props.layoutDoc._height ?? 500; + const groundY = (wall.yPos / 100) * this.props.layoutDoc._height; if (minY < groundY) { this.setState({yPosition: groundY + 0.01}); if (this.props.elasticCollisions) { @@ -1281,7 +1280,7 @@ export default class Weight extends React.Component<IWeightProps, IState> { position: "absolute", zIndex: 500, left: Math.round(this.props.xMax * 0.5 - 200 + this.props.wedgeWidth - 80) + "px", - top: Math.round(this.props.layoutDoc._height * 0.8 - 40) + "px", + top: Math.round(this.yMax - 40) + "px", }} > {Math.round( @@ -1518,7 +1517,7 @@ export default class Weight extends React.Component<IWeightProps, IState> { ); })} {!this.state.dragging && - this.props.showForces && + this.props.showForces && this.props.updatedForces && this.props.updatedForces.map((force, index) => { if (force.magnitude < this.epsilon) { return; |