-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
332 lines (251 loc) · 9.13 KB
/
index.html
File metadata and controls
332 lines (251 loc) · 9.13 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
<html>
<head>
<meta http-equiv="content-type" content="text/html" charset="utf-8" />
<!-- icon -->
<!-- link rel="shortcut icon" href="https://davidhu3141.github.io/anthology/img/pageicon.png" -->
<!-- mathjax -->
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
<!-- jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- highlightjs -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.9.1/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!-- custom css/js -->
<link href='https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700' rel='stylesheet' type='text/css'>
<link rel=stylesheet type="text/css" href="css/article.css">
<link rel=stylesheet type="text/css" href="css/anthology.css">
<!-- d3 -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" charset="utf-8"></script>
<!-- math.js -->
<script src="http://cdnjs.cloudflare.com/ajax/libs/mathjs/3.6.0/math.min.js"></script>
<!-- Three.js -->
<script src="https://rawgithub.com/mrdoob/three.js/master/build/three.js"></script>
<!-- calcutatings -->
<script src="geo.js"></script>
<!-- previewing -->
<script src="preview3d.js"></script>
<script type = "text/javascript">
var canvas;
var context;
var cx = 300;
var cy = 200;
var ck = 30;
function exec(){
var xlb = parseFloat($("#xlb").val());
var xub = parseFloat($("#xub").val());
var xs = parseInt($("#xs").val());
if(xs <= 0){
alert("Invalid X-slice number");
return;
}
var xd = (xub-xlb)/xs;
var ylb = parseFloat($("#ylb").val());
var yub = parseFloat($("#yub").val());
var ys = parseInt($("#ys").val());
if(ys <= 0){
alert("Invalid Y-slice number");
return;
}
var yd = (yub-ylb)/ys;
var originExpression = $("#func").val();
var code;
try {
code = math.compile(originExpression);
} catch (err) {
alert(err.message);
}
// eval
var f = [];
var i=0;
for(var x=xlb; x<=xub; x+=xd){
f[i] = [];
var j=0;
for(var y=ylb; y<=yub; y+=yd){
var scope = {};
scope.x = x;
scope.y = y;
f[i][j] = Math.max(code.eval(scope), 0);
j++;
}
i++;
}
// draw
for(var i=0; i<xs; i++){
for(var j=0; j<ys; j++){
geo.points[0][0] = i;
geo.points[0][1] = j;
geo.points[1][0] = i + 1;
geo.points[1][1] = j;
geo.points[2][0] = i + 1;
geo.points[2][1] = j + 1;
geo.points[3][0] = i;
geo.points[3][1] = j + 1;
geo.dx = xd;
geo.dy = yd;
geo.initLines(f);
segments = geo.drawVirtual();
var ckp = ck / Math.min(xd, yd) * parseFloat($("#sf").val());
var svg = d3.select(".datavis")
.append("svg")
.attr("width", ckp*(segments.maxx-segments.minx))
.attr("height", ckp*(segments.maxy-segments.miny))
.style("margin", "5px 5px 5px 5px");
svg
.append("text")
.text(i+","+j)
.attr("x", 0)
.attr("y", 30)
.attr("fill", "rgb(0,0,0)")
.attr("font-family", "sans-serif")
.attr("font-size", "15px");
svg
.append("g")
.attr("id", "net"+i+"_"+j)
.selectAll("#net"+i+"_"+j)
.data(segments)
.enter()
.append("line")
.attr("x1", function(d){ return ckp*(d.x1-segments.minx) })
.attr("y1", function(d){ return ckp*(d.y1-segments.miny) })
.attr("x2", function(d){ return ckp*(d.x2-segments.minx) })
.attr("y2", function(d){ return ckp*(d.y2-segments.miny) })
.style("stroke-width", 1)
.style("stroke", "rgb(0, 0, 0)");
}
}
}
function drawPreview(wire){
/////////////////////////////////////////////////
var xlb = parseFloat($("#xlb").val());
var xub = parseFloat($("#xub").val());
var xs = parseInt($("#xs").val());
if(xs <= 0){
alert("Invalid X-slice number");
return;
}
var xd = (xub-xlb)/xs;
var ylb = parseFloat($("#ylb").val());
var yub = parseFloat($("#yub").val());
var ys = parseInt($("#ys").val());
if(ys <= 0){
alert("Invalid Y-slice number");
return;
}
var yd = (yub-ylb)/ys;
var code;
try {
code = math.compile($("#func").val());
} catch (err) {
alert(err.message);
}
////////////////////////////////////////////////
var element = document.getElementById("preview_div");
var geometry = new THREE.Geometry();
var sc = 24/(yub-ylb);
var mx = (xub+xlb)/2;
var my = (yub+ylb)/2;
for(var x=xlb; x<=xub; x+=xd){
for(var y=ylb; y<=yub; y+=yd){
geometry.vertices.push(new THREE.Vector3(x-mx,y-my,0).multiplyScalar(sc));
var scope = {};
scope.x = x;
scope.y = y;
geometry.vertices.push(new THREE.Vector3(x-mx,y-my,-Math.max(code.eval(scope), 0)).multiplyScalar(sc));
}
}
for(var i=0; i<xs; i++){
for(var j=0; j<ys; j++){
var bas = (i*(ys+1)+j)*2;
geometry.faces.push( new THREE.Face3( bas, bas+3, bas+1 ) );
geometry.faces.push( new THREE.Face3( bas+3, bas+2, bas ) );
geometry.faces.push( new THREE.Face3( bas+3, bas+2*(ys+1)+3, bas+2 ) );
geometry.faces.push( new THREE.Face3( bas+2*(ys+1)+3, bas+2*(ys+1)+2, bas+2 ) );
geometry.faces.push( new THREE.Face3( bas+2*(ys+1), bas+2*(ys+1)+2, bas+2*(ys+1)+3 ) );
geometry.faces.push( new THREE.Face3( bas+2*(ys+1), bas+2*(ys+1)+3, bas+2*(ys+1)+1 ) );
geometry.faces.push( new THREE.Face3( bas, bas+2*(ys+1)+1, bas+1 ) );
geometry.faces.push( new THREE.Face3( bas, bas+2*(ys+1), bas+2*(ys+1)+1 ) );
geometry.faces.push( new THREE.Face3( bas+1, bas+2*(ys+1)+3, bas+3 ) );
geometry.faces.push( new THREE.Face3( bas+1, bas+2*(ys+1)+1, bas+2*(ys+1)+3 ) );
}
}
geometry.computeBoundingSphere();
geometry.computeFaceNormals ()
preview_3d_render(element, geometry, wire);
}
$().ready(function(){
$("#preview_color_btn").click(function(){
drawPreview(false);
});
$("#preview_btn").click(function(){
drawPreview(true);
});
$("#net").click(function(){
exec();
});
$("#clr").click(function(){
$(".datavis").html("");
$("#preview_div").html("");
});
});
</script>
</head>
<body>
<div class="master">
<div class="mid_warpper">
<div class="content">
<div class="article">
<div class="notprint">
<h2 id="openzfunction">OpenzFunction</h2>
<h3 id="purpose">Purpose</h3>
<p>To make a model of some z-simple solid that is bound above by a surface <script type="math/tex" id="MathJax-Element-5">z=f(x,y)</script> and below by the x-y plane, we can divide the target into pieces and approximate the pieces by polyhedra.</p>
<p><img src="https://i.imgur.com/XnkHQ4n.jpg" alt="" title="" style="width:100%; margin-left:0px;"></p>
<p>This page plots the nets of such polyhedra of a specified surface so that you could make the model. </p>
<h3>Example</h3>
<p><script type="math/tex" id="MathJax-Element-6">z=xy-\frac{yx^3+xy^3}{6}</script>, near origin, sliced into 64 pieces.</p>
<p><img src="https://raw.githubusercontent.com/davidhu3141/OpenzFunction/master/Sample/Faked.jpg" style="width:40%; margin-left:0px;"></p>
<h3 id="input">Input</h3>
<h4 id="function">Function</h4>
<!-- FORM -->
<p>The function <script type="math/tex" id="MathJax-Element-23">z=f(x,y)=</script> <input style="width:25%;" id="func" value="x*x+y*y+0.2"> . </p>
<blockquote>
<p><em>Notice: The program does not view </em><code>^</code><em> as mathematical power. Please use </em><code>pow(2,x)</code><em>rather than</em><code>2^x</code><em>.</em> </p>
</blockquote>
<h4 id="range">Range</h4>
<!-- FORM -->
<p>X ranges from <input style="width:50px;" id="xlb" value="-1"> to <input style="width:50px;" id="xub" value="1">. <br>
Y ranges from <input style="width:50px;" id="ylb" value="-1"> to <input style="width:50px;" id="yub" value="1">.</p>
<!-- FORM -->
<p>How many slices in X direction: <input style="width:50px;" id="xs" value="6"> <br>
How many slices in Y direction: <input style="width:50px;" id="ys" value="6"> </p>
<!-- FORM -->
<p>Scale factor: <input style="width:50px;" id="sf" value="1"> </p>
<!-- end of not print -->
</div>
<h3 id="preview">Preview</h3>
<!-- FORM -->
<p>
<button type="button" id="preview_btn">Generate Preview</button>
<button type="button" id="preview_color_btn">Generate Preview (Colored)</button>
</p>
<div id="preview_div"></div>
<p>
<button type="button" id="net">Generate Net</button>
</p>
<p>
<button type="button" id="clr">Clear Results</button>
</p>
<p>
Use <code>Ctrl+P</code> to print result directly.
</p>
</div>
<div class="datavis">
</div>
</div>
</div>
<div class="footer">
<!-- p> <em> Any suggestion is welcome! Please mail: davidhu8888@livemail.tw</em> </p -->
</div>
</div>
</body>
</html>