|
|
@ -5,15 +5,16 @@ class Pendulum { |
|
|
|
|
|
|
|
|
|
|
|
size: number; |
|
|
|
size: number; |
|
|
|
|
|
|
|
|
|
|
|
constructor(readonly M: number[], readonly L: number[], readonly color: p5.Color) { |
|
|
|
constructor(readonly M: number[], readonly L: number[], readonly color: p5.Color, startAngle: number) { |
|
|
|
console.assert(M.length === L.length, M, L, "Masses and Lengths are not of equal length!"); |
|
|
|
console.assert(M.length === L.length, M, L, "Masses and Lengths are not of equal length!"); |
|
|
|
|
|
|
|
|
|
|
|
this.size = M.length; |
|
|
|
this.size = M.length; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startAngle *= Math.PI / 180; |
|
|
|
|
|
|
|
let direction = new Vector(Math.sin(startAngle), Math.cos(startAngle)); |
|
|
|
let currentPosition = new Vector(0, 0); |
|
|
|
let currentPosition = new Vector(0, 0); |
|
|
|
for (let i = 0; i < this.size; i++){ |
|
|
|
for (let i = 0; i < this.size; i++){ |
|
|
|
let a = Math.sqrt(L[i] * L[i] / 2); |
|
|
|
currentPosition.add(Vector.Mult(direction, L[i])); |
|
|
|
currentPosition.addC(-L[i], 0); |
|
|
|
|
|
|
|
this.X.push(currentPosition.copy()); |
|
|
|
this.X.push(currentPosition.copy()); |
|
|
|
this.V.push(new Vector(0, 0)); |
|
|
|
this.V.push(new Vector(0, 0)); |
|
|
|
} |
|
|
|
} |
|
|
@ -78,13 +79,18 @@ class Pendulum { |
|
|
|
p.strokeWeight(1); |
|
|
|
p.strokeWeight(1); |
|
|
|
p.fill(255); |
|
|
|
p.fill(255); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let scale = p.height / Manager.Size; |
|
|
|
let p1 = new Vector(0, 0); |
|
|
|
let p1 = new Vector(0, 0); |
|
|
|
for (let p2 of this.X){ |
|
|
|
for (let p2 of this.X){ |
|
|
|
|
|
|
|
p2 = p2.copy(); |
|
|
|
|
|
|
|
p2.mult(scale); |
|
|
|
p.line(p1.x, p1.y, p2.x, p2.y); |
|
|
|
p.line(p1.x, p1.y, p2.x, p2.y); |
|
|
|
p1 = p2.copy(); |
|
|
|
p1 = p2.copy(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (let p2 of this.X){ |
|
|
|
for (let p2 of this.X){ |
|
|
|
|
|
|
|
p2 = p2.copy(); |
|
|
|
|
|
|
|
p2.mult(scale); |
|
|
|
p.ellipse(p2.x, p2.y, 10, 10); |
|
|
|
p.ellipse(p2.x, p2.y, 10, 10); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|