forked from unconed/mathbox
/
quat.html
132 lines (119 loc) · 3.53 KB
/
quat.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 - Stereographic Quaternion Hypersphere</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 type="application/glsl" id="rotate4D">
uniform float cos1;
uniform float sin1;
uniform float cos2;
uniform float sin2;
uniform float cos3;
uniform float sin3;
uniform float cos4;
uniform float sin4;
vec4 getRotate4D(vec4 xyzw, inout vec4 stpq) {
xyzw.xy = xyzw.xy * mat2(cos1, sin1, -sin1, cos1);
xyzw.zw = xyzw.zw * mat2(cos2, sin2, -sin2, cos2);
xyzw.xz = xyzw.xz * mat2(cos3, sin3, -sin3, cos3);
xyzw.yw = xyzw.yw * mat2(cos4, sin4, -sin4, cos4);
return xyzw;
}
</script>
<script>
var mathbox = mathBox({
plugins: ['core', 'controls', 'cursor'],
controls: {
klass: THREE.OrbitControls
},
});
mathbox.three.camera.position.set(0, 0, 3);
mathbox.three.renderer.setClearColor(new THREE.Color(0xFFFFFF), 1.0);
var red = 0xDF2000;
var green = 0x20A000;
var blue = 0x3090FF;
view = mathbox
.set({
scale: 500,
})
.clock({
speed: .25
})
.stereographic4()
.shader({
code: '#rotate4D'
}, {
cos1: function (t) { return Math.cos(t * .111) },
sin1: function (t) { return Math.sin(t * .111) },
cos2: function (t) { return Math.cos(t * .151 + 1) },
sin2: function (t) { return Math.sin(t * .151 + 1) },
cos3: function (t) { return Math.cos(t * .071 + Math.sin(t * .081)) },
sin3: function (t) { return Math.sin(t * .071 + Math.sin(t * .081)) },
cos4: function (t) { return Math.cos(t * .053 + Math.sin(t * .066) + 1) },
sin4: function (t) { return Math.sin(t * .053 + Math.sin(t * .066) + 1) },
})
.vertex();
var q1 = new THREE.Quaternion();
var q2 = new THREE.Quaternion();
view.area({
rangeX: [-π/2, π/2],
rangeY: [0, 2*π],
width: 129,
height: 65,
expr: function (emit, θ, ϕ, i, j) {
q1.set(0, 0, Math.sin(θ), Math.cos(θ));
q2.set(0, Math.sin(ϕ), 0, Math.cos(ϕ));
q1.multiply(q2);
emit(q1.x, q1.y, q1.z, q1.w);
},
live: false,
channels: 4,
});
view.line({
color: blue,
});
// ===========================================================================
view.area({
rangeX: [-π/2, π/2],
rangeY: [0, 2*π],
width: 129,
height: 65,
expr: function (emit, θ, ϕ, i, j) {
q1.set(0, Math.sin(θ), 0, Math.cos(θ));
q2.set(Math.sin(ϕ), 0, 0, Math.cos(ϕ));
q1.multiply(q2);
emit(q1.x, q1.y, q1.z, q1.w);
},
live: false,
channels: 4,
});
view.line({
color: green,
});
// ===========================================================================
view.area({
rangeX: [-π/2, π/2],
rangeY: [0, 2*π],
width: 129,
height: 65,
expr: function (emit, θ, ϕ, i, j) {
q1.set(Math.sin(θ), 0, 0, Math.cos(θ));
q2.set(0, 0, Math.sin(ϕ), Math.cos(ϕ));
q1.multiply(q2);
emit(q1.x, q1.y, q1.z, q1.w);
},
live: false,
channels: 4,
});
view.line({
color: red,
});
// ===========================================================================
</script>
</body>
</html>