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:
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). 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)