aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/PhysicsSimulationApp.tsx
diff options
context:
space:
mode:
authorbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-02-07 12:58:32 -0500
committerbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-02-07 12:58:32 -0500
commit2387225f18bd63f70569df7039af445064738836 (patch)
tree69439252d3967dd74d98985b826cd3fa25399a10 /src/client/views/nodes/PhysicsSimulationApp.tsx
parent983ffa5e10abd89448e8b3f9be65894c7b775d84 (diff)
free weight and wedge work
Diffstat (limited to 'src/client/views/nodes/PhysicsSimulationApp.tsx')
-rw-r--r--src/client/views/nodes/PhysicsSimulationApp.tsx55
1 files changed, 21 insertions, 34 deletions
diff --git a/src/client/views/nodes/PhysicsSimulationApp.tsx b/src/client/views/nodes/PhysicsSimulationApp.tsx
index a2490cce8..f31d92db2 100644
--- a/src/client/views/nodes/PhysicsSimulationApp.tsx
+++ b/src/client/views/nodes/PhysicsSimulationApp.tsx
@@ -71,8 +71,7 @@ export default class App extends React.Component<{}, IState> {
xMax = 300;
yMax = 300;
color = `rgba(0,0,0,0.5)`;
- radius = 50
-
+ radius = 0.1*this.yMax
constructor(props: any) {
super(props)
@@ -112,8 +111,8 @@ export default class App extends React.Component<{}, IState> {
wallPositions: [],
wedge: false,
wedgeAngle: 26,
- wedgeHeight: Math.tan((26 * Math.PI) / 180) * 400,
- wedgeWidth: 400,
+ wedgeHeight: Math.tan((26 * Math.PI) / 180) * this.xMax*0.6,
+ wedgeWidth: this.xMax*0.6,
weight: false,
}
}
@@ -219,45 +218,27 @@ export default class App extends React.Component<{}, IState> {
let width = 0;
let height = 0;
if (angle < 50) {
- width = 400;
- height = Math.tan((angle * Math.PI) / 180) * 400;
+ width = this.xMax*0.6;
+ height = Math.tan((angle * Math.PI) / 180) * width;
this.setState({wedgeWidth: width})
this.setState({wedgeHeight: height})
} else if (angle < 70) {
- width = 200;
- height = Math.tan((angle * Math.PI) / 180) * 200;
+ width = this.xMax*0.3;
+ height = Math.tan((angle * Math.PI) / 180) * width;
this.setState({wedgeWidth: width})
this.setState({wedgeHeight: height})
} else {
- width = 100;
- height = Math.tan((angle * Math.PI) / 180) * 100;
+ width = this.xMax*0.15;
+ height = Math.tan((angle * Math.PI) / 180) * width;
this.setState({wedgeWidth: width})
this.setState({wedgeHeight: height})
}
// update weight position based on updated wedge width/height
- let yPos = (width - 50) * Math.tan((angle * Math.PI) / 180);
- if (angle < 40) {
- yPos += Math.sqrt(angle);
- } else if (angle < 58) {
- yPos += angle / 2;
- } else if (angle < 68) {
- yPos += angle;
- } else if (angle < 70) {
- yPos += angle * 1.3;
- } else if (angle < 75) {
- yPos += angle * 1.5;
- } else if (angle < 78) {
- yPos += angle * 2;
- } else if (angle < 79) {
- yPos += angle * 2.25;
- } else if (angle < 80) {
- yPos += angle * 2.6;
- } else {
- yPos += angle * 3;
- }
+ let xPos = (this.xMax * 0.2)-this.radius;
+ let yPos = width * Math.tan((angle * Math.PI) / 180) - this.radius;
- this.setState({startPosX: Math.round((this.xMax * 0.5 - 200) * 10) / 10});
+ this.setState({startPosX: xPos});
this.setState({startPosY: this.getDisplayYPos(yPos)});
this.updateForcesWithFriction(
Number(this.state.coefficientOfStaticFriction),
@@ -308,7 +289,7 @@ export default class App extends React.Component<{}, IState> {
componentDidMount() {
// Add weight
- this.addWeight()
+ this.addWedge()
// Add listener for SHIFT key, which determines if sketch force arrow will be edited or deleted on click
document.addEventListener("keydown", (e) => {
@@ -477,7 +458,7 @@ export default class App extends React.Component<{}, IState> {
pendulum={this.state.pendulum}
pendulumAngle={this.state.pendulumAngle}
pendulumLength={this.state.pendulumLength}
- radius={50}
+ radius={this.radius}
reset={this.state.simulationReset}
showForceMagnitudes={this.state.showForceMagnitudes}
setSketching={(val: boolean) => {this.setState({sketching: val})}}
@@ -506,13 +487,19 @@ export default class App extends React.Component<{}, IState> {
wedgeHeight={this.state.wedgeHeight}
wedgeWidth={this.state.wedgeWidth}
coefficientOfKineticFriction={this.state.coefficientOfKineticFriction}
+ xMax={this.xMax}
+ yMax={this.yMax}
+ xMin={this.xMin}
+ yMin={this.yMin}
/>
)}
{this.state.wedge && (
<Wedge
startWidth={this.state.wedgeWidth}
startHeight={this.state.wedgeHeight}
- startLeft={this.xMax * 0.5 - 200}
+ startLeft={this.xMax * 0.2}
+ xMax={this.xMax}
+ yMax={this.yMax}
/>
)}
</div>