updated pendulum
This commit is contained in:
parent
db5d25c370
commit
c888d1188b
|
@ -19,9 +19,14 @@
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
margin-right: auto;
|
margin-right: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
<p id="inst">Use your mouse to create a simple, closed polygon.</p>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -146,11 +146,6 @@ function centerOfMass(samples) {
|
||||||
sum.mult(h);
|
sum.mult(h);
|
||||||
sum.mult(1 / m);
|
sum.mult(1 / m);
|
||||||
|
|
||||||
L = sum.dist(attachPoint);
|
|
||||||
var helper = createVector(attachPoint.x, attachPoint.y);
|
|
||||||
helper.sub(sum);
|
|
||||||
theta = helper.angleBetween(createVector(0, -1));
|
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,10 +189,25 @@ function draw()
|
||||||
|
|
||||||
// Draw lines between vertices
|
// Draw lines between vertices
|
||||||
stroke(255);
|
stroke(255);
|
||||||
points.forEach(function(item, index) {
|
fill(230, 50, 50);
|
||||||
if(index !== points.length - 1)
|
if(!shapeComplete)
|
||||||
line(item.x, item.y, points[index + 1].x, points[index + 1].y);
|
{
|
||||||
});
|
points.forEach(function(item, index) {
|
||||||
|
if(index !== points.length - 1)
|
||||||
|
line(item.x, item.y, points[index + 1].x, points[index + 1].y);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
beginShape();
|
||||||
|
points.forEach(function(item, index) {
|
||||||
|
vertex(item.x, item.y);
|
||||||
|
});
|
||||||
|
endShape()
|
||||||
|
|
||||||
|
fill(50, 50, 255);
|
||||||
|
rect(centerMass.x - 5, centerMass.y - 5, 10, 10);
|
||||||
|
}
|
||||||
|
|
||||||
if(!shapeComplete)
|
if(!shapeComplete)
|
||||||
{
|
{
|
||||||
|
@ -232,9 +242,6 @@ function draw()
|
||||||
{
|
{
|
||||||
fill(50, 255, 50);
|
fill(50, 255, 50);
|
||||||
rect(attachPoint.x - 5, attachPoint.y - 5, 10, 10);
|
rect(attachPoint.x - 5, attachPoint.y - 5, 10, 10);
|
||||||
|
|
||||||
fill(50, 50, 255);
|
|
||||||
rect(centerMass.x - 5, centerMass.y - 5, 10, 10);
|
|
||||||
|
|
||||||
simulate();
|
simulate();
|
||||||
}
|
}
|
||||||
|
@ -254,13 +261,21 @@ function handleClick(event)
|
||||||
shapeComplete = true;
|
shapeComplete = true;
|
||||||
inertia = momentOfInertia(100);
|
inertia = momentOfInertia(100);
|
||||||
console.log("Moment of inertia: " + inertia + " ML²");
|
console.log("Moment of inertia: " + inertia + " ML²");
|
||||||
|
centerMass = centerOfMass(100);
|
||||||
|
|
||||||
|
document.getElementById("inst").innerHTML = "Use your mouse to select the pivot point."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(!attachPointSelected)
|
else if(!attachPointSelected)
|
||||||
{
|
{
|
||||||
attachPoint = createVector(mouseX, mouseY);
|
attachPoint = createVector(mouseX, mouseY);
|
||||||
attachPointSelected = true;
|
attachPointSelected = true;
|
||||||
centerMass = centerOfMass(100);
|
|
||||||
// simulate();
|
L = centerMass.dist(attachPoint);
|
||||||
|
var helper = createVector(attachPoint.x, attachPoint.y);
|
||||||
|
helper.sub(centerMass);
|
||||||
|
theta = helper.angleBetween(createVector(0, -1));
|
||||||
|
|
||||||
|
document.getElementById("inst").innerHTML = "Refresh the website to try another shape."
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue