Skip to content

Instantly share code, notes, and snippets.

@ymkim92
Created November 5, 2022 01:07
Show Gist options
  • Save ymkim92/7e8f77023ebc3eaa6c131e2efa9c026a to your computer and use it in GitHub Desktop.
Save ymkim92/7e8f77023ebc3eaa6c131e2efa9c026a to your computer and use it in GitHub Desktop.
Find x in this pyramid by Pythagorean theorem (3D drawing by matplotlib)
"""Find x in this pyramid
by Pythagorean theorem
3D drawing by matplotlib"""
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot([0,4],[0,0], [0,0], 'b')
ax.plot([0,4],[2,2], [0,0], 'b')
ax.plot([0,0],[0,2], [0,0], 'b')
ax.plot([4,4],[0,2], [0,0], 'b')
ax.plot([0,2],[0,1], [0,1], 'b')
ax.plot([4,2],[0,1], [0,1], 'b')
ax.plot([0,2],[2,1], [0,1], 'b')
ax.plot([4,2],[2,1], [0,1], 'b')
ax.text(3, 1.5, 0.5, 'x')
ax.plot([2,2],[1,1], [0,1], 'r')
ax.legend()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment