我只会这样求,但是显然对于N维来说,这个样子太累了...
rectangle = [(0,0,0),(0,1,0),(1,1,0),(1,0,0)]
x, y, z = zip(*rectangle)
centroid = (sum(x)/len(x), sum(y)/len(y), sum(z)/len(z))
不知道合适的语法应该怎么写?
另外,再求教一下,3d geometry操作的lib有何推荐?
比如我想rectangle.z = z0
或者rectangle.scale((0,0,1), 0.5)
,朝着某个点缩放坐标,0.5倍
再或者,求几分点等等
1
Septembers 2015-05-17 13:32:00 +08:00
|
2
Valyrian 2015-05-17 13:44:41 +08:00
N维的话for loop一下不就行了。。
|
3
Septembers 2015-05-17 13:50:35 +08:00
>>> rectangle = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0)]
>>> centroid = [sum(x) / len(x) for x in zip(*rectangle)] >>> centroid [0, 0, 0] |