fork download
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. def draw_fbd():
  5. fig, ax = plt.subplots(figsize=(6, 4))
  6. ax.set_xlim(-2, 14)
  7. ax.set_ylim(-5, 5)
  8.  
  9. # Draw the pipe (horizontal line)
  10. pipe_x = [0, 12]
  11. pipe_y = [0, 0]
  12. ax.plot(pipe_x, pipe_y, 'k-', linewidth=4, label="Pipe")
  13.  
  14. # Fixed support at the wall (left side)
  15. ax.add_patch(plt.Rectangle((-1.5, -1), 1.5, 2, color='gray', alpha=0.6, label="Fixed Support"))
  16.  
  17. # Force P downward at the end
  18. ax.arrow(12, 0, 0, -2, head_width=0.5, head_length=0.5, fc='r', ec='r', label="Force P (40 lb)")
  19. ax.text(12.2, -2, "$P=40$ lb", fontsize=10, color='r')
  20.  
  21. # Bending moment (curved arrow at fixed end)
  22. ax.annotate('', xy=(0, 2), xytext=(0, 1), arrowprops=dict(arrowstyle='->', color='b', lw=2))
  23. ax.text(-0.5, 2, "$M=480$ lb-in", fontsize=10, color='b')
  24.  
  25. # Torsional moment (curved arrow around pipe axis)
  26. ax.annotate('', xy=(1, 0.5), xytext=(0.5, 1), arrowprops=dict(arrowstyle='->', color='purple', lw=2))
  27. ax.text(1, 1, "$T=360$ lb-in", fontsize=10, color='purple')
  28.  
  29. # Labels
  30. ax.text(6, 0.5, "Pipe Wrench Handle", fontsize=10, color='black')
  31. ax.text(-1.8, 0, "Fixed Support", fontsize=10, color='black')
  32.  
  33. # Hide axes
  34. ax.set_xticks([])
  35. ax.set_yticks([])
  36. ax.spines['top'].set_visible(False)
  37. ax.spines['right'].set_visible(False)
  38. ax.spines['left'].set_visible(False)
  39. ax.spines['bottom'].set_visible(False)
  40.  
  41. plt.legend()
  42. plt.title("Free-Body Diagram of Pipe Wrench")
  43. plt.show()
  44.  
  45. draw_fbd()
  46.  
  47.  
Success #stdin #stdout 0.03s 25788KB
stdin
Standard input is empty
stdout
import matplotlib.pyplot as plt
import numpy as np

def draw_fbd():
    fig, ax = plt.subplots(figsize=(6, 4))
    ax.set_xlim(-2, 14)
    ax.set_ylim(-5, 5)
    
    # Draw the pipe (horizontal line)
    pipe_x = [0, 12]
    pipe_y = [0, 0]
    ax.plot(pipe_x, pipe_y, 'k-', linewidth=4, label="Pipe")
    
    # Fixed support at the wall (left side)
    ax.add_patch(plt.Rectangle((-1.5, -1), 1.5, 2, color='gray', alpha=0.6, label="Fixed Support"))
    
    # Force P downward at the end
    ax.arrow(12, 0, 0, -2, head_width=0.5, head_length=0.5, fc='r', ec='r', label="Force P (40 lb)")
    ax.text(12.2, -2, "$P=40$ lb", fontsize=10, color='r')
    
    # Bending moment (curved arrow at fixed end)
    ax.annotate('', xy=(0, 2), xytext=(0, 1), arrowprops=dict(arrowstyle='->', color='b', lw=2))
    ax.text(-0.5, 2, "$M=480$ lb-in", fontsize=10, color='b')
    
    # Torsional moment (curved arrow around pipe axis)
    ax.annotate('', xy=(1, 0.5), xytext=(0.5, 1), arrowprops=dict(arrowstyle='->', color='purple', lw=2))
    ax.text(1, 1, "$T=360$ lb-in", fontsize=10, color='purple')
    
    # Labels
    ax.text(6, 0.5, "Pipe Wrench Handle", fontsize=10, color='black')
    ax.text(-1.8, 0, "Fixed Support", fontsize=10, color='black')
    
    # Hide axes
    ax.set_xticks([])
    ax.set_yticks([])
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['left'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    
    plt.legend()
    plt.title("Free-Body Diagram of Pipe Wrench")
    plt.show()

draw_fbd()