Untitled

 avatar
unknown
plain_text
a month ago
951 B
3
Indexable
import matplotlib.pyplot as plt
import numpy as np

# Example 1: Ladder Leaning Against a Wall
ladder_length = 8
base = 4
height = np.sqrt(ladder_length**2 - base**2)

fig, ax = plt.subplots(figsize=(6,5))
# Plot the triangle
ax.plot([0, base], [height, 0], 'r-', lw=2, label="Ladder (Hypotenuse)")
ax.plot([0, 0], [0, height], 'b--', lw=2, label="Wall (Vertical)")
ax.plot([0, base], [0, 0], 'g--', lw=2, label="Ground (Horizontal)")

# Annotate key points
ax.annotate("Top of Ladder", xy=(0, height), xytext=(-1, height+0.5))
ax.annotate("Base of Ladder", xy=(base, 0), xytext=(base+0.2, -0.5))
ax.annotate(f"60°", xy=(base-0.5, 0), xytext=(base-1.5, 1))

# Mark the right angle
ax.plot([0, 0.5, 0.5], [0, 0, 0.5], 'k-')

ax.set_title("Example 1: Ladder Leaning Against a Wall")
ax.set_xlabel("Distance (m)")
ax.set_ylabel("Height (m)")
ax.legend()
ax.grid(True)
plt.xlim(-2, base+2)
plt.ylim(-1, height+2)
plt.show()
Editor is loading...
Leave a Comment