3-8, 3-31, 3-32, and throwing a ball
This commit is contained in:
144
3-31.html
Normal file
144
3-31.html
Normal file
@@ -0,0 +1,144 @@
|
||||
<!--
|
||||
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>
|
||||
Exercise 3-31
|
||||
</title>
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
}
|
||||
|
||||
canvas {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
</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>
|
||||
|
||||
<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 = 1;
|
||||
var y1 = 0;
|
||||
var y2 = 0;
|
||||
var v1 = 0;
|
||||
var v2 = 0;
|
||||
var a1 = g / 5;
|
||||
var a2 = -2 * g /5;
|
||||
var n = 1;
|
||||
var dist = 150;
|
||||
//Relative position of canvas
|
||||
var xPos = 0;
|
||||
var yPos = 200;
|
||||
//Moves and scales canvas
|
||||
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
||||
ctx.scale(1, -1);
|
||||
Reset();
|
||||
|
||||
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;
|
||||
y1 += v1 * dt;
|
||||
y2 += v2 * dt;
|
||||
if (y2 > dist - 20)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
setTimeout(Update, 5);
|
||||
}
|
||||
|
||||
function Reset()
|
||||
{
|
||||
y1 = 0;
|
||||
y2 = 0;
|
||||
v1 = 0;
|
||||
v2 = 0;
|
||||
}
|
||||
|
||||
function Draw()
|
||||
{
|
||||
ctx.strokeStyle = '#000000';
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-c.width, yPos + 50);
|
||||
ctx.lineTo(c.width, yPos + 50);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos, yPos + 50);
|
||||
ctx.lineTo(xPos, yPos);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos, yPos, 20, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos - 20, yPos - dist * 2 + y1);
|
||||
ctx.lineTo(xPos - 20, yPos);
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#888888";
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos + 10, yPos - dist * 2 + y1, 30, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = "#000000";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + 20, yPos - dist + y2);
|
||||
ctx.lineTo(xPos + 20, yPos);
|
||||
ctx.stroke();
|
||||
ctx.fillStyle = "#888888";
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos + 40, yPos - dist + y2, 20, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.fillStyle = "#000000";
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + 40, yPos - dist + y2);
|
||||
ctx.lineTo(xPos + 40, yPos - dist * 2 + y1);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + 60, yPos - dist + y2);
|
||||
ctx.lineTo(xPos + 60, yPos + 50);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener('resize', function(event) {
|
||||
c.width = window.innerWidth;
|
||||
c.height = window.innerHeight;
|
||||
ctx.translate(c.width / 2, c.height / 2);
|
||||
ctx.scale(1, -1);
|
||||
}, 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>
|
||||
157
3-32.html
Normal file
157
3-32.html
Normal file
@@ -0,0 +1,157 @@
|
||||
<!--
|
||||
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>
|
||||
Exercise 3-32
|
||||
</title>
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
}
|
||||
|
||||
canvas {
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
</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>
|
||||
|
||||
<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 = 1;
|
||||
var y1 = 0;
|
||||
var y2 = 0;
|
||||
var yp = 0;
|
||||
var v1 = 0;
|
||||
var v2 = 0;
|
||||
var vp = 0;
|
||||
var a1 = -g;
|
||||
var a2 = -g;
|
||||
var ap = -3 * g;
|
||||
var n = 1;
|
||||
var dist = 100;
|
||||
//Relative position of canvas
|
||||
var xPos = 0;
|
||||
var yPos = 200;
|
||||
//Moves and scales canvas
|
||||
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
||||
ctx.scale(1, -1);
|
||||
Reset();
|
||||
|
||||
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;
|
||||
vp += ap * dt;
|
||||
y1 += v1 * dt;
|
||||
y2 += v2 * dt;
|
||||
yp += vp * dt;
|
||||
if (Math.abs(yp - (y2 - dist * 2)) < 20)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
setTimeout(Update, 5);
|
||||
}
|
||||
|
||||
function Reset()
|
||||
{
|
||||
y1 = 0;
|
||||
y2 = 0;
|
||||
yp = 0;
|
||||
v1 = 0;
|
||||
v2 = 0;
|
||||
vp = 0;
|
||||
}
|
||||
|
||||
function Draw()
|
||||
{
|
||||
ctx.strokeStyle = '#000000';
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-c.width, yPos + 50);
|
||||
ctx.lineTo(c.width, yPos + 50);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos, yPos + 50);
|
||||
ctx.lineTo(xPos, yPos);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos, yPos, 30, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos - 30, yPos - dist + yp);
|
||||
ctx.lineTo(xPos - 30, yPos);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos - 30, yPos - dist + yp, 20, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos - 50, yPos - dist + yp);
|
||||
ctx.lineTo(xPos - 50, yPos - dist * 3 + y1);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos - 50, yPos - dist * 3 + y1, 5, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos + 10, yPos - dist * 3 + y2, 20, 0, Math.PI * 2);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos - 10, yPos - dist * 3 + y2);
|
||||
ctx.lineTo(xPos - 10, yPos - dist + yp);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + 30, yPos - dist * 3 + y2);
|
||||
ctx.lineTo(xPos + 30, yPos);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + 10, yPos - dist * 3 + y2);
|
||||
ctx.lineTo(xPos + 10, yPos - dist * 3.5 + y2);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.arc(xPos + 10, yPos - dist * 3.5 + y2, 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(1, -1);
|
||||
}, 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>
|
||||
139
3-8.html
Normal file
139
3-8.html
Normal file
@@ -0,0 +1,139 @@
|
||||
<!--
|
||||
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-8
|
||||
</title>
|
||||
<style>
|
||||
html, body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
border: 0;
|
||||
overflow: hidden;
|
||||
display: block;
|
||||
}
|
||||
|
||||
canvas {
|
||||
position: absolute;
|
||||
}
|
||||
</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>
|
||||
|
||||
<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 = 200;
|
||||
var mPlane = 0.5;
|
||||
var mBlock = 1;
|
||||
var th = Math.PI / 6;
|
||||
var planeLength = 100;
|
||||
var blockSideLength = 10;
|
||||
var planePosition = 0;
|
||||
var blockPositionX = 0;
|
||||
var blockPositionY = 0;
|
||||
var planeVelocity = 0;
|
||||
var blockVelocityX = 0;
|
||||
var blockVelocityY = 0;
|
||||
var planeAcceleration = 0;
|
||||
var blockAccelerationX = 0;
|
||||
var blockAccelerationY = 0;
|
||||
calcAccelerations();
|
||||
//Relative position of canvas
|
||||
var xPos = 0;
|
||||
var yPos = 0;
|
||||
//Moves and scales canvas
|
||||
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
||||
ctx.scale(1, -1);
|
||||
|
||||
function calcAccelerations()
|
||||
{
|
||||
planeAcceleration = -mBlock * g * Math.sin(th) * Math.cos(th) / (mPlane + mBlock * Math.sin(th) * Math.sin(th));
|
||||
blockAccelerationX = -planeAcceleration * mPlane / mBlock;
|
||||
blockAccelerationY = -g - (mPlane * planeAcceleration * Math.cos(th)) / (mBlock * Math.sin(th));
|
||||
}
|
||||
|
||||
function Reset()
|
||||
{
|
||||
planePosition = 0;
|
||||
blockPositionX = 0;
|
||||
blockPositionY = 0;
|
||||
planeVelocity = 0;
|
||||
blockVelocityX = 0;
|
||||
blockVelocityY = 0;
|
||||
calcAccelerations();
|
||||
}
|
||||
Reset();
|
||||
|
||||
function Clear(ctx)
|
||||
{
|
||||
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
||||
}
|
||||
|
||||
function Update()
|
||||
{
|
||||
Clear(ctx);
|
||||
Draw();
|
||||
t += dt;
|
||||
if (t > 0.7)
|
||||
{
|
||||
//Reset();
|
||||
}
|
||||
planeVelocity += planeAcceleration * dt;
|
||||
planePosition += planeVelocity * dt;
|
||||
blockVelocityX += blockAccelerationX * dt;
|
||||
blockVelocityY += blockAccelerationY * dt;
|
||||
blockPositionX += blockVelocityX * dt;
|
||||
blockPositionY += blockVelocityY * dt;
|
||||
setTimeout(Update, 1000/60);
|
||||
}
|
||||
|
||||
function Draw()
|
||||
{
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-c.width, yPos);
|
||||
ctx.lineTo(c.width, yPos);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(planePosition, yPos);
|
||||
ctx.lineTo(planePosition, yPos + Math.tan(th) * planeLength);
|
||||
ctx.lineTo(planePosition + planeLength, yPos);
|
||||
ctx.stroke();
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + blockPositionX + planeLength - 90, yPos + blockPositionY + 90 * Math.tan(th));
|
||||
ctx.lineTo(xPos + blockPositionX + planeLength - 90 + blockSideLength * Math.cos(Math.PI / 2 - th), yPos + blockPositionY + 90 * Math.tan(th) + blockSideLength * Math.sin(Math.PI / 2 - th));
|
||||
ctx.lineTo(xPos + blockPositionX + planeLength - 90 + blockSideLength * (Math.cos(Math.PI / 2 - th) + Math.cos(th)), yPos + blockPositionY + 90 * Math.tan(th) + blockSideLength * (Math.sin(Math.PI / 2 - th) - Math.sin(th)));
|
||||
ctx.lineTo(xPos + blockPositionX + planeLength - 90 + blockSideLength * Math.cos(th), yPos + blockPositionY + 90 * Math.tan(th) - blockSideLength * Math.sin(th));
|
||||
ctx.lineTo(xPos + blockPositionX + planeLength - 90, yPos + blockPositionY + 90 * Math.tan(th));
|
||||
ctx.stroke();
|
||||
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener('resize', function(event) {
|
||||
c.width = window.innerWidth;
|
||||
c.height = window.innerHeight;
|
||||
ctx.translate(c.width / 2, c.height / 2);
|
||||
ctx.scale(1, -1);
|
||||
}, 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>
|
||||
40
index.html
40
index.html
@@ -67,6 +67,14 @@
|
||||
<t>Chapter 3: Using F=ma</t>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href='throwingABall.html'>Throwing a Ball Example</a>
|
||||
</td>
|
||||
<td>
|
||||
<t>Maximization of distance with relation to ground slope</t>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href='3-1.html'>Problem 3-1</a>
|
||||
@@ -91,6 +99,14 @@
|
||||
<t>Infinite Atwood's machine</t>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href='3-8.html'>Problem 3-8</a>
|
||||
</td>
|
||||
<td>
|
||||
<t>Block on a moving inclined plane</t>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href='3-11.html'>Problem 3-11</a>
|
||||
@@ -123,6 +139,30 @@
|
||||
<t>Yet another Atwood's machine</t>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href='3-30.html'>Problem 3-30</a>
|
||||
</td>
|
||||
<td>
|
||||
<t>ANOTHER Atwood's machine</t>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href='3-31.html'>Problem 3-31</a>
|
||||
</td>
|
||||
<td>
|
||||
<t>Haven't there been enough Atwood's machines yet?</t>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href='3-32.html'>Problem 3-32</a>
|
||||
</td>
|
||||
<td>
|
||||
<t>Nope, one more</t>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<p xmlns:cc="http://creativecommons.org/ns#" >
|
||||
This work is licensed under
|
||||
|
||||
156
throwingABall.html
Normal file
156
throwingABall.html
Normal file
@@ -0,0 +1,156 @@
|
||||
<!--
|
||||
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>
|
||||
Throwing a Ball
|
||||
</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>Beta</t>
|
||||
<input type="range" min="-1.57" max="1.57" value="0" step="0.01" class="greenSlider" id="wRSlider">
|
||||
</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.01;
|
||||
var t = 0;
|
||||
var beta = 0;
|
||||
var g = 98;
|
||||
var v0 = 100;
|
||||
var thetaStep = Math.PI / 20;
|
||||
var maxTheta = (Math.PI / 2 + beta) / 2;
|
||||
var xPos = 0;
|
||||
var yPos = 0;
|
||||
//Moves and scales canvas
|
||||
ctx.translate(ctx.canvas.width / 2, ctx.canvas.height / 2)
|
||||
ctx.scale(2, -2);
|
||||
Reset();
|
||||
|
||||
wRSlider.oninput = function()
|
||||
{
|
||||
beta = parseFloat(this.value);
|
||||
maxTheta = (Math.PI / 2 + beta) / 2;
|
||||
Reset();
|
||||
}
|
||||
|
||||
function Clear(ctx)
|
||||
{
|
||||
ctx.clearRect(-c.width, -c.height, c.width * 2, c.height * 2);
|
||||
}
|
||||
|
||||
function Update()
|
||||
{
|
||||
//Clear(ctx);
|
||||
Draw();
|
||||
t += dt;
|
||||
setTimeout(Update, 1);
|
||||
}
|
||||
|
||||
function Reset()
|
||||
{
|
||||
Clear(ctx);
|
||||
t = 0;
|
||||
ctx.strokeStyle = "#000000";
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(-c.width, -c.width * Math.tan(beta));
|
||||
ctx.lineTo(c.width, c.width * Math.tan(beta));
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function Draw()
|
||||
{
|
||||
for (i = 0; i < Math.PI / 2; i += thetaStep)
|
||||
{
|
||||
if (v0 * Math.sin(i) * t - g * (t ** 2) / 2 >= v0 * Math.cos(i) * t * Math.tan(beta))
|
||||
{
|
||||
ctx.strokeStyle = "#000000";
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + v0 * Math.cos(i) * t, yPos + v0 * Math.sin(i) * t - g * (t ** 2) / 2);
|
||||
ctx.lineTo(xPos + v0 * Math.cos(i) * (t+dt), yPos + v0 * Math.sin(i) * (dt + t) - g * ((t + dt) ** 2) / 2);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
if (v0 * Math.sin(maxTheta) * t - g * (t ** 2) / 2 >= v0 * Math.cos(maxTheta) * t * Math.tan(beta))
|
||||
{
|
||||
ctx.strokeStyle = "#ee0000";
|
||||
ctx.lineWidth = 2;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(xPos + v0 * Math.cos(maxTheta) * t, yPos + v0 * Math.sin(maxTheta) * t - g * (t ** 2) / 2);
|
||||
ctx.lineTo(xPos + v0 * Math.cos(maxTheta) * (t+dt), yPos + v0 * Math.sin(maxTheta) * (dt + t) - g * ((t + dt) ** 2) / 2);
|
||||
ctx.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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>
|
||||
Reference in New Issue
Block a user