-
Notifications
You must be signed in to change notification settings - Fork 0
/
VectorField2D.js
55 lines (44 loc) · 1.15 KB
/
VectorField2D.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
class VectorField
{
constructor(FieldWidth, FieldHeight, Rows, Cols, Offset)
{
this.FieldWidth = FieldWidth;
this.FieldHeight = FieldHeight;
this.Rows = Rows;
this.Cols = Cols;
this.VectorArray = [];
this.Offset = Offset;
this.LoadArray();
}
LoadArray()
{
for(let i = 0; i < this.Cols; i++)
{
this.VectorArray[i] = [];
for(let j = 0; j < this.Rows; j++)
{
let yPos = map(i, 0, this.Cols, 0, this.FieldHeight);
let xPos = map(j, 0, this.Rows, 0, this.FieldWidth);
this.VectorArray[i][j] = new FieldVector(this.Offset.copy().add(createVector(xPos, yPos)));
}
}
}
Show()
{
for(let i = 0; i < this.Cols; i++)
{
for(let j = 0; j < this.Rows; j++)
{
this.VectorArray[i][j].Show();
}
}
}
UpdateVectors(Mag, scale = 4000) {
for (let i = 0; i < this.Cols; i++) {
for (let j = 0; j < this.Rows; j++) {
const magneticField = Mag.CalculateMagneticField(this.VectorArray[i][j].Pos);
this.VectorArray[i][j].StrengthVec = magneticField.normalize().mult(5);
}
}
}
}