如果想优雅地绘制一个足球,那首先需要绘制正二十面体:用Python绘制正二十面体
其核心代码为
import numpy as np
from itertools import product
G = (np.sqrt(5)-1)/2
def getVertex():
pt2 = [(a,b) for a,b in product([1,-1], [G, -G])]
pts = [(a,b,0) for a,b in pt2]
pts += [(0,a,b) for a,b in pt2]
pts += [(b,0,a) for a,b in pt2]
return np.array(pts)
def getDisMat(pts):
N = len(pts)
dMat = np.ones([N,N])*np.inf
for i in range(N):
for j in range(i):
dMat[i,j] = np.linalg.norm([pts-pts[j]])
return dMat
from itertools import combinations
# 获取正二十面体的面
faces = [es for es in combinations(edges, 3)
if isFace(*es)]
为了克服plot_trisurf在xy坐标系中的bug,需要对足球做一点旋转,所以下面要写入旋转矩阵。
# 将角度转弧度后再求余弦
cos = lambda th : np.cos(np.deg2rad(th))
sin = lambda th : np.sin(np.deg2rad(th))
我两个都不好……
点评
使用道具 举报
同道中人
使用道具 举报
写代码跟做数学题感觉一样
使用道具 举报