-
Notifications
You must be signed in to change notification settings - Fork 0
/
plots.js
72 lines (59 loc) · 2.06 KB
/
plots.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
70
71
72
let minMargin = 50;
let margins = Array(4);
function viewMesh() {
noFill();
stroke(255);
strokeWeight(1);
createMargins();
let l = (margins[2]-margins[0])/mesh.nelx;
let h = (margins[1]-margins[3])/mesh.nely;
mesh.con.vals.forEach((nod,index)=>{
if (index%4==3) {
let xp = map(mesh.x[nod],0,mesh.L,margins[0],margins[2]);
let yp = map(mesh.y[nod],0,mesh.H,margins[1],margins[3]);
rect(xp,yp,l,h);
}
});
}
function viewMargins() {
let margin = minMargin - 5;
noFill();
stroke(255);
strokeWeight(1);
rect(margin,margin,width-2*margin,height-2*margin);
}
function createMargins() {
let marginY = height/2 - (mesh.H/mesh.L)*(width -2*minMargin)/2;
let marginX = width/2 - (mesh.L/mesh.H)*(height-2*minMargin)/2
if (marginY > minMargin || marginX < minMargin) {
margins[0] = minMargin;
margins[2] = width - minMargin;
margins[1] = height - marginY;
margins[3] = marginY;
} else {
margins[0] = marginX;
margins[2] = width - marginX;
margins[1] = height - minMargin;
margins[3] = minMargin;
}
}
function viewDisplacements() {
noFill();
stroke(255,100,100);
strokeWeight(1);
createMargins();
for(let row = 0 ; row < mesh.con.rows ; row++) {
let element = mesh.con.vals.slice(row*4,(row+1)*4);
element.forEach((nod,index) => {
let u1 = mesh.x[nod] + fact*U.vals[nod*2];
let u2 = mesh.x[element[(index+1)%4]] + fact*U.vals[element[(index+1)%4]*2]
let v1 = mesh.y[nod] + fact*U.vals[nod*2+1];
let v2 = mesh.y[element[(index+1)%4]] + fact*U.vals[element[(index+1)%4]*2+1]
let x1 = map(u1,0,mesh.L,margins[0],margins[2]);
let x2 = map(u2,0,mesh.L,margins[0],margins[2]);
let y1 = map(v1,0,mesh.H,margins[1],margins[3]);
let y2 = map(v2,0,mesh.H,margins[1],margins[3]);
line(x1,y1,x2,y2);
})
}
}