简体   繁体   English

在 python 中绘制 3D 截头体

[英]Plotting a 3D frustrum in python

I'm trying to plot a 3D pyramid frustum (surface plot) in a python program, where the frustum geometry is given by the plane images below:我正在尝试在 python 程序中绘制一个 3D 棱锥体(曲面图),其中截头体几何由下面的平面图像给出:

在此处输入图片说明

Where all the variables B, L, alpha, beta... will be given in my program (note that alpha is not equal to beta such in regular frustums).所有变量 B, L, alpha, beta... 将在我的程序中给出(请注意,在常规视锥体中,alpha 不等于 beta)。 Would anyone help me with any advice on how could I proceed with this?有没有人可以帮助我提供有关如何进行此操作的任何建议? Thank you in advance!先感谢您!

Something like this?像这样的东西?

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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM