#Sway Bar Calculator
#Inputs
sigma = 100 # Max Shear Stress (ksi)
G = 11600 # Shear Modulus (ksi)
L = 40 # Length Tip to Tip (inches)
OD = 1 # Outer diameter (inches)
ID = 0 # Inner diameter (inches), enter 0 if solid bar
A = 16 # Arm Length (inches), center to center
O = 2 # Arm Offset (inches), enter negative number for arms wider at sway bar side
Y = 44 # Distance between shock mounts at axle (inches)
T = 12 # Shock travel (inches)
#Setup
import math
pi = math.pi
L_w = L - 4 # Working Length
#Formulas
theta = 2 * L_w * sigma / (G * OD) # Max Twist Angle (radians)
theta_d = theta * 180 / pi # Convert from radians to degrees
J = pi/32 * (OD ** 4 - ID ** 4 ) # Polar Moment of Inertia (in^4)
tau = 1000 * J * G * theta / L_w # Torque at Max Twist Angle (in-lbs)
F = tau / A # Force at Max Twist Angle (lbs)
K = tau / (theta * A ** 2) # Sway bar rate (lbs/in)
flex = theta * A * Y / (L + 2 * O) # Max articulation (in)
lim = 100 * flex / T # Flex limited from sway bar (as percentage, >100%: sway bar does not limit flex)
#Outputs
print("Max Twist Angle =", round(theta_d,1), "°")
print("Force at Max Twist =", round(F,2), "lbs")
print("Sway Bar Rate =", round(K,1), "lbs/in")
print("Max Articulation (at shocks) =", round(flex,2), "in")
print("Usable Flex =", round(lim,1), "%")