aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-05-04 10:39:00 -0400
committerbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-05-04 10:39:00 -0400
commit6c1143b27293f22ef4c21ac53c6bdbda381ee09d (patch)
tree713545aa925941a20c7ca86d863cbb1194acd3e5 /src
parent7a773b075753e92112ad2d16e414eaaa8be59378 (diff)
debugging change size
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx95
-rw-r--r--src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx4
2 files changed, 33 insertions, 66 deletions
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
index 7efb8b73a..53e1cd15f 100644
--- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
+++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
@@ -111,7 +111,6 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
this.layoutDoc._height = 800;
this.xMax = this.layoutDoc._width*0.6;
this.yMax = this.layoutDoc._height*0.9;
- this.radius = 60;
this.dataDoc.reviewCoefficient = this.dataDoc.reviewCoefficient ?? 0;
this.dataDoc.questionVariables = this.dataDoc.questionVariables ?? [];
this.dataDoc.accelerationXDisplay = this.dataDoc.accelerationXDisplay ?? 0;
@@ -137,7 +136,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
this.dataDoc.startForces = this.dataDoc.startForces ?? [];
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)
+ (400 - (0.08*this.layoutDoc._height)) * Math.tan((26 * Math.PI) / 180) + Math.sqrt(26)
);
this.dataDoc.startVelX = this.dataDoc.startVelX ?? 0;
this.dataDoc.startVelY = this.dataDoc.startVelY ?? 0;
@@ -187,8 +186,8 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
this.dataDoc.coefficientOfKineticFriction = this.dataDoc.coefficientOfKineticFriction ?? 0;
this.dataDoc.coefficientOfStaticFriction = this.dataDoc.coefficientOfStaticFriction ?? 0;
this.dataDoc.wedgeAngle = this.dataDoc.wedgeAngle ?? 26;
- this.dataDoc.wedgeHeight = this.dataDoc.wedgeHeight ?? Math.tan((26 * Math.PI) / 180) * 400;
- this.dataDoc.wedgeWidth = this.dataDoc.wedgeWidth ?? 400;
+ this.dataDoc.wedgeHeight = this.dataDoc.wedgeHeight ?? Math.tan((26 * Math.PI) / 180) * this.xMax*0.5;
+ this.dataDoc.wedgeWidth = this.dataDoc.wedgeWidth ?? this.xMax*0.5;
// Used for pulley simulation
this.dataDoc.positionXDisplay2 = this.dataDoc.positionXDisplay2 ?? 0;
@@ -220,9 +219,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
if (this.xMax != this.layoutDoc._width*0.6 || this.yMax != this.layoutDoc._height*0.9) {
this.xMax = this.layoutDoc._width*0.6;
this.yMax = this.layoutDoc._height*0.9;
- this.radius = 0.08*this.layoutDoc._height ?? 60;
- this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
+ this.setupSimulation(this.dataDoc.simulationType, this.dataDoc.mode)
+ console.log('reset sim')
}
+ console.log('update')
}
setupSimulation = (simulationType: string, mode: string) => {
@@ -237,10 +237,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
this.dataDoc.showForceMagnitudes = (true);
if (simulationType == "One Weight") {
this.dataDoc.showComponentForces = false;
- this.dataDoc.startPosY = (this.yMin + this.radius);
- this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - this.radius);
- this.dataDoc.positionYDisplay = (this.getDisplayYPos(this.yMin + this.radius));
- this.dataDoc.positionXDisplay = ((this.xMax + this.xMin) / 2 - this.radius);
+ this.dataDoc.startPosY = (this.yMin + (0.08*this.layoutDoc._height));
+ this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - (0.08*this.layoutDoc._height));
+ this.dataDoc.positionYDisplay = (this.getDisplayYPos(this.yMin + (0.08*this.layoutDoc._height)));
+ this.dataDoc.positionXDisplay = ((this.xMax + this.xMin) / 2 - (0.08*this.layoutDoc._height));
this.dataDoc.updatedForces = ([
{
description: "Gravity",
@@ -325,7 +325,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
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.startPosX = ((this.xMax + this.xMin) / 2 - (0.08*this.layoutDoc._height));
this.dataDoc.selectedTutorial = (tutorials.freeWeight);
this.dataDoc.startForces = (this.getForceFromJSON(tutorials.freeWeight.steps[0].forces));
this.dataDoc.showForceMagnitudes = (tutorials.freeWeight.steps[0].showMagnitude);
@@ -333,7 +333,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
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.startPosX = ((this.xMax + this.xMin) / 2 - (0.08*this.layoutDoc._height));
this.dataDoc.selectedTutorial = (tutorials.spring);
this.dataDoc.startForces = (this.getForceFromJSON(tutorials.spring.steps[0].forces));
this.dataDoc.showForceMagnitudes = (tutorials.spring.steps[0].showMagnitude);
@@ -343,8 +343,8 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
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;
+ const xPos = this.xMax / 2 - x - (0.08*this.layoutDoc._height);
+ const yPos = y - (0.08*this.layoutDoc._height) - 5;
this.dataDoc.startPosX = (xPos);
this.dataDoc.startPosY = (yPos);
this.dataDoc.selectedTutorial = (tutorials.pendulum);
@@ -387,10 +387,10 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
// Helper function to go between display and real values
getDisplayYPos = (yPos: number) => {
- return this.yMax - yPos - 2 * this.radius + 5;
+ return this.yMax - yPos - 2 * (0.08*this.layoutDoc._height) + 5;
};
getYPosFromDisplay = (yDisplay: number) => {
- return this.yMax - yDisplay - 2 * this.radius + 5;
+ return this.yMax - yDisplay - 2 * (0.08*this.layoutDoc._height) + 5;
};
// Update forces when coefficient of static friction changes in freeform mode
@@ -492,49 +492,14 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
// Change wedge height and width and weight position to match new wedge angle
changeWedgeBasedOnNewAngle = (angle: number) => {
- let width = 0;
- let height = 0;
- if (angle < 50) {
- width = 400;
- height = Math.tan((angle * Math.PI) / 180) * 400;
- this.dataDoc.wedgeWidth = width;
- this.dataDoc.wedgeHeight = height;
- } else if (angle < 70) {
- width = 200;
- height = Math.tan((angle * Math.PI) / 180) * 200;
- this.dataDoc.wedgeWidth = width;
- this.dataDoc.wedgeHeight = height;
- } else {
- width = 100;
- height = Math.tan((angle * Math.PI) / 180) * 100;
- this.dataDoc.wedgeWidth = width;
- this.dataDoc.wedgeHeight = height;
- }
+ this.dataDoc.wedgeWidth = this.xMax*0.5;
+ this.dataDoc.wedgeHeight = Math.tan((angle * Math.PI) / 180) * this.xMax*0.5;
// update weight position based on updated wedge width/height
- let yPos = (width - this.radius) * 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 yPos = this.yMax - (0.08*this.layoutDoc._height) - Math.tan((angle * Math.PI) / 180) * this.xMax*0.5;
+
this.dataDoc.startPosX = Math.round((this.xMax * 0.5 - 200) * 10) / 10;
- this.dataDoc.startPosY = this.getDisplayYPos(yPos);
+ this.dataDoc.startPosY = yPos;
if (this.dataDoc.mode == "Freeform") {
this.updateForcesWithFriction(
Number(this.dataDoc.coefficientOfStaticFriction),
@@ -1032,8 +997,8 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
this.dataDoc.showComponentForces = (false);
this.dataDoc.startVelY = (0);
this.dataDoc.startVelX = (value);
- let xPos = (this.xMax + this.xMin) / 2 - this.radius;
- let yPos = (this.yMax + this.yMin) / 2 + this.dataDoc.circularMotionRadius - this.radius;
+ let xPos = (this.xMax + this.xMin) / 2 - (0.08*this.layoutDoc._height);
+ let yPos = (this.yMax + this.yMin) / 2 + this.dataDoc.circularMotionRadius - (0.08*this.layoutDoc._height);
this.dataDoc.startPosY = (yPos);
this.dataDoc.startPosX = (xPos);
const tensionForce: IForce = {
@@ -1053,8 +1018,8 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
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;
+ const xPos = this.xMax / 2 - x - (0.08*this.layoutDoc._height);
+ const yPos = y - (0.08*this.layoutDoc._height) - 5;
this.dataDoc.startPosX = (xPos);
this.dataDoc.startPosY = (yPos);
const mag = this.dataDoc.mass * Math.abs(this.dataDoc.gravity) * Math.sin((60 * Math.PI) / 180);
@@ -1126,7 +1091,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
};
this.dataDoc.updatedForces = ([gravityForce]);
this.dataDoc.startForces = ([gravityForce]);
- this.dataDoc.startPosX = (this.xMax / 2 - this.radius);
+ this.dataDoc.startPosX = (this.xMax / 2 - (0.08*this.layoutDoc._height));
this.dataDoc.startPosY = (200);
this.dataDoc.springConstant = (0.5);
this.dataDoc.springRestLength = (200);
@@ -1136,7 +1101,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
// Default setup for suspension simulation
setupSuspension = () => {
- let xPos = (this.xMax + this.xMin) / 2 - this.radius;
+ let xPos = (this.xMax + this.xMin) / 2 - (0.08*this.layoutDoc._height);
let yPos = this.yMin + 200;
this.dataDoc.startPosY = (yPos);
this.dataDoc.startPosX = (xPos);
@@ -1199,6 +1164,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
directionInDegrees: 90,
component: false,
};
+
this.dataDoc.updatedForces = ([gravityForce1, tensionForce1]);
this.dataDoc.startForces = ([gravityForce1, tensionForce1]);
this.dataDoc.startPosY2 = ((this.yMax + this.yMin) / 2);
@@ -1207,6 +1173,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
this.dataDoc.positionXDisplay2 = ((this.xMin + this.xMax) / 2 + 5);
this.dataDoc.updatedForces2 = ([gravityForce2, tensionForce2]);
this.dataDoc.startForces2 = ([gravityForce2, tensionForce2]);
+
this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
};
@@ -1308,7 +1275,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
paused={this.dataDoc.simulationPaused}
pendulumAngle={this.dataDoc.pendulumAngle}
pendulumLength={this.dataDoc.pendulumLength}
- radius={this.radius}
+ radius={(0.08*this.layoutDoc._height)}
reset={this.dataDoc.simulationReset}
simulationSpeed={this.dataDoc.simulationSpeed}
startPendulumAngle={this.dataDoc.startPendulumAngle}
@@ -1358,7 +1325,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
paused={this.dataDoc.simulationPaused}
pendulumAngle={this.dataDoc.pendulumAngle}
pendulumLength={this.dataDoc.pendulumLength}
- radius={this.radius}
+ radius={(0.08*this.layoutDoc._height)}
reset={this.dataDoc.simulationReset}
simulationSpeed={this.dataDoc.simulationSpeed}
startPendulumAngle={this.dataDoc.startPendulumAngle}
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx
index 85c20760e..3386bfd1c 100644
--- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx
+++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationInputField.tsx
@@ -44,10 +44,10 @@ export default class InputField extends React.Component<IInputProps, IState> {
epsilon: number = 0.01;
componentDidUpdate(prevProps: Readonly<IInputProps>, prevState: Readonly<IState>, snapshot?: any): void {
- if (prevProps.value != this.props.value) {
+ if (prevProps.value != this.props.value && !isNaN(this.props.value)) {
if (this.props.mode == "Freeform") {
if (Math.abs(this.state.tempValue - Number(this.props.value)) > 1) {
- console.log('update temp value')
+ console.log('update temp value', Number(this.props.value))
this.setState({tempValue: Number(this.props.value)})
}
}