commit 13ebc7588edd388390a19fe699da8c15fb98278d
parent 16976ddad1175e2ca9bf70cdeb5d90a82d0560ee
Author: AsherMorgan <59518073+AsherMorgan@users.noreply.github.com>
Date: Mon, 1 Mar 2021 10:23:06 -0800
Improve atwood machine simulation
Diffstat:
2 files changed, 59 insertions(+), 21 deletions(-)
diff --git a/simulations/atwood-machine.html b/simulations/atwood-machine.html
@@ -29,6 +29,10 @@
<input type="range" min="1" max="10" step="0.1" v-model.number="mass2" @input="reset" :disabled="active" id="mass2Input">
</section>
<section>
+ <label for="angleInput"><b>Angle:</b> {{ angle.toFixed(0) }}<sup>o</sup></label>
+ <input type="range" min="0" max="90" step="1" v-model.number="angle" @input="reset" :disabled="active" id="angleInput">
+ </section>
+ <section>
<label for="gravityInput"><b>Gravity:</b> {{ gravity.toFixed(1) }} m/s<sup>2</sup></label>
<input type="range" min="1" max="10" step="0.1" v-model.number="gravity" @input="reset" :disabled="active" id="gravityInput">
</section>
@@ -41,25 +45,25 @@
</div>
<div id="output" hidden>
- <svg width="200px" viewBox="0 0 4 8">
+ <svg width="400px" viewBox="0 0 8.1 8">
<!-- Pulley -->
- <circle cx="2" cy="1.1" r="1" stroke-width="0.1" stroke="#808080" fill="#404040"></circle>
+ <circle cx="1.5" cy="1.5" r="1" stroke-width="0.1" stroke="#808080" fill="#404040"></circle>
<!-- 1st weight -->
- <line x1="1" y1="1.1" x2="1" :y2="4.1 + positions[0]" stroke-width="0.1" stroke="#808080"></line>
- <circle cx="1" :cy="4.1 + positions[0]" :r="0.03*mass1+0.2" fill="#ff0000"></circle>
+ <line x1="0.5" y1="1.5" x2="0.5" :y2="4.5 + displacement" stroke-width="0.1" stroke="#808080"></line>
+ <circle cx="0.5" :cy="4.5 + displacement" :r="0.03*mass1+0.2" fill="#ff0000"></circle>
<!-- 2nd weight -->
- <line x1="3" y1="1.1" x2="3" :y2="4.1 + positions[1]" stroke-width="0.1" stroke="#808080"></line>
- <circle cx="3" :cy="4.1 + positions[1]" :r="0.03*mass2+0.2" fill="#0000ff"></circle>
+ <line :x1="positionVector[0] + 1.5" :y1="positionVector[1] + 1.5" :x2="positionVector[2] + 1.5" :y2="positionVector[3] + 1.5" stroke-width="0.1" stroke="#808080"></line>
+ <circle :cx="positionVector[2] + 1.5" :cy="positionVector[3] + 1.5" :r="0.03*mass2+0.2" fill="#0000ff"></circle>
</svg>
</div>
<div id="data" hidden>
<label><b>Time:</b> {{ time.toFixed(2) }} s</label>
- <label><b>Displacement:</b> {{ Math.abs(positions[0]).toFixed(2) }} m</label>
- <label><b>Speed:</b> {{ Math.abs(velocity).toFixed(2) }} m/s</label>
- <label><b>Acceleration:</b> {{ Math.abs(acceleration).toFixed(2) }} m/s<sup>2</sup></label>
+ <label><b>Displacement:</b> {{ Math.abs(displacement).toFixed(2) }} m</label>
+ <label><b>Velocity:</b> {{ velocity.toFixed(2) }} m/s</label>
+ <label><b>Acceleration:</b> {{ acceleration.toFixed(2) }} m/s<sup>2</sup></label>
</div>
</div>
</body>
diff --git a/simulations/atwood-machine.js b/simulations/atwood-machine.js
@@ -1,6 +1,7 @@
const App = {
data: function() {
return {
+ angle: 90, // The angle of the 2nd weight (degrees)
mass1: 1, // The mass of the 1st weight (Kg)
mass2: 10, // The mass of the 2nd weight (Kg)
gravity: 9.8, // The acceleration due to gravity (m/s/s)
@@ -12,35 +13,48 @@ const App = {
},
computed: {
/**
- * The net force on the 1st weight
+ * The net force on the 2nd weight
*/
netForce: function() {
- return (this.mass1 * this.gravity) - (this.mass2 * this.gravity);
+ let gravityX = this.getO(this.angle, this.mass2 * this.gravity);
+ let netX = (this.mass1 * this.gravity) - gravityX;
+ return netX;
},
/**
- * The acceleration of the 1st weight
+ * The acceleration of the 2nd weight
*/
acceleration: function() {
- return this.netForce / (this.mass1 + this.mass2);
+ return this.netForce / (this.mass2 + this.mass1);
},
/**
- * The velocity of the 1st weight
+ * The velocity of the 2nd weight
*/
velocity: function() {
return this.acceleration * this.time;
},
/**
- * The heights of the weights
+ * The displacement of the 2nd weight
*/
- positions: function() {
- let position = 0.5 * this.acceleration * this.time * this.time;
- if (position > 3) position = 3;
- if (position < -3) position = -3;
- if (Math.abs(position) === 3 && this.active) this.toggle();
- return [position, -position];
+ displacement: function() {
+ let result = 0.5 * this.acceleration * this.time * this.time;
+ if (result > 3) result = 3;
+ if (result < -3) result = -3;
+ if (Math.abs(result) === 3 && this.active) this.toggle();
+ return result;
+ },
+
+ /**
+ * The position of the 2nd weight
+ */
+ positionVector: function() {
+ let x1 = this.getA(this.angle - 90, 1);
+ let y1 = this.getO(this.angle - 90, 1);
+ let x2 = this.getA(this.angle, - this.displacement + 3) + x1;
+ let y2 = this.getO(this.angle, - this.displacement + 3) + y1;
+ return [x1, y1, x2, y2];
},
},
methods: {
@@ -66,6 +80,26 @@ const App = {
update: function() {
this.time += this.refreshRate;
},
+
+ /**
+ * Get the length of the opposite side of a triangle
+ * @param {Number} angle The angle in degrees
+ * @param {Number} distance The length of the hypotenuse
+ * @returns {Number} The length of the opposite side
+ */
+ getO: function(angle, distance) {
+ return Math.sin(angle / 360 * 2 * Math.PI) * distance;
+ },
+
+ /**
+ * Get the length of the adjacent side of a triangle
+ * @param {Number} angle The angle in degrees
+ * @param {Number} distance The length of the hypotenuse
+ * @returns {Number} The length of the adjacent side
+ */
+ getA: function(angle, distance) {
+ return Math.cos(angle / 360 * 2 * Math.PI) * distance;
+ },
},
}