import matplotlib.pyplot as plt from mpl_toolkits.mplot3d.art3d import Poly3DCollection def plot_3d_figure(): fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, projection='3d') # Define the vertices of the inscribed tetrahedron # The bounding box is a 6x6x6 cube v1 = [0, 0, 6] # Top-left-front v2 = [6, 0, 0] # Bottom-right-front v3 = [0, 6, 0] # Bottom-left-back v4 = [6, 6, 6] # Top-right-back # Define the 4 triangular faces of the tetrahedron faces = [ [v1, v2, v3], [v1, v2, v4], [v1, v3, v4], [v2, v3, v4] ] # Create the 3D polygon collection poly3d = Poly3DCollection(faces, facecolors='#4C99D1', linewidths=1.5, edgecolors='black', alpha=0.85) ax.add_collection3d(poly3d) # Draw the bounding box (cube) with dashed lines for better visualization context cube_vertices = [ [0,0,0], [6,0,0], [6,6,0], [0,6,0], [0,0,6], [6,0,6], [6,6,6], [0,6,6] ] cube_edges = [ (0,1), (1,2), (2,3), (3,0), # bottom (4,5), (5,6), (6,7), (7,4), # top (0,4), (1,5), (2,6), (3,7) # vertical ] for edge in cube_edges: p1 = cube_vertices[edge[0]] p2 = cube_vertices[edge[1]] ax.plot([p1[0], p2[0]], [p1[1], p2[1]], [p1[2], p2[2]], color='gray', linestyle='--', linewidth=1, alpha=0.4) # Set axes limits ax.set_xlim([0, 6]) ax.set_ylim([0, 6]) ax.set_zlim([0, 6]) # Set labels ax.set_xlabel('X (Width)') ax.set_ylabel('Y (Depth)') ax.set_zlabel('Z (Height)') # Set viewing angle to clearly see the shape ax.view_init(elev=25, azim=-55) # Force equal proportions for the axes ax.set_box_aspect([1, 1, 1]) plt.title("3D Reconstruction: Regular Tetrahedron Inscribed in a Cube", fontsize=14, pad=20) plt.tight_layout() plt.show() if __name__ == "__main__": plot_3d_figure()