diff options
Diffstat (limited to 'src')
3 files changed, 32 insertions, 33 deletions
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx index 143ff9896..5335fc1ec 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx @@ -141,8 +141,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi this.dataDoc.simulationSpeed = this.dataDoc.simulationSpeed ?? 2; this.dataDoc.simulationType = this.dataDoc.simulationType ?? "Inclined Plane"; this.dataDoc.startForces = this.dataDoc.startForces ?? []; - this.dataDoc.startPosX = this.dataDoc.startPosX ?? 0; - this.dataDoc.startPosY = this.dataDoc.startPosY ?? 0; + this.dataDoc.startPosX = this.dataDoc.startPosX ?? Math.round((this.xMax * 0.5 - 200) * 10) / 10; + this.dataDoc.startPosY = this.dataDoc.startPosY ?? this.getDisplayYPos( + (400 - this.radius) * Math.tan((26 * Math.PI) / 180) + Math.sqrt(26) + ); this.dataDoc.startVelX = this.dataDoc.startVelX ?? 0; this.dataDoc.startVelY = this.dataDoc.startVelY ?? 0; this.dataDoc.stepNumber = this.dataDoc.stepNumber ?? 0; @@ -209,6 +211,16 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi this.dataDoc.mass2 = this.dataDoc.mass2 ?? 1; // Setup simulation + this.setupSimulation() + } + + componentDidUpdate() { + this.xMax = this.layoutDoc._width*0.7 ?? 700; + this.yMax = this.layoutDoc._height*0.7 ?? 700; + this.radius = 0.05*this.layoutDoc._height ?? 50; + } + + setupSimulation = () => { if (this.dataDoc.simulationType != "Circular Motion") { this.dataDoc.startVelX = 0; this.dataDoc.setStartVelY = 0; @@ -365,18 +377,6 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi // } this.dataDoc.simulationReset = (!this.dataDoc.simulationReset); } - - - console.log("width: ", this.xMax) - console.log("height: ", this.yMax) - } - - componentDidUpdate() { - this.xMax = this.layoutDoc._width*0.7 ?? 700; - this.yMax = this.layoutDoc._height*0.7 ?? 700; - this.radius = 0.05*this.layoutDoc._height ?? 50; - console.log("width: ", this.xMax) - console.log("height: ", this.yMax) } // Helper function to go between display and real values @@ -1270,9 +1270,9 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi <div style={{ position: "fixed", - left: "10vw", - top: "95vh", - width: "50vw", + left: 0.10*this.layoutDoc._width + "px", + top: 0.95*this.layoutDoc._height + "px", + width: 0.50*this.layoutDoc._width + "px", }} > <LinearProgress /> @@ -1290,7 +1290,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi value={this.dataDoc.simulationType} onChange={(event) => { this.dataDoc.simulationType = (event.target.value); - // TODO change simulation type based on mode/type + this.setupSimulation() }} style={{ height: "2em", width: "100%", fontSize: "16px" }} > @@ -1458,8 +1458,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi value={this.dataDoc.mode} onChange={(event) => { this.dataDoc.mode = (event.target.value); - - // TODO setup simulation based on type and mode + this.setupSimulation() }} style={{ height: "2em", width: "100%", fontSize: "16px" }} > diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWall.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWall.tsx index 6e60ad85c..83dff660a 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWall.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWall.tsx @@ -18,8 +18,8 @@ export default class Wall extends React.Component<IWallProps> { } wallStyle = { - width: this.props.angleInDegrees == 0 ? this.props.length + "%" : "3%", - height: this.props.angleInDegrees == 0 ? "3%" : this.props.length + "%", + width: this.props.angleInDegrees == 0 ? this.props.length + "%" : "1%", + height: this.props.angleInDegrees == 0 ? "1%" : this.props.length + "%", position: "absolute" as "absolute", left: this.props.xPos + "%", top: this.props.yPos + "%", diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx index ab7ae8450..a5bd5a04e 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx @@ -235,7 +235,7 @@ export default class Weight extends React.Component<IWeightProps, IState> { this.setDisplayValues(); } - // Make sure weight doesn't go above max height + // Make sure weight doesn't go above max height if (prevState.updatedStartPosY != this.state.updatedStartPosY || prevProps.startVelY != this.props.startVelY) { if (this.props.dataDoc['simulationType'] == "One Weight") { let maxYPos = this.state.updatedStartPosY; @@ -401,7 +401,7 @@ export default class Weight extends React.Component<IWeightProps, IState> { w.push({ length: 70, xPos: 0, yPos: 0, angleInDegrees: 0 }); w.push({ length: 70, xPos: 0, yPos: 80, angleInDegrees: 0 }); w.push({ length: 80, xPos: 0, yPos: 0, angleInDegrees: 90 }); - w.push({ length: 80, xPos: 69.5, yPos: 0, angleInDegrees: 90 }); + w.push({ length: 85, xPos: 69.5, yPos: 0, angleInDegrees: 90 }); } this.setState({walls: w}) } @@ -415,14 +415,14 @@ export default class Weight extends React.Component<IWeightProps, IState> { } } - // Update y position when start pos y changes - if (prevProps.startPosY != this.props.startPosY) { - if (this.props.paused) { - // this.setState({yPosition: this.props.startPosY}) - // this.setState({updatedStartPosY: this.props.startPosY}) - this.props.dataDoc['positionYDisplay'] = this.props.startPosY - } - } + // Update y position when start pos y changes TODO debug + // if (prevProps.startPosY != this.props.startPosY) { + // if (this.props.paused) { + // this.setState({yPosition: this.props.startPosY}) + // this.setState({updatedStartPosY: this.props.startPosY}) + // this.props.dataDoc['positionYDisplay'] = this.getDisplayYPos(this.props.startPosY) + // } + // } // Update wedge coordinates if (prevProps.wedgeWidth != this.props.wedgeWidth || prevProps.wedgeHeight != this.props.wedgeHeight) { @@ -1276,7 +1276,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.yMax - 40) + "px", + top: Math.round(this.props.yMax - 40) + "px", }} > {Math.round( |