我们需要找到
二
plane
(正常)。我们可以通过以下程序实现:
-
飞机
-
k = (1, 0, 0)
-
计算
math.abs(np.dot(k, plane))
-
如果(>);0.9然后设置
k = (0, 1, 0)
-
a = np.cross(k, plane))
和
b = np.cross(plane, a)
-
现在平面上有两个向量。你可以通过将这两个向量的几倍相加,再加上
centeroid
-
如果需要特定距离,则需要归一化
a
b
代码:
import numpy as np
import math
def normalize(a):
b = 1.0 / math.sqrt(np.sum(a ** 2))
return a * b
def circlePoints(r, N_points, plane=(1,1,1), centroid=(0,0,0)):
p = normalize(np.array(plane))
k = (1, 0, 0)
if math.fabs(np.dot(k, p)) > 0.9:
k = (0, 1, 0)
a = normalize(np.cross(k, p))
b = normalize(np.cross(p, a))
step = (np.pi * 2) / N_points
ang = [step * i for i in xrange(N_points)]
return [(np.array(centroid) + \
r * (math.cos(rot) * a + math.sin(rot) * b)) \
for rot in ang]
print circlePoints(10, 5, (1, 1, 1), (0, 0, 0))