forked from unconed/mathbox
/
cartesian4.html
132 lines (113 loc) · 2.96 KB
/
cartesian4.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>MathBox - 4D Cartesian w/ projection</title>
<script src="../../build/mathbox-bundle.js"></script>
<link rel="stylesheet" href="../../build/mathbox.css">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
</head>
<body>
<script>
mathbox = mathBox({
plugins: ['core', 'controls', 'cursor'],
controls: {
klass: THREE.OrbitControls
},
});
three = mathbox.three;
three.camera.position.set(2.3, 1, 2);
three.renderer.setClearColor(new THREE.Color(0xFFFFFF), 1.0);
view = mathbox.transform4({
matrix: [
1, 0, 0, .577,
0, 1, 0, .577,
0, 0, 1, .577,
0, 0, 0, 1,
],
}).cartesian4({
range: [[-1, 1], [-1, 1], [-1, 1], [-1, 1]],
scale: [1, 1, 1, 1],
});
view.axis({
axis: 1,
});
view.grid({
axes: [1, 3],
width: 4,
});
view.axis({
axis: 2,
});
view.axis({
axis: 3,
});
view.axis({
axis: 4,
});
// Native 4D
view.area({
rangeX: [-π, π],
rangeY: [-1, 1],
width: 32,
height: 8,
expr: function (emit, x, y, i, j, time) {
θ = π / 2 * (
Math.cos(time * .31 + Math.cos(time * .481 - Math.sin(time * .318)) + Math.sin(time * 1.179))
+ Math.cos(time * .61 - Math.sin(time * .305 - Math.cos(time * .573)) + Math.cos(time * 0.962))
)
ϕ = time + Math.sin(time * .51 - Math.cos(time * .527 + Math.sin(time * .113)) + Math.sin(time * 1.224))
ξ1 = ϕ + y / 2
ξ2 = x
η = θ
sum = ξ1 + ξ2
diff = ξ1 - ξ2
s = Math.sin(η)
c = Math.cos(η)
x = Math.cos(sum) * s
y = Math.sin(sum) * s
z = Math.cos(diff) * c
w = Math.sin(diff) * c
emit(x, y, z, w);
},
channels: 4,
});
view.line({
color: 0x3080FF,
width: 10,
});
// Manual 4D -> 3D
view.area({
rangeX: [-π, π],
rangeY: [-1, 1],
width: 96,
height: 8,
expr: function (emit, x, y, i, j, time) {
θ = π / 2 * (
Math.cos(time * .31 + Math.cos(time * .481 - Math.sin(time * .318)) + Math.sin(time * 1.179))
+ Math.cos(time * .61 - Math.sin(time * .305 - Math.cos(time * .573)) + Math.cos(time * 0.962))
)
ϕ = time + Math.sin(time * .51 - Math.cos(time * .527 + Math.sin(time * .113)) + Math.sin(time * 1.224))
ξ1 = ϕ + y / 2
ξ2 = x
η = θ
sum = ξ1 + ξ2
diff = ξ1 - ξ2
s = Math.sin(η)
c = Math.cos(η)
x = Math.cos(sum) * s
y = Math.sin(sum) * s
z = Math.cos(diff) * c
w = Math.sin(diff) * c
s = .577
emit(x + w * s, y + w * s, z + w * s, 0);
},
channels: 4,
});
view.point({
color: 0xc02050,
size: 20,
});
</script>
</body>
</html>