2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Shade3D(ver16), pythonスクリプトで正十二面体をつくる

Last updated at Posted at 2020-12-06

備忘:Shade3D ver16 pythonスクリプトで正十二面体をつくる

正十二面体、頂点は20個。辺は30個。

オイラーの多面体定理:「頂点の数」−「辺の数」+「面の数」=2
20−30+12=2

手順

①20個の頂点の座標を調べる。
②30辺の点の組み合わせをセットする。
③3次元内の2点間を結ぶスクリプトを書き、辺を結ぶ。

20個の頂点の座標

以下のツイートを参考にさせていただきました。ありがとうございます。

↓引用ここから

https://twitter.com/hyrodium/status/369819992658698240
スクリーンショット 2020-12-06 14.33.13.png

↑引用ここまで

φを、1.618として、

lst = [0] * 21
lst[1]= [1,1,1]
lst[2]= [1.618,0,1/1.618]
lst[3]= [1.618,0,-1/1.618]
lst[4]= [1,1,-1]
lst[5]= [1/1.618,1.618,0]
lst[6]= [0,1/1.618,1.618]
lst[7]= [1,-1,1]
lst[8]= [1,-1,-1]
lst[9]= [0,1/1.618,-1.618]
lst[10]= [-1/1.618,1.618,0]
lst[11]= [-1,1,1]
lst[12]= [0,-1/1.618,1.618]
lst[13]= [1/1.618,-1.618,0]
lst[14]= [0,-1/1.618,-1.618]
lst[15]= [-1,1,-1]
lst[16]= [-1.618,0,1/1.618]
lst[17]= [-1,-1,1]
lst[18]= [-1/1.618,-1.618,0]
lst[19]= [-1,-1,-1]
lst[20]= [-1.618,0,-1/1.618]

30個の辺の組み合わせをセット

[i,j]として、i番の頂点と、j番の頂点を結ぶ

hen = [0] * 31
hen[1] = [1,2]
hen[2] = [2,3]
hen[3] = [3,4]
hen[4] = [4,5]
hen[5] = [5,1]
hen[6] = [1,6]
hen[7] = [2,7]
hen[8] = [3,8]
hen[9] = [4,9]
hen[10] = [5,10]
hen[11] = [6,11]
hen[12] = [6,12]
hen[13] = [7,12]
hen[14] = [7,13]
hen[15] = [8,13]
hen[16] = [8,14]
hen[17] = [9,14]
hen[18] = [9,15]
hen[19] = [10,15]
hen[20] = [10,11]
hen[21] = [11,16]
hen[22] = [12,17]
hen[23] = [13,18]
hen[24] = [14,19]
hen[25] = [15,20]
hen[26] = [16,17]
hen[27] = [17,18]
hen[28] = [18,19]
hen[29] = [19,20]
hen[30] = [20,16]

3次元内の2点間を結ぶスクリプト

*1)2点を結ぶもの

点P1(x1,y1,z1)から点P2(x2,y2,z2)への単位ベクトルは、

(X,Y,Z) = (x2-x1,y2-y1,z2-z1)
を用いて、r、θ、φを求め、
dx = sinθ cosφ
dy = sinθ sinφ
dz = cosθ
方向に、動かせばよい。

本プログラムでは、rの距離を、20ステップで移動している

import math
import random
scene = xshade.scene()
scene.begin_creating()
s = 8 #点、となる、球の大きさ
#i
x1 = 10 
y1 = 20 
z1 = 30 
#j
x2 = 100 
y2 = 100 
z2 = 100 
px = -x1+x2 
py = -y1+y2 
pz = -z1+z2 
r =  math.sqrt(px*px + py*py + pz*pz)
th = math.acos(pz / r)
if math.sqrt(px * px + py * py) == 0:
	fi = 0
else:
	if py >= 0:
		fi = 1 *  math.acos(px / math.sqrt(px * px + py * py))
	else:
		fi = -1 * math.acos(px / math.sqrt(px * px + py * py))
dx = math.sin(th) *math.cos(fi) * (r/20)
dy = math.sin(th) *math.sin(fi) * (r/20)
dz = math.cos(th) * (r/20)
cx = x1
cy = y1
cz = z1
for ii in range(0,20+1,1):
	scene.create_primitive_sphere(None,3,True,s,s,[cx, cy, cz],s)
	cx += dx
	cy += dy
	cz += dz
scene.end_creating()

↓wikipediaより

(参考)
https://ja.wikipedia.org/wiki/%E7%90%83%E9%9D%A2%E5%BA%A7%E6%A8%99%E7%B3%BB
スクリーンショット 2020-12-06 18.54.23.png

↑wikipediaより

*2)30の辺のループ

for i in range(1,30+1,1):
	rd = 50
	pt1 = hen[i][0]
	pt2 = hen[i][1]
	x1 = lst[pt1][0] * rd
	y1 = lst[pt1][1] * rd
	z1 = lst[pt1][2] * rd
	x2 = lst[pt2][0] * rd
	y2 = lst[pt2][1] * rd
	z2 = lst[pt2][2] * rd

出来上がり

スクリーンショット 2020-12-06 14.43.26.png

ソース

STL

スクリーンショット 2020-12-06 16.13.23.png

参考

Shade3D(ver16)で、Pythonスクリプトで生成したデータを、3Dプリンタ用に整形する
https://qiita.com/santarou6/items/4093443416120eafb0c5

①Pythonで画像から色情報抜き出す、②PythonでShade3Dスクリプトで濃淡絵を書く、③3Dプリンタで書き出す
https://qiita.com/santarou6/items/92d4b3f245642bea9862

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?