質問編集履歴

5

真剣勝負

2017/07/28 07:52

投稿

masaizokumoai1
masaizokumoai1

スコア12

test CHANGED
File without changes
test CHANGED
@@ -110,7 +110,9 @@
110
110
 
111
111
  =一つ分の面の座標かなと。
112
112
 
113
- ```javaの正二十面体のプログラムをF#にコンバートすることはできませんか?誰かよろしくお願いします。
113
+ 下記のjavaの正二十面体のプログラムをF#にコンバートすることはできませんか?誰かよろしくお願いします。
114
+
115
+ ```
114
116
 
115
117
  import java.applet.*;
116
118
 

4

一方的な変更

2017/07/28 07:52

投稿

masaizokumoai1
masaizokumoai1

スコア12

test CHANGED
File without changes
test CHANGED
@@ -109,3 +109,221 @@
109
109
  (各頂点数×一点に集約される面数÷正N面体の面数分)
110
110
 
111
111
  =一つ分の面の座標かなと。
112
+
113
+ ```javaの正二十面体のプログラムをF#にコンバートすることはできませんか?誰かよろしくお願いします。
114
+
115
+ import java.applet.*;
116
+
117
+ import java.awt.*;
118
+
119
+
120
+
121
+ import com.sun.j3d.utils.picking.behaviors.PickRotateBehavior;
122
+
123
+ import com.sun.j3d.utils.universe.*;
124
+
125
+ import javax.media.j3d.*;
126
+
127
+ import javax.vecmath.*;
128
+
129
+
130
+
131
+ public class Icosahedron2 extends Applet{
132
+
133
+ private static final long serialVersionUID = 1L;
134
+
135
+ private SimpleUniverse u = null;
136
+
137
+
138
+
139
+ public void init(){
140
+
141
+ int i;
142
+
143
+
144
+
145
+ //<set layout of applet, construct canvas3d, add canvas3d>
146
+
147
+ setLayout(new BorderLayout());
148
+
149
+ GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
150
+
151
+ Canvas3D canvas3d = new Canvas3D(config);
152
+
153
+ add(canvas3d, BorderLayout.CENTER);
154
+
155
+
156
+
157
+ //create scene graph
158
+
159
+ BranchGroup root = new BranchGroup();
160
+
161
+ Transform3D tr = new Transform3D();
162
+
163
+ tr.setScale(0.48);
164
+
165
+ TransformGroup tg = new TransformGroup(tr);
166
+
167
+ root.addChild(tg);
168
+
169
+
170
+
171
+ //appearance for polygon
172
+
173
+ Appearance ap = new Appearance();
174
+
175
+ Material mt = new Material();
176
+
177
+ mt.setLightingEnable(true);
178
+
179
+ ap.setMaterial(mt);
180
+
181
+ PolygonAttributes pa = new PolygonAttributes();
182
+
183
+ pa.setBackFaceNormalFlip(true);
184
+
185
+ pa.setCullFace(PolygonAttributes.CULL_NONE);
186
+
187
+ ap.setPolygonAttributes(pa);
188
+
189
+
190
+
191
+ //coordinates of vertices
192
+
193
+ Point3f[] vertices = new Point3f[12];
194
+
195
+ float x = (float) ((1+Math.sqrt(5))/2);
196
+
197
+
198
+
199
+ vertices[0] = new Point3f( 1, x, 0);
200
+
201
+ vertices[1] = new Point3f(-1, x, 0);
202
+
203
+ vertices[2] = new Point3f(-1, -x, 0);
204
+
205
+ vertices[3] = new Point3f( 1, -x, 0);
206
+
207
+ vertices[4] = new Point3f( 0, 1, x);
208
+
209
+ vertices[5] = new Point3f( 0, -1, x);
210
+
211
+ vertices[6] = new Point3f( 0, -1, -x);
212
+
213
+ vertices[7] = new Point3f( 0, 1, -x);
214
+
215
+ vertices[8] = new Point3f( x, 0, 1);
216
+
217
+ vertices[9] = new Point3f( x, 0, -1);
218
+
219
+ vertices[10] = new Point3f(-x, 0, -1);
220
+
221
+ vertices[11] = new Point3f(-x, 0, 1);
222
+
223
+
224
+
225
+ //polygon of 3 rectangles
226
+
227
+ QuadArray geometry = new QuadArray(12, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.COLOR_3);
228
+
229
+ geometry.setCoordinates(0, vertices);
230
+
231
+ for(i=0; i<4; i++) geometry.setNormal(i, new Vector3f(0, 0, 1));
232
+
233
+ for(i=4; i<8; i++) geometry.setNormal(i, new Vector3f(1, 0, 0));
234
+
235
+ for(i=8; i<12; i++) geometry.setNormal(i, new Vector3f(0, 1, 0));
236
+
237
+ for(i=0; i<4; i++) geometry.setColor(i, new Color3f(Color.RED));
238
+
239
+ for(i=4; i<8; i++) geometry.setColor(i, new Color3f(Color.GREEN));
240
+
241
+ for(i=8; i<12; i++) geometry.setColor(i, new Color3f(Color.BLUE));
242
+
243
+ Shape3D s3d = new Shape3D(geometry);
244
+
245
+ s3d.setAppearance(ap);
246
+
247
+ tg.addChild(s3d);
248
+
249
+
250
+
251
+ //wire frame
252
+
253
+ for(i=0; i<12; i++){
254
+
255
+ for(int j=i; j<12; j++){
256
+
257
+ if (vertices[i].distance(vertices[j]) < 2.1f){
258
+
259
+ LineArray ends = new LineArray(2, GeometryArray.COORDINATES);
260
+
261
+ Point3f vertex[] = new Point3f[2];
262
+
263
+ vertex[0] = vertices[i];
264
+
265
+ vertex[1] = vertices[j];
266
+
267
+ ends.setCoordinates(0, vertex);
268
+
269
+ Shape3D line = new Shape3D(ends);
270
+
271
+ tg.addChild(line);
272
+
273
+ }
274
+
275
+ }
276
+
277
+ }
278
+
279
+
280
+
281
+ //lighting
282
+
283
+ BoundingSphere bounds =
284
+
285
+ new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
286
+
287
+
288
+
289
+ Color3f color = new Color3f(1.0f, 1.0f, 1.0f); // white light
290
+
291
+ Vector3f direction = new Vector3f(4.0f,5.0f,-10.0f);
292
+
293
+ DirectionalLight light = new DirectionalLight(color,direction);
294
+
295
+ light.setInfluencingBounds(bounds);
296
+
297
+ root.addChild(light);
298
+
299
+
300
+
301
+ //picking
302
+
303
+ BoundingSphere bounds2 =
304
+
305
+ new BoundingSphere(new Point3d(0.0,0.0,0.0), 0.1);
306
+
307
+ PickRotateBehavior prb = new PickRotateBehavior(root,canvas3d,bounds2); //left button
308
+
309
+ root.addChild(prb);
310
+
311
+ tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
312
+
313
+ tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
314
+
315
+ tg.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
316
+
317
+
318
+
319
+ u = new SimpleUniverse(canvas3d);
320
+
321
+ u.getViewingPlatform().setNominalViewingTransform();
322
+
323
+ u.addBranchGraph(root);
324
+
325
+ }
326
+
327
+ }
328
+
329
+ ```

3

紆余曲折ありまして

2017/07/28 07:50

投稿

masaizokumoai1
masaizokumoai1

スコア12

test CHANGED
File without changes
test CHANGED
@@ -9,3 +9,103 @@
9
9
  このように表示され、正二十面体にならないので非常に困っています。
10
10
 
11
11
  正二十面体はどのようにして記述できるかというコード詳細をご教授願えないでしょうか?
12
+
13
+
14
+
15
+ ```F#+OpenTK
16
+
17
+ type GLEx =
18
+
19
+ /// Add multiple vertices to GL
20
+
21
+ static member Vertices vertices =
22
+
23
+ for (x:float32), y, z in vertices do
24
+
25
+ GL.Vertex3(x, y, z)
26
+
27
+
28
+
29
+ /// Add mesh to the GL and set the specified normal vector first
30
+
31
+ static member Face (x:float32, y, z) vertices =
32
+
33
+ GL.Normal3(x, y, z)
34
+
35
+ GLEx.Vertices vertices
36
+
37
+ ```
38
+
39
+
40
+
41
+ ```F#+OpenTK
42
+
43
+ let cube = DF (fun ctx ->
44
+
45
+ GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, ctx.Color)
46
+
47
+ GL.Begin(BeginMode.Quads)
48
+
49
+ GLEx.Face
50
+
51
+ (-1.f, 0.f, 0.f)
52
+
53
+ [ (-0.5f, -0.5f, -0.5f); (-0.5f, -0.5f, 0.5f);
54
+
55
+ (-0.5f, 0.5f, 0.5f); (-0.5f, 0.5f, -0.5f) ]
56
+
57
+ GLEx.Face
58
+
59
+ ( 1.f, 0.f, 0.f)
60
+
61
+ [ ( 0.5f, -0.5f, -0.5f); ( 0.5f, -0.5f, 0.5f);
62
+
63
+ ( 0.5f, 0.5f, 0.5f); ( 0.5f, 0.5f, -0.5f) ]
64
+
65
+ GLEx.Face
66
+
67
+ (0.f, -1.f, 0.f)
68
+
69
+ [ (-0.5f, -0.5f, -0.5f); (-0.5f, -0.5f, 0.5f);
70
+
71
+ ( 0.5f, -0.5f, 0.5f); ( 0.5f, -0.5f, -0.5f) ]
72
+
73
+ GLEx.Face
74
+
75
+ (0.f, 1.f, 0.f)
76
+
77
+ [ (-0.5f, 0.5f, -0.5f); (-0.5f, 0.5f, 0.5f);
78
+
79
+ ( 0.5f, 0.5f, 0.5f); ( 0.5f, 0.5f, -0.5f) ]
80
+
81
+ GLEx.Face
82
+
83
+ (0.f, 0.f, -1.f)
84
+
85
+ [ (-0.5f, -0.5f, -0.5f); (-0.5f, 0.5f, -0.5f);
86
+
87
+ ( 0.5f, 0.5f, -0.5f); ( 0.5f, -0.5f, -0.5f) ]
88
+
89
+ GLEx.Face
90
+
91
+ (0.f, 0.f, 1.f)
92
+
93
+ [ (-0.5f, -0.5f, 0.5f); (-0.5f, 0.5f, 0.5f);
94
+
95
+ ( 0.5f, 0.5f, 0.5f); ( 0.5f, -0.5f, 0.5f) ]
96
+
97
+ GL.End() )
98
+
99
+ ```
100
+
101
+ となるわけで正六面体(=立方体)24箇所座標があるということは
102
+
103
+ 正二十面体では12箇所では足りないのではと思いまして
104
+
105
+ とりあえず
106
+
107
+ 必要なことは
108
+
109
+ (各頂点数×一点に集約される面数÷正N面体の面数分)
110
+
111
+ =一つ分の面の座標かなと。

2

わかりやすくするため

2017/07/28 07:09

投稿

masaizokumoai1
masaizokumoai1

スコア12

test CHANGED
File without changes
test CHANGED
@@ -1,10 +1,10 @@
1
1
  F#とOpenTKを用いて正二十面体を描画したいのですが、どのようなコードを記述すればいいのかわからなくなりました。
2
2
 
3
- ![イメジ説明](f373768b27072f18dfe332ca658ba52d.jpeg)
3
+ ![F#+OpenTK一部コド群](f373768b27072f18dfe332ca658ba52d.jpeg)
4
4
 
5
5
  こちらのコードを実行すると
6
6
 
7
- ![イメージ説明](1391706f114beda9391fb34227c263d6.jpeg)
7
+ ![長方形複合体](1391706f114beda9391fb34227c263d6.jpeg)
8
8
 
9
9
  このように表示され、正二十面体にならないので非常に困っています。
10
10
 

1

2017/07/25 11:16

投稿

masaizokumoai1
masaizokumoai1

スコア12

test CHANGED
File without changes
test CHANGED
File without changes