質問編集履歴
5
真剣勝負
title
CHANGED
File without changes
|
body
CHANGED
@@ -54,7 +54,8 @@
|
|
54
54
|
必要なことは
|
55
55
|
(各頂点数×一点に集約される面数÷正N面体の面数分)
|
56
56
|
=一つ分の面の座標かなと。
|
57
|
-
|
57
|
+
下記のjavaの正二十面体のプログラムをF#にコンバートすることはできませんか?誰かよろしくお願いします。
|
58
|
+
```
|
58
59
|
import java.applet.*;
|
59
60
|
import java.awt.*;
|
60
61
|
|
4
一方的な変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -53,4 +53,113 @@
|
|
53
53
|
とりあえず
|
54
54
|
必要なことは
|
55
55
|
(各頂点数×一点に集約される面数÷正N面体の面数分)
|
56
|
-
=一つ分の面の座標かなと。
|
56
|
+
=一つ分の面の座標かなと。
|
57
|
+
```javaの正二十面体のプログラムをF#にコンバートすることはできませんか?誰かよろしくお願いします。
|
58
|
+
import java.applet.*;
|
59
|
+
import java.awt.*;
|
60
|
+
|
61
|
+
import com.sun.j3d.utils.picking.behaviors.PickRotateBehavior;
|
62
|
+
import com.sun.j3d.utils.universe.*;
|
63
|
+
import javax.media.j3d.*;
|
64
|
+
import javax.vecmath.*;
|
65
|
+
|
66
|
+
public class Icosahedron2 extends Applet{
|
67
|
+
private static final long serialVersionUID = 1L;
|
68
|
+
private SimpleUniverse u = null;
|
69
|
+
|
70
|
+
public void init(){
|
71
|
+
int i;
|
72
|
+
|
73
|
+
//<set layout of applet, construct canvas3d, add canvas3d>
|
74
|
+
setLayout(new BorderLayout());
|
75
|
+
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
|
76
|
+
Canvas3D canvas3d = new Canvas3D(config);
|
77
|
+
add(canvas3d, BorderLayout.CENTER);
|
78
|
+
|
79
|
+
//create scene graph
|
80
|
+
BranchGroup root = new BranchGroup();
|
81
|
+
Transform3D tr = new Transform3D();
|
82
|
+
tr.setScale(0.48);
|
83
|
+
TransformGroup tg = new TransformGroup(tr);
|
84
|
+
root.addChild(tg);
|
85
|
+
|
86
|
+
//appearance for polygon
|
87
|
+
Appearance ap = new Appearance();
|
88
|
+
Material mt = new Material();
|
89
|
+
mt.setLightingEnable(true);
|
90
|
+
ap.setMaterial(mt);
|
91
|
+
PolygonAttributes pa = new PolygonAttributes();
|
92
|
+
pa.setBackFaceNormalFlip(true);
|
93
|
+
pa.setCullFace(PolygonAttributes.CULL_NONE);
|
94
|
+
ap.setPolygonAttributes(pa);
|
95
|
+
|
96
|
+
//coordinates of vertices
|
97
|
+
Point3f[] vertices = new Point3f[12];
|
98
|
+
float x = (float) ((1+Math.sqrt(5))/2);
|
99
|
+
|
100
|
+
vertices[0] = new Point3f( 1, x, 0);
|
101
|
+
vertices[1] = new Point3f(-1, x, 0);
|
102
|
+
vertices[2] = new Point3f(-1, -x, 0);
|
103
|
+
vertices[3] = new Point3f( 1, -x, 0);
|
104
|
+
vertices[4] = new Point3f( 0, 1, x);
|
105
|
+
vertices[5] = new Point3f( 0, -1, x);
|
106
|
+
vertices[6] = new Point3f( 0, -1, -x);
|
107
|
+
vertices[7] = new Point3f( 0, 1, -x);
|
108
|
+
vertices[8] = new Point3f( x, 0, 1);
|
109
|
+
vertices[9] = new Point3f( x, 0, -1);
|
110
|
+
vertices[10] = new Point3f(-x, 0, -1);
|
111
|
+
vertices[11] = new Point3f(-x, 0, 1);
|
112
|
+
|
113
|
+
//polygon of 3 rectangles
|
114
|
+
QuadArray geometry = new QuadArray(12, QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.COLOR_3);
|
115
|
+
geometry.setCoordinates(0, vertices);
|
116
|
+
for(i=0; i<4; i++) geometry.setNormal(i, new Vector3f(0, 0, 1));
|
117
|
+
for(i=4; i<8; i++) geometry.setNormal(i, new Vector3f(1, 0, 0));
|
118
|
+
for(i=8; i<12; i++) geometry.setNormal(i, new Vector3f(0, 1, 0));
|
119
|
+
for(i=0; i<4; i++) geometry.setColor(i, new Color3f(Color.RED));
|
120
|
+
for(i=4; i<8; i++) geometry.setColor(i, new Color3f(Color.GREEN));
|
121
|
+
for(i=8; i<12; i++) geometry.setColor(i, new Color3f(Color.BLUE));
|
122
|
+
Shape3D s3d = new Shape3D(geometry);
|
123
|
+
s3d.setAppearance(ap);
|
124
|
+
tg.addChild(s3d);
|
125
|
+
|
126
|
+
//wire frame
|
127
|
+
for(i=0; i<12; i++){
|
128
|
+
for(int j=i; j<12; j++){
|
129
|
+
if (vertices[i].distance(vertices[j]) < 2.1f){
|
130
|
+
LineArray ends = new LineArray(2, GeometryArray.COORDINATES);
|
131
|
+
Point3f vertex[] = new Point3f[2];
|
132
|
+
vertex[0] = vertices[i];
|
133
|
+
vertex[1] = vertices[j];
|
134
|
+
ends.setCoordinates(0, vertex);
|
135
|
+
Shape3D line = new Shape3D(ends);
|
136
|
+
tg.addChild(line);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
//lighting
|
142
|
+
BoundingSphere bounds =
|
143
|
+
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
|
144
|
+
|
145
|
+
Color3f color = new Color3f(1.0f, 1.0f, 1.0f); // white light
|
146
|
+
Vector3f direction = new Vector3f(4.0f,5.0f,-10.0f);
|
147
|
+
DirectionalLight light = new DirectionalLight(color,direction);
|
148
|
+
light.setInfluencingBounds(bounds);
|
149
|
+
root.addChild(light);
|
150
|
+
|
151
|
+
//picking
|
152
|
+
BoundingSphere bounds2 =
|
153
|
+
new BoundingSphere(new Point3d(0.0,0.0,0.0), 0.1);
|
154
|
+
PickRotateBehavior prb = new PickRotateBehavior(root,canvas3d,bounds2); //left button
|
155
|
+
root.addChild(prb);
|
156
|
+
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
|
157
|
+
tg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
|
158
|
+
tg.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
|
159
|
+
|
160
|
+
u = new SimpleUniverse(canvas3d);
|
161
|
+
u.getViewingPlatform().setNominalViewingTransform();
|
162
|
+
u.addBranchGraph(root);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
```
|
3
紆余曲折ありまして
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,4 +3,54 @@
|
|
3
3
|
こちらのコードを実行すると
|
4
4
|

|
5
5
|
このように表示され、正二十面体にならないので非常に困っています。
|
6
|
-
正二十面体はどのようにして記述できるかというコード詳細をご教授願えないでしょうか?
|
6
|
+
正二十面体はどのようにして記述できるかというコード詳細をご教授願えないでしょうか?
|
7
|
+
|
8
|
+
```F#+OpenTK
|
9
|
+
type GLEx =
|
10
|
+
/// Add multiple vertices to GL
|
11
|
+
static member Vertices vertices =
|
12
|
+
for (x:float32), y, z in vertices do
|
13
|
+
GL.Vertex3(x, y, z)
|
14
|
+
|
15
|
+
/// Add mesh to the GL and set the specified normal vector first
|
16
|
+
static member Face (x:float32, y, z) vertices =
|
17
|
+
GL.Normal3(x, y, z)
|
18
|
+
GLEx.Vertices vertices
|
19
|
+
```
|
20
|
+
|
21
|
+
```F#+OpenTK
|
22
|
+
let cube = DF (fun ctx ->
|
23
|
+
GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, ctx.Color)
|
24
|
+
GL.Begin(BeginMode.Quads)
|
25
|
+
GLEx.Face
|
26
|
+
(-1.f, 0.f, 0.f)
|
27
|
+
[ (-0.5f, -0.5f, -0.5f); (-0.5f, -0.5f, 0.5f);
|
28
|
+
(-0.5f, 0.5f, 0.5f); (-0.5f, 0.5f, -0.5f) ]
|
29
|
+
GLEx.Face
|
30
|
+
( 1.f, 0.f, 0.f)
|
31
|
+
[ ( 0.5f, -0.5f, -0.5f); ( 0.5f, -0.5f, 0.5f);
|
32
|
+
( 0.5f, 0.5f, 0.5f); ( 0.5f, 0.5f, -0.5f) ]
|
33
|
+
GLEx.Face
|
34
|
+
(0.f, -1.f, 0.f)
|
35
|
+
[ (-0.5f, -0.5f, -0.5f); (-0.5f, -0.5f, 0.5f);
|
36
|
+
( 0.5f, -0.5f, 0.5f); ( 0.5f, -0.5f, -0.5f) ]
|
37
|
+
GLEx.Face
|
38
|
+
(0.f, 1.f, 0.f)
|
39
|
+
[ (-0.5f, 0.5f, -0.5f); (-0.5f, 0.5f, 0.5f);
|
40
|
+
( 0.5f, 0.5f, 0.5f); ( 0.5f, 0.5f, -0.5f) ]
|
41
|
+
GLEx.Face
|
42
|
+
(0.f, 0.f, -1.f)
|
43
|
+
[ (-0.5f, -0.5f, -0.5f); (-0.5f, 0.5f, -0.5f);
|
44
|
+
( 0.5f, 0.5f, -0.5f); ( 0.5f, -0.5f, -0.5f) ]
|
45
|
+
GLEx.Face
|
46
|
+
(0.f, 0.f, 1.f)
|
47
|
+
[ (-0.5f, -0.5f, 0.5f); (-0.5f, 0.5f, 0.5f);
|
48
|
+
( 0.5f, 0.5f, 0.5f); ( 0.5f, -0.5f, 0.5f) ]
|
49
|
+
GL.End() )
|
50
|
+
```
|
51
|
+
となるわけで正六面体(=立方体)24箇所座標があるということは
|
52
|
+
正二十面体では12箇所では足りないのではと思いまして
|
53
|
+
とりあえず
|
54
|
+
必要なことは
|
55
|
+
(各頂点数×一点に集約される面数÷正N面体の面数分)
|
56
|
+
=一つ分の面の座標かなと。
|
2
わかりやすくするため
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
F#とOpenTKを用いて正二十面体を描画したいのですが、どのようなコードを記述すればいいのかわからなくなりました。
|
2
|
-

|
3
3
|
こちらのコードを実行すると
|
4
|
-

|
5
5
|
このように表示され、正二十面体にならないので非常に困っています。
|
6
6
|
正二十面体はどのようにして記述できるかというコード詳細をご教授願えないでしょうか?
|
1
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|