python draw parallelepiped

后端 未结 4 686
庸人自扰
庸人自扰 2021-02-08 05:25

I am trying to draw a parallelepiped. Actually I started from the python script drawing a cube as:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
imp         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-08 05:55

    Done using matplotlib and coordinate geometry

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    import numpy as np
    
    
    def cube_coordinates(edge_len,step_size):
        X = np.arange(0,edge_len+step_size,step_size)
        Y = np.arange(0,edge_len+step_size,step_size)
        Z = np.arange(0,edge_len+step_size,step_size)
        temp=list()
        for i in range(len(X)):
            temp.append((X[i],0,0))
            temp.append((0,Y[i],0))
            temp.append((0,0,Z[i]))
            temp.append((X[i],edge_len,0))
            temp.append((edge_len,Y[i],0))
            temp.append((0,edge_len,Z[i]))
            temp.append((X[i],edge_len,edge_len))
            temp.append((edge_len,Y[i],edge_len))
            temp.append((edge_len,edge_len,Z[i]))
            temp.append((edge_len,0,Z[i]))
            temp.append((X[i],0,edge_len))
            temp.append((0,Y[i],edge_len))
        return temp
    
    
    edge_len = 10
    
    
    A=cube_coordinates(edge_len,0.01)
    A=list(set(A))
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    A=zip(*A)
    X,Y,Z=list(A[0]),list(A[1]),list(A[2])
    ax.scatter(X,Y,Z,c='g')
    
    plt.show()
    

提交回复
热议问题