我想把一个由X,Y,Z原子坐标定义的5原子晶体旋转一个随机角度。我最初的想法是使用一个外部包来生成一个旋转矩阵(https://github.com/qobilidop/randrot),然后将这个矩阵乘以一个向量,这个向量定义了单个原子的坐标。然而,这根本不起作用,所有的原子都分散了。我为此写了一个函数:
def rotation():
crystal = []
rotmat = np.asarray(randrot.generate(3)) #generates 3x3 rotation matrix
for x,y,z in zip(new_x, new_y, new_z):
vec = np.array([x,y,z])
rot = vec.dot(rotmat)
for elem in rot:
crystal.append(elem)
return np.array(crystal).reshape([5,3])
rotated = rotation()
ax.scatter(rotated[0], rotated[1], rotated[2], marker='.', s=100, color='green')
下面是它的外观(红色是初始位置,绿色是旋转后):
下面是一个示例代码,它围绕随机生成的旋转矩阵旋转给定的3d点,旋转矩阵的创建取自another answer。你知道吗
相关问题 更多 >
编程相关推荐