From 136d946b88ff817c2dd738553ddb2aea0a11f0e7 Mon Sep 17 00:00:00 2001 From: brynnchernosky <56202540+brynnchernosky@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:29:43 -0500 Subject: remove extraneous code --- src/client/views/nodes/PhysicsSimulationApp.tsx | 1353 +------------------- src/client/views/nodes/PhysicsSimulationBox.scss | 7 + src/client/views/nodes/PhysicsSimulationWall.tsx | 1 - src/client/views/nodes/PhysicsSimulationWedge.tsx | 2 +- src/client/views/nodes/PhysicsSimulationWeight.tsx | 1 - 5 files changed, 27 insertions(+), 1337 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/PhysicsSimulationApp.tsx b/src/client/views/nodes/PhysicsSimulationApp.tsx index 7486aa88d..0a39b3291 100644 --- a/src/client/views/nodes/PhysicsSimulationApp.tsx +++ b/src/client/views/nodes/PhysicsSimulationApp.tsx @@ -1,51 +1,8 @@ -import AddIcon from "@mui/icons-material/Add"; -import AddCircleIcon from "@mui/icons-material/AddCircle"; -import ClearIcon from "@mui/icons-material/Clear"; -import PauseIcon from "@mui/icons-material/Pause"; -import PlayArrowIcon from "@mui/icons-material/PlayArrow"; -import ReplayIcon from "@mui/icons-material/Replay"; -import QuestionMarkIcon from "@mui/icons-material/QuestionMark"; -import ArrowLeftIcon from "@mui/icons-material/ArrowLeft"; -import ArrowRightIcon from "@mui/icons-material/ArrowRight"; -import { SelectChangeEvent } from "@mui/material/Select"; -import { - Alert, - Box, - Button, - Checkbox, - CircularProgress, - Dialog, - DialogTitle, - DialogContent, - DialogContentText, - DialogActions, - Divider, - FormControl, - FormControlLabel, - FormGroup, - IconButton, - InputAdornment, - InputLabel, - LinearProgress, - List, - ListItem, - ListItemButton, - ListItemIcon, - ListItemText, - MenuItem, - Popover, - Select, - Stack, - TextField, - Tooltip, -} from "@mui/material"; -import { styled } from "@mui/material/styles"; -import { tooltipClasses, TooltipProps } from "@mui/material/Tooltip"; -import Typography from "@mui/material/Typography"; import React, { useEffect, useState } from "react"; import "./PhysicsSimulationBox.scss"; import { IForce, Weight } from "./PhysicsSimulationWeight"; -import { Description } from "@mui/icons-material"; +import {Wall, IWallProps } from "./PhysicsSimulationWall" +import {Wedge} from "./PhysicsSimulationWedge" interface VectorTemplate { top: number; @@ -91,17 +48,6 @@ function App() { magnitude: gravityMagnitude, directionInDegrees: 270, }; - const HtmlTooltip = styled(({ className, ...props }: TooltipProps) => ( - - ))(({ theme }) => ({ - [`& .${tooltipClasses.tooltip}`]: { - backgroundColor: "#f5f5f9", - color: "rgba(0, 0, 0, 0.87)", - maxWidth: 220, - fontSize: theme.typography.pxToRem(12), - border: "1px solid #dadde9", - }, - })); const xMin = 0; const yMin = 0; const xMax = window.innerWidth * 0.7; @@ -165,12 +111,6 @@ function App() { const [reviewNormalMagnitude, setReviewNormalMagnitude] = useState(0); const [reviewStaticAngle, setReviewStaticAngle] = useState(0); const [reviewStaticMagnitude, setReviewStaticMagnitude] = useState(0); - const [selectedQuestion, setSelectedQuestion] = useState( - questions.inclinePlane[0] - ); - const [selectedTutorial, setSelectedTutorial] = useState( - tutorials.inclinePlane - ); const [questionPartTwo, setQuestionPartTwo] = useState(""); const [selectedSolutions, setSelectedSolutions] = useState([]); const [showAcceleration, setShowAcceleration] = useState(false); @@ -333,244 +273,7 @@ function App() { const getDisplayYPos = (yPos: number) => { return yMax - yPos - 2 * 50 + 5; }; - - // In review mode, update forces when coefficient of static friction changed - const updateReviewForcesBasedOnCoefficient = (coefficient: number) => { - let theta: number = Number(wedgeAngle); - let index = - selectedQuestion.variablesForQuestionSetup.indexOf("theta - max 45"); - if (index >= 0) { - theta = questionVariables[index]; - } - if (isNaN(theta)) { - return; - } - setReviewGravityMagnitude(forceOfGravity.magnitude); - setReviewGravityAngle(270); - setReviewNormalMagnitude( - forceOfGravity.magnitude * Math.cos((theta * Math.PI) / 180) - ); - setReviewNormalAngle(90 - theta); - let yForce = -forceOfGravity.magnitude; - yForce += - 9.81 * - Math.cos((theta * Math.PI) / 180) * - Math.sin(((90 - theta) * Math.PI) / 180); - yForce += - coefficient * - 9.81 * - Math.cos((theta * Math.PI) / 180) * - Math.sin(((180 - theta) * Math.PI) / 180); - let friction = coefficient * 9.81 * Math.cos((theta * Math.PI) / 180); - if (yForce > 0) { - friction = - (-(forceOfGravity.magnitude * Math.cos((theta * Math.PI) / 180)) * - Math.sin(((90 - theta) * Math.PI) / 180) + - forceOfGravity.magnitude) / - Math.sin(((180 - theta) * Math.PI) / 180); - } - setReviewStaticMagnitude(friction); - setReviewStaticAngle(180 - theta); - }; - - // In review mode, update forces when wedge angle changed - const updateReviewForcesBasedOnAngle = (angle: number) => { - setReviewGravityMagnitude(9.81); - setReviewGravityAngle(270); - setReviewNormalMagnitude(9.81 * Math.cos((Number(angle) * Math.PI) / 180)); - setReviewNormalAngle(90 - angle); - let yForce = -forceOfGravity.magnitude; - yForce += - 9.81 * - Math.cos((Number(angle) * Math.PI) / 180) * - Math.sin(((90 - Number(angle)) * Math.PI) / 180); - yForce += - reviewCoefficient * - 9.81 * - Math.cos((Number(angle) * Math.PI) / 180) * - Math.sin(((180 - Number(angle)) * Math.PI) / 180); - let friction = - reviewCoefficient * 9.81 * Math.cos((Number(angle) * Math.PI) / 180); - if (yForce > 0) { - friction = - (-(9.81 * Math.cos((Number(angle) * Math.PI) / 180)) * - Math.sin(((90 - Number(angle)) * Math.PI) / 180) + - forceOfGravity.magnitude) / - Math.sin(((180 - Number(angle)) * Math.PI) / 180); - } - setReviewStaticMagnitude(friction); - setReviewStaticAngle(180 - angle); - }; - - // Solve for the correct answers to the generated problem - const getAnswersToQuestion = ( - question: QuestionTemplate, - questionVars: number[] - ) => { - const solutions: number[] = []; - - let theta: number = Number(wedgeAngle); - let index = question.variablesForQuestionSetup.indexOf("theta - max 45"); - if (index >= 0) { - theta = questionVars[index]; - } - let muS: number = Number(coefficientOfStaticFriction); - index = question.variablesForQuestionSetup.indexOf( - "coefficient of static friction" - ); - if (index >= 0) { - muS = questionVars[index]; - } - - for (let i = 0; i < question.answerSolutionDescriptions.length; i++) { - const description = question.answerSolutionDescriptions[i]; - if (!isNaN(Number(description))) { - solutions.push(Number(description)); - } else if (description == "solve normal force angle from wedge angle") { - solutions.push(90 - theta); - } else if ( - description == "solve normal force magnitude from wedge angle" - ) { - solutions.push( - forceOfGravity.magnitude * Math.cos((theta / 180) * Math.PI) - ); - } else if ( - description == - "solve static force magnitude from wedge angle given equilibrium" - ) { - let normalForceMagnitude = - forceOfGravity.magnitude * Math.cos((theta / 180) * Math.PI); - let normalForceAngle = 90 - theta; - let frictionForceAngle = 180 - theta; - let frictionForceMagnitude = - (-normalForceMagnitude * - Math.sin((normalForceAngle * Math.PI) / 180) + - 9.81) / - Math.sin((frictionForceAngle * Math.PI) / 180); - solutions.push(frictionForceMagnitude); - } else if ( - description == - "solve static force angle from wedge angle given equilibrium" - ) { - solutions.push(180 - theta); - } else if ( - description == - "solve minimum static coefficient from wedge angle given equilibrium" - ) { - let normalForceMagnitude = - forceOfGravity.magnitude * Math.cos((theta / 180) * Math.PI); - let normalForceAngle = 90 - theta; - let frictionForceAngle = 180 - theta; - let frictionForceMagnitude = - (-normalForceMagnitude * - Math.sin((normalForceAngle * Math.PI) / 180) + - 9.81) / - Math.sin((frictionForceAngle * Math.PI) / 180); - let frictionCoefficient = frictionForceMagnitude / normalForceMagnitude; - solutions.push(frictionCoefficient); - } else if ( - description == - "solve maximum wedge angle from coefficient of static friction given equilibrium" - ) { - solutions.push((Math.atan(muS) * 180) / Math.PI); - } - } - setSelectedSolutions(solutions); - return solutions; - }; - - // In review mode, check if input answers match correct answers and optionally generate alert - const checkAnswers = (showAlert: boolean = true) => { - let error: boolean = false; - let epsilon: number = 0.01; - if (selectedQuestion) { - for (let i = 0; i < selectedQuestion.answerParts.length; i++) { - if (selectedQuestion.answerParts[i] == "force of gravity") { - if ( - Math.abs(reviewGravityMagnitude - selectedSolutions[i]) > epsilon - ) { - error = true; - } - } else if (selectedQuestion.answerParts[i] == "angle of gravity") { - if (Math.abs(reviewGravityAngle - selectedSolutions[i]) > epsilon) { - error = true; - } - } else if (selectedQuestion.answerParts[i] == "normal force") { - if ( - Math.abs(reviewNormalMagnitude - selectedSolutions[i]) > epsilon - ) { - error = true; - } - } else if (selectedQuestion.answerParts[i] == "angle of normal force") { - if (Math.abs(reviewNormalAngle - selectedSolutions[i]) > epsilon) { - error = true; - } - } else if ( - selectedQuestion.answerParts[i] == "force of static friction" - ) { - if ( - Math.abs(reviewStaticMagnitude - selectedSolutions[i]) > epsilon - ) { - error = true; - } - } else if ( - selectedQuestion.answerParts[i] == "angle of static friction" - ) { - if (Math.abs(reviewStaticAngle - selectedSolutions[i]) > epsilon) { - error = true; - } - } else if ( - selectedQuestion.answerParts[i] == "coefficient of static friction" - ) { - if ( - Math.abs( - Number(coefficientOfStaticFriction) - selectedSolutions[i] - ) > epsilon - ) { - error = true; - } - } else if (selectedQuestion.answerParts[i] == "wedge angle") { - if (Math.abs(Number(wedgeAngle) - selectedSolutions[i]) > epsilon) { - error = true; - } - } - } - } - if (showAlert) { - if (!error) { - setSimulationPaused(false); - setTimeout(() => { - setSimulationPaused(true); - }, 3000); - } else { - setSimulationPaused(false); - setTimeout(() => { - setSimulationPaused(true); - }, 3000); - } - } - if (selectedQuestion.goal == "noMovement") { - if (!error) { - setNoMovement(true); - } else { - setNoMovement(false); - } - } - }; - - const resetReviewValuesToDefault = () => { - // Reset all values to default - setReviewGravityMagnitude(0); - setReviewGravityAngle(0); - setReviewNormalMagnitude(0); - setReviewNormalAngle(0); - setReviewStaticMagnitude(0); - setReviewStaticAngle(0); - setCoefficientOfKineticFriction(0); - setSimulationPaused(true); - setAnswerInputFields(
); - }; - + // In review mode, edit force arrow sketch on mouse movement const editForce = (element: VectorTemplate) => { if (!sketching) { @@ -589,288 +292,6 @@ function App() { } }; - // In review mode, reset problem variables and generate a new question - const generateNewQuestion = () => { - resetReviewValuesToDefault(); - - const vars: number[] = []; - let question: QuestionTemplate = questions.inclinePlane[0]; - - if (simulationType == "Inclined Plane") { - if (questionNumber == questions.inclinePlane.length - 1) { - setQuestionNumber(0); - } else { - setQuestionNumber(questionNumber + 1); - } - question = questions.inclinePlane[questionNumber]; - - let coefficient = 0; - let wedge = 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); - wedge = randValue; - } else if ( - question.variablesForQuestionSetup[i] == - "coefficient of static friction" - ) { - let randValue = Math.round(Math.random() * 1000) / 1000; - vars.push(randValue); - coefficient = randValue; - } - } - setWedgeAngle(wedge); - changeWedgeBasedOnNewAngle(wedge); - setCoefficientOfStaticFriction(coefficient); - 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)"; - } - } - } - questionVariables = vars; - setSelectedQuestion(question); - setQuestionPartOne(q); - setQuestionPartTwo(question.question); - const answers = getAnswersToQuestion(question, vars); - generateInputFieldsForQuestion(false, question, answers); - }; - - // Generate answerInputFields for new review question - const generateInputFieldsForQuestion = ( - showIcon: boolean = false, - question: QuestionTemplate = selectedQuestion, - answers: number[] = selectedSolutions - ) => { - let answerInput = []; - const d = new Date(); - for (let i = 0; i < question.answerParts.length; i++) { - if (question.answerParts[i] == "force of gravity") { - setReviewGravityMagnitude(0); - answerInput.push( -
- - FG -

- } - lowerBound={0} - changeValue={setReviewGravityMagnitude} - step={0.1} - unit={"N"} - upperBound={50} - value={reviewGravityMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "angle of gravity") { - setReviewGravityAngle(0); - answerInput.push( -
- - θG -

- } - lowerBound={0} - changeValue={setReviewGravityAngle} - step={1} - unit={"°"} - upperBound={360} - value={reviewGravityAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "normal force") { - setReviewNormalMagnitude(0); - answerInput.push( -
- - FN -

- } - lowerBound={0} - changeValue={setReviewNormalMagnitude} - step={0.1} - unit={"N"} - upperBound={50} - value={reviewNormalMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "angle of normal force") { - setReviewNormalAngle(0); - answerInput.push( -
- - θN -

- } - lowerBound={0} - changeValue={setReviewNormalAngle} - step={1} - unit={"°"} - upperBound={360} - value={reviewNormalAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "force of static friction") { - setReviewStaticMagnitude(0); - answerInput.push( -
- - F - - Fs - -

- } - lowerBound={0} - changeValue={setReviewStaticMagnitude} - step={0.1} - unit={"N"} - upperBound={50} - value={reviewStaticMagnitude} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "angle of static friction") { - setReviewStaticAngle(0); - answerInput.push( -
- - θ - - Fs - -

- } - lowerBound={0} - changeValue={setReviewStaticAngle} - step={1} - unit={"°"} - upperBound={360} - value={reviewStaticAngle} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "coefficient of static friction") { - updateReviewForcesBasedOnCoefficient(0); - answerInput.push( -
- - - μs - - Coefficient of static friction; between 0 and 1 - - } - followCursor - > - - μs - - - } - lowerBound={0} - changeValue={setCoefficientOfStaticFriction} - step={0.1} - unit={""} - upperBound={1} - value={coefficientOfStaticFriction} - effect={updateReviewForcesBasedOnCoefficient} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } else if (question.answerParts[i] == "wedge angle") { - updateReviewForcesBasedOnAngle(0); - answerInput.push( -
- - θ - Angle of incline plane from the ground, 0-49 - - } - followCursor - > - θ - - } - lowerBound={0} - changeValue={setWedgeAngle} - step={1} - unit={"°"} - upperBound={49} - value={wedgeAngle} - effect={(val: number) => { - changeWedgeBasedOnNewAngle(val); - updateReviewForcesBasedOnAngle(val); - }} - radianEquivalent={true} - showIcon={showIcon} - correctValue={answers[i]} - /> -
- ); - } - } - - setAnswerInputFields( -
- {answerInput} -
- ); - }; - // Remove floor and walls from simulation const removeWalls = () => { setWallPositions([]); @@ -939,62 +360,6 @@ function App() { setAdjustPendulumAngle({ angle: 50, length: 300 }); removeWalls(); } - } else if (mode == "Review") { - setShowForceMagnitudes(true); - if (simulationType == "Two Weights") { - // TODO - } else if (simulationType == "Inclined Plane") { - addWedge(); - setUpdatedForces([]); - setStartForces([]); - addWalls(); - } - setShowAcceleration(false); - setShowVelocity(false); - setShowForces(true); - generateNewQuestion(); - } else if (mode == "Tutorial") { - setStepNumber(0); - if (simulationType == "One Weight") { - addWeight(); - setStartPosY(yMin + 50); - setStartPosX((xMax + xMin - 50) / 2); - setSelectedTutorial(tutorials.freeWeight); - setSelectedTutorial(tutorials.freeWeight); - setStartForces(getForceFromJSON(tutorials.freeWeight.steps[0].forces)); - setShowForceMagnitudes(tutorials.freeWeight.steps[0].showMagnitude); - addWalls(); - } else if (simulationType == "Two Weights") { - // TODO - } else if (simulationType == "Pendulum") { - 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 = xMax / 2 - x - 50; - const yPos = y - 50 - 5; - addPendulum(); - setStartPosX(xPos); - setStartPosY(yPos); - setSelectedTutorial(tutorials.pendulum); - setStartForces(getForceFromJSON(tutorials.pendulum.steps[0].forces)); - setShowForceMagnitudes(tutorials.pendulum.steps[0].showMagnitude); - setPendulumAngle(50); - setPendulumLength(300); - setAdjustPendulumAngle({ angle: 30, length: 300 }); - removeWalls(); - } else if (simulationType == "Inclined Plane") { - addWedge(); - setWedgeAngle(26); - changeWedgeBasedOnNewAngle(26); - setSelectedTutorial(tutorials.inclinePlane); - setStartForces( - getForceFromJSON(tutorials.inclinePlane.steps[0].forces) - ); - setShowForceMagnitudes(tutorials.inclinePlane.steps[0].showMagnitude); - addWalls(); - } - setSimulationReset(!simulationReset); } }, [simulationType, mode]); @@ -1130,7 +495,7 @@ function App() { width: "50vw", }} > - +

SIMULATION IN PROGRESS

)}
- - {simulationPaused && mode != "Tutorial" && ( - - { - setSimulationPaused(false); - }} - > - - - +
+ {simulationPaused && ( + )} - {!simulationPaused && mode != "Tutorial" && ( - - { - setSimulationPaused(true); - }} - > - - - + {!simulationPaused && ( + )} - {simulationPaused && mode != "Tutorial" && ( - - { - setSimulationReset(!simulationReset); - }} - > - - - + {simulationPaused && ( + )} - +