动画动画按角度

时间:2019-01-11 12:34:41

标签: python animation

我想从1到x度(1、2、3、4 ... x)对立方体进行动画处理。我的代码甚至可能吗?尝试使用FuncAnimation,但将所有多维数据集放在一个图像上,而不是动画。 感谢您的帮助

from mpl_toolkits.mplot3d import Axes3D    
import matplotlib.pyplot as plt    
import numpy as np    
import matplotlib.animation as animation    
from itertools import product, combinations    
from numpy import sin, cos    


fig = plt.figure()    
ax = fig.gca(projection='3d')    
ax.set_aspect("auto")    
ax.set_xlim(-10, 10)    
ax.set_ylim(-10, 10)    
ax.set_zlim(-10, 10)    
ax.set_xlabel("Os X")    
ax.set_ylabel("Os Y")    
ax.set_zlabel("Os Z")  
ax.grid(2)   

d = [-2, 2]

def rotate():    
    for x in range(1, 46): #rotate by Z axis    
        theta = np.radians(x)    
        for s, e in combinations(np.array(list(product(d,d,d))), 2):    
            if np.sum(np.abs(s-e)) == d[1]-d[0]:    
                s_rotated = [s[0] * cos(theta) - s[1] * sin(theta),    
                             s[0] * sin(theta) + s[1] * cos(theta),    
                             s[2]]    
                e_rotated = [e[0] * cos(theta) - e[1] * sin(theta),    
                             e[0] * sin(theta) + e[1] * cos(theta),    
                             e[2]]    
                y = ax.plot3D(*zip(s_rotated,e_rotated), color="g")    

ani = animation.FuncAnimation(fig, rotate(), interval=1000, blit=False, repeat_delay=1000)
plt.show()

0 个答案:

没有答案