-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmarchingclasses.js
63 lines (54 loc) · 1.42 KB
/
marchingclasses.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
class MData{
constructor(){
this.normals = [];
this.vertices = [];
}
}
class GridCell
{
constructor(){
this.P = [ [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0], [0,0,0] ];
this.Density = [0,0,0,0, 0,0,0,0];
}
}
class Triangle
{
constructor(){
this.P = [
[0,0,0],
[0,0,0],
[0,0,0]
];
}
}
function cross(a, b) {
return [a[1] * b[2] - a[2] * b[1],
a[2] * b[0] - a[0] * b[2],
a[0] * b[1] - a[1] * b[0]];
}
function normalize(v) {
var length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
// make sure we don't divide by 0.
if (length > 0.00001) {
return [v[0] / length, v[1] / length, v[2] / length];
} else {
return [1, 1, 1];
}
}
function subtractVectors(a, b) {
return [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
}
function VertexInterp(IsoLevel, p1, p2, valp1, valp2)
{
var mu = 0;
var p = [0,0,0];
if (Math.abs(IsoLevel - valp1) < 0.00001)
return p1;
if (Math.abs(IsoLevel - valp2) < 0.00001)
return p2;
if (Math.abs(valp1 - valp2) < 0.00001)
return p1;
mu = (IsoLevel - valp1) / (valp2 - valp1);
p = [p1[0] + mu * (p2[0] - p1[0]), p1[1] + mu * (p2[1] - p1[1]), p1[2] + mu * (p2[2] - p1[2])];
return p;
}