2017年11月8日 星期三

JavaFX 3D - Icosahedron

以下是以JavaFX 8的TriangleMesh類別建構之Icosahedron (正二十面體),屬於Platonic Solid (柏拉圖多面體)。

float p0 = 0.5f * length;
float p1 = 0.0f;
float p2 = (float) (length * (Math.sqrt(5.0) + 1.0) / 4.0f);

// 建立TriangleMesh
TriangleMesh trianglemesh = new TriangleMesh();

// 設定頂點座標
trianglemesh.getPoints().addAll(
   p0,  p1,  p2,
   p0,  p1, -p2,
  -p0,  p1,  p2,
  -p0,  p1, -p2,
   p2,  p0,  p1,
   p2, -p0,  p1,
  -p2,  p0,  p1,
  -p2, -p0,  p1,
   p1,  p2,  p0,
   p1,  p2, -p0,
   p1, -p2,  p0,
   p1, -p2, -p0
);

// 設定各三角形的面
trianglemesh.getFaces().addAll(
   0, 0,  2, 1, 10, 2,  
   0, 1, 10, 0,  5, 3, 
   0, 2,  5, 1,  4, 4,
   0, 0,  4, 2,  8, 5,
   0, 1,  8, 0,  2, 3,
   2, 2,  8, 1,  6, 4,
   2, 0,  6, 2,  7, 5,
   2, 0,  7, 1, 10, 2,
  10, 2,  7, 1, 11, 4,  
  10, 0, 11, 2,  5, 5, 
   5, 0, 11, 1,  1, 2,
   5, 1,  1, 0,  4, 3,
   4, 0,  1, 2,  9, 5,
   4, 0,  9, 1,  8, 2,
   8, 1,  9, 0,  6, 3,
   6, 2,  9, 1,  3, 4,
   6, 0,  3, 1,  7, 2,  
   7, 1,  3, 0, 11, 3, 
  11, 2,  3, 1,  1, 4,
   1, 0,  3, 2,  9, 5
);

// 設定各面的平滑參數
trianglemesh.getFaceSmoothingGroups().addAll(
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0
);

// 建立MeshView
MeshView meshview;

meshview = new MeshView(createMesh(150));
...
【參考資料】

[1] Java Official Web Site:http://www.oracle.com/technetwork/java/index.html
[2] JavaFX:http://www.oracle.com/technetwork/java/javafx
[3] JavaFX 8.0 API Specification.
[4] Java Platform, Standard Edition 8 API Specification.
[5] JDK 8 Certified System Configurations.
[6] H. M. Cundy, A. P. Rollett, Mathematical Models, Tarquin Publications, 1981.
[7] G. Sellers, R. S. Wright, N. Haemel, OpenGL SuperBible: Comprehensive Tutorial and Reference (6th Edition), Addison-Wesley Professional, 2013.
[8] 黃嘉輝, JavaFX 8技術手冊, ISBN: 9789863474050, 碁峰資訊, 2014.

© Chia-Hui Huang

沒有留言:

張貼留言