forceArray = np.array([[dxA/lA],[dxB/lB],[dxC/lC],[dxD/lD],[dxE/lE],[dxF/lF], [dyA/lA],[dyB/lB],[dyC/lC],[dyD/lD],[dyE/lE],[dyF/lF], [dzA/lA],[dzB/lB],[dzC/lC],[dzD/lD],[dzE/lE],[dzF/lF], [mA[0]], [mB[0]], [mC[0]], [mD[0]], [mE[0]], [mF[0]], [mA[1]], [mB[1]], [mC[1]], [mD[1]], [mE[1]], [mF[1]], [mA[2]], [mB[2]], [mC[2]], [mD[2]], [mE[2]], [mF[2]]])
forceMatrix = np.reshape(forceArray, (6,6))
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from numpy.linalg import inv
g = 9.81 # Gravitational acceleration
# Vehicle parameters
mass = 310 # kg
wb = 1550 # Wheelbase in mm
tw = 1200 # Track width in mm
cm = 280 # Center of mass height in mm
wd = 0.5 # Static weight distribution (front load fraction)
# Suspension coordinates (updated with separate upright points)
# Replace the placeholder values with your actual coordinates
# Fore and aft lower wishbone upright attachment points
fb = np.array([[10, -50, 110], [210, -390, 120]]) # Fore lower
ab = np.array([[-10, -50, 110], [-150, -390, 150]]) # Aft lower
# Fore and aft upper wishbone upright attachment points
ft = np.array([[10, -50, 300], [110, -340, 280]]) # Fore upper
at = np.array([[-10, -50, 300], [-130, -340, 260]]) # Aft upper
# Damper
d = np.array([[-5, -90, 260], [-5, -270, 100]])
# Tie rod
tr = np.array([[50, -40, 145], [80, -420, 180]])
# Contact patch
cP = np.array([0, 0, 0])
# Applied force in G's (longitudinal, lateral, normal)
fap = np.array([0, 1.7, 0])
# Calculate weight transfer
h_cg = cm / 1000 # Convert to meters
tw_m = tw / 1000 # Convert to meters
wtLat = mass * fap[1] * g * h_cg / tw_m
# Vertical load on this wheel
Fz_static = wd * mass * g / 2
Fz = Fz_static + wtLat / 2
# Update fap with actual forces
fap[2] = Fz
fzPercent = Fz / (mass * g)
fap[1] = fap[1] * g * mass * fzPercent
# Extract points for calculations
A = fb[0]
B = ab[0]
C = ft[0]
D = at[0]
E = d[0]
F = tr[0]
# Total applied force/moment vectors
mom = np.cross(cP, fap)
fapTot = np.concatenate((fap, mom)).reshape(6, 1)
# Delta calculations
def delta(p1, p2):
return p2 - p1
dxA, dyA, dzA = delta(fb[0], fb[1])
dxB, dyB, dzB = delta(ab[0], ab[1])
dxC, dyC, dzC = delta(ft[0], ft[1])
dxD, dyD, dzD = delta(at[0], at[1])
dxE, dyE, dzE = delta(d[0], d[1])
dxF, dyF, dzF = delta(tr[0], tr[1])
# Lengths of each member
def length(dx, dy, dz):
return np.sqrt(dx**2 + dy**2 + dz**2)
lA = length(dxA, dyA, dzA)
lB = length(dxB, dyB, dzB)
lC = length(dxC, dyC, dzC)
lD = length(dxD, dyD, dzD)
lE = length(dxE, dyE, dzE)
lF = length(dxF, dyF, dzF)
# Unit force vectors
forceA = np.array([dxA/lA, dyA/lA, dzA/lA])
forceB = np.array([dxB/lB, dyB/lB, dzB/lB])
forceC = np.array([dxC/lC, dyC/lC, dzC/lC])
forceD = np.array([dxD/lD, dyD/lD, dzD/lD])
forceE = np.array([dxE/lE, dyE/lE, dzE/lE])
forceF = np.array([dxF/lF, dyF/lF, dzF/lF])
# Moments about the origin
mA = np.cross(A, forceA)
mB = np.cross(B, forceB)
mC = np.cross(C, forceC)
mD = np.cross(D, forceD)
mE = np.cross(E, forceE)
mF = np.cross(F, forceF)
# Assemble force matrix
forceMatrix = np.array([
[dxA/lA, dxB/lB, dxC/lC, dxD/lD, dxE/lE, dxF/lF],
[dyA/lA, dyB/lB, dyC/lC, dyD/lD, dyE/lE, dyF/lF],
[dzA/lA, dzB/lB, dzC/lC, dzD/lD, dzE/lE, dzF/lF],
[mA[0], mB[0], mC[0], mD[0], mE[0], mF[0]],
[mA[1], mB[1], mC[1], mD[1], mE[1], mF[1]],
[mA[2], mB[2], mC[2], mD[2], mE[2], mF[2]]
])
# Solve for forces in members
forces = np.dot(inv(forceMatrix), fapTot)
print("Forces in members:")
print(forces)
# Compute Upper Ball Joint Forces
UBJ = np.array([
forces[2][0]*np.array([dxC, dyC, dzC])/lC + forces[3][0]*np.array([dxD, dyD, dzD])/lD
])
print("Upper Ball Joint Forces:")
print(UBJ)
# Plotting the suspension geometry
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# Function to plot links
def plot_link(p1, p2, color, label):
xs = [p1[0], p2[0]]
ys = [p1[1], p2[1]]
zs = [p1[2], p2[2]]
ax.plot(xs, ys, zs, color=color, label=label)
plot_link(fb[0], fb[1], 'green', 'Fore Lower Arm')
plot_link(ab[0], ab[1], 'green', 'Aft Lower Arm')
plot_link(ft[0], ft[1], 'blue', 'Fore Upper Arm')
plot_link(at[0], at[1], 'blue', 'Aft Upper Arm')
plot_link(d[0], d[1], 'red', 'Damper')
plot_link(tr[0], tr[1], 'purple', 'Tie Rod')
ax.scatter(cP[0], cP[1], cP[2], color='black', label='Contact Patch')
# Set labels and aspect ratio
ax.set_xlabel('X (mm)')
ax.set_ylabel('Y (mm)')
ax.set_zlabel('Z (mm)')
ax.set_box_aspect([1,1,1])
ax.legend()
plt.show()