【问题标题】:Plotting a 3D frustrum in python在 python 中绘制一个 3D 平截头体
【发布时间】:2021-11-25 23:45:03
【问题描述】:

我正在尝试在 python 程序中绘制一个 3D 锥体截锥体(曲面图),其中截锥体几何由下面的平面图像给出:

所有变量 B、L、alpha、beta... 都将在我的程序中给出(请注意,alpha 不等于 beta,例如在常规截头锥中)。有人会帮助我就如何进行此操作提供任何建议吗?提前谢谢!

【问题讨论】:

    标签: python matplotlib plot 3d geometry-surface


    【解决方案1】:

    这样的?

    import numpy as np
    import matplotlib.pyplot as plt
    
    def get_vertices(L, B, I, alpha, beta):
        P = np.empty((8,3), dtype=float)
        Ind = np.array([4,5,6,7])
        #Ind = np.array([0,2,4,6])
        
        P[Ind, 0] = L/2 + I*np.tan(np.pi*alpha/180)
        P[Ind, 1] = B/2 + I*np.tan(np.pi*beta/180)
        P[Ind, 2] = I
        P[5, 0] = - P[5, 0]
        P[7, 1] = - P[7, 1]
        P[6, [0,1]] = - P[6, [0,1]]
        
        Ind = Ind - 4
        P[Ind, 0] = L/2
        P[Ind, 1] = B/2
        P[Ind, 2] = 0
        P[1, 0] = - P[1, 0]
        P[3, 1] = - P[3, 1]
        P[2, [0,1]] = - P[2, [0,1]]
        
        return P
    
    
    def draw(P):
        l_x = -7
        r_x = 7
        l_y = -7
        r_y = 7
        l_z = -0.5
        r_z = 7
        fig = plt.figure()
        ax = fig.add_subplot(projection='3d')
        ax.set_xlim((l_x, r_x))
        ax.set_ylim((l_y, r_y))
        ax.set_zlim((l_z, r_z))
        Ind = np.array([[0,1], [1,2], [2,3], [3,0]]) 
        for i in Ind:        
            ax.plot(P[i, 0], P[i, 1], P[i, 2], 'r-')
        Ind = np.array([[4,5], [5,6], [6,7], [7,4]]) 
        for i in Ind:        
            ax.plot(P[i, 0], P[i, 1], P[i, 2], 'r-')
        Ind = np.array([[0,4], [1,5], [2,6], [3,7]]) 
        for i in Ind:        
            ax.plot(P[i, 0], P[i, 1], P[i, 2], 'r-')
        ax.plot(P[:,0], P[:,1], P[:,2], 'bo')
        plt.show()
        return None
    
    L = 8
    B = 5
    I = 4
    alpha = 15
    beta = 30
    ful = get_vertices(L, B, I, alpha, beta)
    
    draw(ful)
    

    【讨论】:

      猜你喜欢
      • 2011-07-16
      • 1970-01-01
      • 2022-11-10
      • 2021-08-10
      • 2018-08-10
      • 2012-06-23
      • 2020-02-04
      • 2021-07-21
      • 2015-01-31
      相关资源
      最近更新 更多