-
Notifications
You must be signed in to change notification settings - Fork 1
/
dm-logo-ring.html
85 lines (80 loc) · 2.9 KB
/
dm-logo-ring.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>DM Logo 25</title>
<script src="http://acko.net/files/mathbox2/mathbox-bundle.min.js"></script>
<link rel="stylesheet" href="http://acko.net/files/mathbox2/mathbox.css">
<meta name="viewport" content="initial-scale=1, maximum-scale=1">
</head>
<body>
<script>
var mathbox = mathBox({
plugins: ['core', 'controls', 'cursor'],
controls: {
klass: THREE.OrbitControls,
camera: new THREE.OrthographicCamera(-2, 2, 2, -2, 0.01, 10000),
},
});
if (mathbox.fallback) throw "WebGL error";
var three = mathbox.three;
three.camera.position.set(0, 2, 0);
three.renderer.setClearColor(new THREE.Color(0xFFFFFF), 1.0);
function reuleaux(i, j, k, thickness) {
var rad = (j / 10.0 - 1) * Math.PI / 3.0
//using Polar equation of a curve from https://en.wikipedia.org/wiki/Polar_coordinate_system
//R=1, r0=1/sqrt(3) (2/3 height of unit sided equilateral triangle, offset of centre of reuleaux arc)
var cosr = Math.cos(rad)
var r = (Math.sqrt(4.0/3.0*cosr*cosr + 8.0/3.0) - 2.0/Math.sqrt(3.0)*cosr)/2.0
var az = i / 100.0 * Math.PI * 2.0
var rot = az*2/3
var degrees = (rot/Math.PI*180+30)%120-30
function cos_deg(d) { return Math.cos(d/180*Math.PI); }
if(degrees<30){
var r0 = 1-cos_deg(degrees)/Math.sqrt(3.0)
}else{
var r0 = cos_deg(degrees-60)/Math.sqrt(3.0)
}
var th = rad + k*Math.PI*2/3 + rot //twist it!
//based on parametric equation of a torus
var full_radius = r * Math.cos(th) - r0 - 0.5;
full_radius = 1.0 + full_radius/25.0*thickness;
var x = Math.sin(-az)* full_radius
var y = Math.cos(-az)* full_radius
var z = r*Math.sin(th)/5
return {x: x, y: z, z: y}
}
var view = mathbox.cartesian({scale: [0.1, 0.1, 0.1]})
.unit({scale:1000})
var numXY=3
for(var i=0; i<=0; ++i)
{
var thickness = 3;//i+numXY/2+1;
view.voxel({
width: 100, height: 20, depth: 3,
items: 4, channels: 3,
expr: function (emit, i, j, k, t) {
var p0 = reuleaux(i,j,k,thickness); emit(p0.x, p0.y, p0.z);
var p1 = reuleaux(i+1,j,k,thickness); emit(p1.x, p1.y, p1.z);
var p2 = reuleaux(i+1,j+1,k,thickness); emit(p2.x, p2.y, p2.z);
var p3 = reuleaux(i,j+1,k,thickness); emit(p3.x, p3.y, p3.z);
console.log(
}
})
for(var j=0; j<=0; ++j) {
view.transform({scale: [1.5,1.5,1.5], position: [6.0*Math.sin((j-0.5)/numXY*Math.PI/2.0), 0, -i*3.5]})
.transform({rotation: [i/numXY*Math.PI, 0, j/numXY*Math.PI/2.0]})
.face({color: 0xEEEEEE, shaded: false})
.face({color: 0xEEEEEE, shaded: true, opacity: 0.5})
}
}
//function exportASCII() {
// var result = exporter.parse( mesh );
// saveString( result, "C:/src/notebooks/dm-logo-ring.stl");
//}
//function saveString( text, filename ) {
// save( new Blob( [ text ], { type: 'text/plain' } ), filename );
//}
</script>
</body>
</html>