Problems 3-1 and 3-2

This commit is contained in:
2021-08-27 20:22:01 -07:00
parent 0422ae0cf8
commit 2c8989262a
3 changed files with 439 additions and 3 deletions

View File

@@ -37,7 +37,7 @@
.greenSlider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
background: #66ff77;
background: #000000;
border-radius: 50%;
width: 15px;
height: 15px;
@@ -45,7 +45,7 @@
}
.greenSlider::-moz-range-thumb {
background: #66ff77;
background: #000000;
border-radius: 50%;
width: 15px;
height: 15px;
@@ -92,7 +92,7 @@
wRSlider.oninput = function()
{
theta = this.value;
theta = parseFloat(this.value);
w = Math.sqrt(980 / (l * Math.cos(theta)));
}

194
problem3-1.html Normal file
View File

@@ -0,0 +1,194 @@
<!--
This work is licensed under CC BY-NC-ND 4.0
Link to license: http://creativecommons.org/licenses/by-nc-nd/4.0/
Attribute to Russell Georgi
-->
<html>
<head>
<title>
Problem 3-1
</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
canvas {
position: absolute;
}
.greenSlider {
-webkit-appearance: none;
border-radius: 5px;
height: 10px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.greenSlider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
background: #000000;
border-radius: 50%;
width: 15px;
height: 15px;
cursor: pointer;
}
.greenSlider::-moz-range-thumb {
background: #000000;
border-radius: 50%;
width: 15px;
height: 15px;
cursor: pointer;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="1" height="1" style="border:1px solid #ffffff;">
Your browser does not support the HTML5 canvas tag.</canvas>
<div class="slidecontainer">
<t>M1</t>
<input type="range" min="0.1" max="5" value="1" step="0.1" class="greenSlider" id="m1Slider">
<br>
<t>M2</t>
<input type="range" min="0.1" max="5" value="2" step="0.1" class="greenSlider" id="m2Slider">
</div>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
c.width = window.innerWidth;
c.height = window.innerHeight;
//Time step
var dt = 0.002;
var t = 0;
var g = 98;
var m1 = 1;
var m2 = 2;
var y1 = 0;
var y2 = 0;
var v1 = 0;
var v2 = 0;
var a = (m2 - m1) * g / (m2 + m1);
//Relative position of canvas
var xPos = 0;
var yPos = 70;
//Moves and scales canvas
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
ctx.scale(2, -2);
m1Slider.oninput = function()
{
m1 = parseFloat(this.value);
a = (m2 - m1) * g / (m2 + m1);
Reset();
}
m2Slider.oninput = function()
{
m2 = parseFloat(this.value);
a = (m2 - m1) * g / (m2 + m1);
Reset();
}
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
Clear(ctx);
Draw();
t += dt;
v1 += a * dt;
v2 -= a * dt;
y1 += v1 * dt;
y2 += v2 * dt;
if (Math.sqrt(((100 - y1) ** 2) + (400)) < Math.sqrt(m1) + 30)
{
Reset();
}
if (Math.sqrt(((100 - y2) ** 2) + (400)) < Math.sqrt(m2) + 30)
{
Reset();
}
setTimeout(Update, 5);
}
function Reset()
{
y1 = 0;
y2 = 0;
v1 = 0;
v2 = 0;
}
function Draw()
{
ctx.beginPath();
ctx.arc(xPos, yPos, 20, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + 20, yPos);
ctx.lineTo(xPos + 20, yPos - (100 - y2));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos + 20, yPos - (100 - y2), Math.PI * Math.sqrt(m2), 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.moveTo(xPos - 20, yPos);
ctx.lineTo(xPos - 20, yPos - (100 - y1));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos - 20, yPos - (100 - y1), Math.PI * Math.sqrt(m1), 0, Math.PI * 2);
ctx.fill();
/*ctx.beginPath();
ctx.arc(xPos + lx / 2, yPos, pulleyR, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos - lx / 2, yPos, pulleyR, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + lx / 2 + pulleyR, yPos);
ctx.lineTo(xPos + lx / 2 + pulleyR + r * Math.sin(theta), yPos - r * Math.cos(theta));
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos - lx / 2 - pulleyR, yPos);
ctx.lineTo(xPos - lx / 2 - pulleyR, yPos - (250 - r));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos + lx / 2 + pulleyR + r * Math.sin(theta), yPos - r * Math.cos(theta), 5, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.arc(xPos - lx / 2 - pulleyR, yPos - (250 - r), 5, 0, Math.PI * 2);
ctx.fill();*/
}
window.addEventListener('resize', function(event) {
c.width = window.innerWidth;
c.height = window.innerHeight;
ctx.translate(c.width / 2, c.height / 2);
ctx.scale(2, -2);
}, true);
Update();
</script>
</body>
<p xmlns:cc="http://creativecommons.org/ns#" style="font-size: 1vw; bottom: 0px; position: absolute;">
This work is licensed under
<a href="http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-ND 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nd.svg?ref=chooser-v1"></a></p>
</html>

242
problem3-2.html Normal file
View File

@@ -0,0 +1,242 @@
<!--
This work is licensed under CC BY-NC-ND 4.0
Link to license: http://creativecommons.org/licenses/by-nc-nd/4.0/
Attribute to Russell Georgi
-->
<html>
<head>
<title>
Problem 3-2
</title>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0px;
border: 0;
overflow: hidden;
display: block;
}
canvas {
position: absolute;
}
.greenSlider {
-webkit-appearance: none;
border-radius: 5px;
height: 10px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
}
.greenSlider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
background: #000000;
border-radius: 50%;
width: 15px;
height: 15px;
cursor: pointer;
}
.greenSlider::-moz-range-thumb {
background: #000000;
border-radius: 50%;
width: 15px;
height: 15px;
cursor: pointer;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="1" height="1" style="border:1px solid #ffffff;">
Your browser does not support the HTML5 canvas tag.</canvas>
<div class="slidecontainer">
<t>M1</t>
<input type="range" min="0.1" max="5" value="1" step="0.1" class="greenSlider" id="m1Slider">
<br>
<t>M2</t>
<input type="range" min="0.1" max="5" value="2" step="0.1" class="greenSlider" id="m2Slider">
<br>
<t>M3</t>
<input type="range" min="0.1" max="5" value="3" step="0.1" class="greenSlider" id="m3Slider">
</div>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
c.width = window.innerWidth;
c.height = window.innerHeight;
//Time step
var dt = 0.002;
var t = 0;
var g = 98;
var m1 = 1;
var m2 = 2;
var m3 = 3;
var y1 = 0;
var y2 = 0;
var y3 = 0;
var v1 = 0;
var v2 = 0;
var v3 = 0;
var a1 = 0;
var a2 = 0;
var a3 = 0;
calcAccelerations();
//Relative position of canvas
var xPos = 0;
var yPos = 70;
//Moves and scales canvas
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
ctx.scale(2, -2);
function calcAccelerations()
{
a1 = g * (4 * m2 * m3 - m1 * (m2 + m3)) / (4 * m2 * m3 + m1 * (m2 + m3));
a2 = -g * (4 * m2 * m3 + m1 * (m2 - 3 * m3)) / (4 * m2 * m3 + m1 * (m2 + m3));
a3 = -g * (4 * m2 * m3 + m1 * (m3 - 3 * m2)) / (4 * m2 * m3 + m1 * (m2 + m3));
}
m1Slider.oninput = function()
{
m1 = parseFloat(this.value);
Reset();
calcAccelerations();
}
m2Slider.oninput = function()
{
m2 = parseFloat(this.value);
Reset();
calcAccelerations();
}
m3Slider.oninput = function()
{
m3 = parseFloat(this.value);
Reset();
calcAccelerations();
}
function Clear(ctx)
{
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
}
function Update()
{
Clear(ctx);
Draw();
t += dt;
v1 += a1 * dt;
v2 += a2 * dt;
v3 += a3 * dt;
y1 += v1 * dt;
y2 += v2 * dt;
y3 += v3 * dt;
if (y1 >= 55)
{
Reset();
}
if (75 - y2 - y1 <= 20)
{
Reset();
}
if (75 - y3 - y1 <= 20)
{
Reset();
}
if (75 + y1 <= 35)
{
Reset();
}
setTimeout(Update, 5);
}
function Reset()
{
y1 = 0;
y2 = 0;
y3 = 0;
v1 = 0;
v2 = 0;
v3 = 0;
}
function Draw()
{
ctx.beginPath();
ctx.arc(xPos, yPos, 20, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos - 20, yPos);
ctx.lineTo(xPos - 20, yPos - (75 - y1));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos - 20, yPos - (75 - y1), Math.PI * Math.sqrt(m1), 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.moveTo(xPos + 20, yPos);
ctx.lineTo(xPos + 20, yPos - (75 + y1));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos + 20, yPos - (75 + y1), 20, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos, yPos - (75 + y1));
ctx.lineTo(xPos, yPos - (150 - y2));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos, yPos - (150 - y2), Math.PI * Math.sqrt(m2), 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.moveTo(xPos + 40, yPos - (75 + y1));
ctx.lineTo(xPos + 40, yPos - (150 - y3));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos + 40, yPos - (150 - y3), Math.PI * Math.sqrt(m3), 0, Math.PI * 2);
ctx.fill();
/*ctx.beginPath();
ctx.arc(xPos + lx / 2, yPos, pulleyR, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos - lx / 2, yPos, pulleyR, 0, Math.PI * 2);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos + lx / 2 + pulleyR, yPos);
ctx.lineTo(xPos + lx / 2 + pulleyR + r * Math.sin(theta), yPos - r * Math.cos(theta));
ctx.stroke();
ctx.beginPath();
ctx.moveTo(xPos - lx / 2 - pulleyR, yPos);
ctx.lineTo(xPos - lx / 2 - pulleyR, yPos - (250 - r));
ctx.stroke();
ctx.beginPath();
ctx.arc(xPos + lx / 2 + pulleyR + r * Math.sin(theta), yPos - r * Math.cos(theta), 5, 0, Math.PI * 2);
ctx.fill();
ctx.beginPath();
ctx.arc(xPos - lx / 2 - pulleyR, yPos - (250 - r), 5, 0, Math.PI * 2);
ctx.fill();*/
}
window.addEventListener('resize', function(event) {
c.width = window.innerWidth;
c.height = window.innerHeight;
ctx.translate(c.width / 2, c.height / 2);
ctx.scale(2, -2);
}, true);
Update();
</script>
</body>
<p xmlns:cc="http://creativecommons.org/ns#" style="font-size: 1vw; bottom: 0px; position: absolute;">
This work is licensed under
<a href="http://creativecommons.org/licenses/by-nc-nd/4.0/?ref=chooser-v1" target="_blank" rel="license noopener noreferrer" style="display:inline-block;">CC BY-NC-ND 4.0<img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/cc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/by.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nc.svg?ref=chooser-v1"><img style="height:22px!important;margin-left:3px;vertical-align:text-bottom;" src="https://mirrors.creativecommons.org/presskit/icons/nd.svg?ref=chooser-v1"></a></p>
</html>