33 lines
845 B
Python
33 lines
845 B
Python
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
from mpl_toolkits.mplot3d import Axes3D
|
|
|
|
# 定义不规则图形的顶点坐标
|
|
polygon1_points = np.array([[0, 0], [1, 0], [1, 1], [0, 1]])
|
|
polygon2_points = np.array([[1.5, 0.5], [2.5, 0.5], [2.5, 1.5], [1.5, 1.5]])
|
|
|
|
# 创建三维图形
|
|
fig = plt.figure()
|
|
ax = fig.add_subplot(111, projection='3d')
|
|
|
|
# 绘制第一个不规则图形
|
|
x1, y1 = polygon1_points[:, 0], polygon1_points[:, 1]
|
|
X1, Y1 = np.meshgrid(x1, y1)
|
|
Z1 = np.zeros_like(X1)
|
|
#ax.plot_surface(X1, Y1, Z1, color='r', alpha=0.5)
|
|
|
|
|
|
# 绘制第二个不规则图形
|
|
x2, y2 = polygon2_points[:, 0], polygon2_points[:, 1]
|
|
X2, Y2 = np.meshgrid(x2, y2)
|
|
Z2 = np.zeros_like(X2)
|
|
ax.plot_surface(X2, Y2, Z2, color='g', alpha=0.5)
|
|
|
|
|
|
# 设置坐标轴标签
|
|
ax.set_xlabel('X axis')
|
|
ax.set_ylabel('Y axis')
|
|
ax.set_zlabel('Z axis')
|
|
|
|
plt.show()
|