-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroatingDisc.js
69 lines (57 loc) · 2 KB
/
roatingDisc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function roatingDisc() {
this.discMagnets = [];
this.MagnetsPositions = [];
this.discAngle = 0;
this.center = createVector();
this.Inertia = 2000000;
this.ForcedSpeed = 0;
this.vel = 0;
this.acc = 0;
this.moment = 0;
this.addMagnet = function (m, angle, r) {
this.discMagnets.push(m);
this.MagnetsPositions.push([ angle, r]);
}
this.DrawDisc = function () {
fill(0)
strokeWeight(1)
stroke(0)
ellipse(this.center.x, this.center.y, 20,20);
for (var i = 0; i < this.discMagnets.length; i++) {
this.discMagnets[i].location.x = this.center.x + (this.MagnetsPositions[i][1] * cos(this.discAngle + this.MagnetsPositions[i][0]));
this.discMagnets[i].location.y = this.center.y + (this.MagnetsPositions[i][1] * sin(this.discAngle + this.MagnetsPositions[i][0]));
this.discMagnets[i].display();
this.discMagnets[i].drawArrow();
stroke(0);
strokeWeight(1)
line(this.discMagnets[i].location.x, this.discMagnets[i].location.y, this.center.x, this.center.y);
}
}
this.updateposition = function () {
this.acc = this.moment / this.Inertia;
// console.log(this.vel);
if (this.ForcedSpeed == 0){
this.vel += this.acc;
}else {
this.vel = this.ForcedSpeed;
};
var ss = this.discAngle + this.vel;
this.acc = 0;
this.moment = 0;
this.discAngle = ss - TWO_PI * Math.floor(ss / TWO_PI);
}
this.momentCalc = function (magnets) {
var M = 0;
if (magnets) {
for (var i = 0; i < this.discMagnets.length; i++) {
this.discMagnets[i].resultant(magnets);
var r = p5.Vector.sub(this.discMagnets[i].location, this.center);
this.discMagnets[i].torqueShare = p5.Vector.dot(createVector(0, 0, 1), p5.Vector.cross(r, this.discMagnets[i].Force_state));
M += this.discMagnets[i].torqueShare;
}
}
M = 1e-8 * round(M * 1e8);
this.moment = M;
// console.log(this.moment);
}
}