From 18b4c2ff62eb6fc3d6c1b5d0c6aeeaa785208aa6 Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 24 May 2023 12:38:21 -0400 Subject: physics cleanup for window resizing, etc --- .../nodes/PhysicsBox/PhysicsSimulationBox.tsx | 354 ++++++++------------- 1 file changed, 128 insertions(+), 226 deletions(-) (limited to 'src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx') diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx index e2b882389..c4e8e7721 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx @@ -6,8 +6,11 @@ import QuestionMarkIcon from '@mui/icons-material/QuestionMark'; import ReplayIcon from '@mui/icons-material/Replay'; import { Box, Button, Checkbox, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControl, FormControlLabel, FormGroup, IconButton, LinearProgress, Stack } from '@mui/material'; import Typography from '@mui/material/Typography'; +import { computed } from 'mobx'; import { observer } from 'mobx-react'; -import { HeightSym, NumListCast, WidthSym } from '../../../../fields/Doc'; +import { NumListCast } from '../../../../fields/Doc'; +import { List } from '../../../../fields/List'; +import { BoolCast, NumCast, StrCast } from '../../../../fields/Types'; import { ViewBoxAnnotatableComponent } from '../../DocComponent'; import { FieldView, FieldViewProps } from './../FieldView'; import './PhysicsSimulationBox.scss'; @@ -17,9 +20,6 @@ import * as tutorials from './PhysicsSimulationTutorial.json'; import Wall from './PhysicsSimulationWall'; import Weight from './PhysicsSimulationWeight'; import React = require('react'); -import { BoolCast, NumCast, StrCast } from '../../../../fields/Types'; -import { List } from '../../../../fields/List'; -import { computed, trace } from 'mobx'; interface IWallProps { length: number; @@ -82,6 +82,14 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { + return { + description: 'Gravity', + magnitude: mass * Math.abs(this.gravity), + directionInDegrees: 270, + component: false, + }; + }; @computed get simulationType() { return StrCast(this.dataDoc.simulation_type, 'Inclined Plane'); } @@ -129,6 +137,9 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { + const radAng = (angle * Math.PI) / 180; this.dataDoc.wedge_width = this.xMax * 0.5; - this.dataDoc.wedge_height = Math.tan((angle * Math.PI) / 180) * this.xMax * 0.5; + this.dataDoc.wedge_height = Math.tan(radAng) * this.dataDoc.wedge_width; // update weight position based on updated wedge width/height - let yPos = this.yMax - 0.08 * this.props.PanelHeight() * 2 - Math.tan((angle * Math.PI) / 180) * this.xMax * 0.5; + let yPos = this.yMax - this.mass1Radius * 2 - this.dataDoc.wedge_height - this.mass1Radius * Math.cos(radAng) + this.mass1Radius; + let xPos = this.xMax * 0.25 + this.mass1Radius * Math.sin(radAng) - this.mass1Radius; - // adjust y position - if (angle >= 5 && angle < 10) { - yPos += 0.08 * this.props.PanelHeight() * 0.1; - } else if (angle >= 10 && angle < 15) { - yPos += 0.08 * this.props.PanelHeight() * 0.23; - } else if (angle >= 15 && angle < 20) { - yPos += 0.08 * this.props.PanelHeight() * 0.26; - } else if (angle >= 20 && angle < 25) { - yPos += 0.08 * this.props.PanelHeight() * 0.33; - } else if (angle >= 25 && angle < 30) { - yPos += 0.08 * this.props.PanelHeight() * 0.35; - } else if (angle >= 30 && angle < 35) { - yPos += 0.08 * this.props.PanelHeight() * 0.4; - } else if (angle >= 35 && angle < 40) { - yPos += 0.08 * this.props.PanelHeight() * 0.45; - } else if (angle >= 40 && angle < 45) { - yPos += 0.08 * this.props.PanelHeight() * 0.47; - } else if (angle >= 45) { - yPos += 0.08 * this.props.PanelHeight() * 0.52; - } - - this.dataDoc.mass1_positionXstart = this.xMax * 0.25; + this.dataDoc.mass1_positionXstart = xPos; this.dataDoc.mass1_positionYstart = yPos; if (this.simulationMode == 'Freeform') { - this.updateForcesWithFriction(NumCast(this.dataDoc.coefficientOfStaticFriction), this.xMax * 0.5, Math.tan((angle * Math.PI) / 180) * this.xMax * 0.5); + this.updateForcesWithFriction(NumCast(this.dataDoc.coefficientOfStaticFriction), this.dataDoc.wedge_width, Math.tan(radAng) * this.dataDoc.wedge_width); } }; @@ -730,24 +695,8 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { this.dataDoc.simulation_showComponentForces = false; - const gravityForce: IForce = { - description: 'Gravity', - magnitude: Math.abs(this.gravity) * this.mass1, - directionInDegrees: 270, - component: false, - }; - this.dataDoc.mass1_forcesUpdated = JSON.stringify([gravityForce]); - this.dataDoc.mass1_forcesStart = JSON.stringify([gravityForce]); + this.dataDoc.mass1_forcesUpdated = JSON.stringify([this.gravityForce(this.mass1)]); + this.dataDoc.mass1_forcesStart = JSON.stringify([this.gravityForce(this.mass1)]); this.dataDoc.mass1_positionXstart = this.xMax / 2 - 0.08 * this.props.PanelHeight(); this.dataDoc.mass1_positionYstart = 200; this.dataDoc.spring_constant = 0.5; @@ -792,14 +735,9 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent )} -
+
)}
-
+
{(this.simulationType == 'One Weight' || this.simulationType == 'Inclined Plane') && this.wallPositions?.map((element, index) => )}
@@ -1708,24 +1636,8 @@ export class PhysicsSimulationBox extends ViewBoxAnnotatableComponent