I am writing a code to compute the Angle of Attack and Angle of Side Slip of an aircraft, based on the aircraft's orientation and global velocity vector. All of my data is housed in a dataframe. To calculate the angles, I first need to determine the aircraft-relative velocity and I do that with this bit of code. From there it is a trivial to get the Angle of Attack and Angle of Side Slip.
This code works, but I feel like I am missing something that would make it run faster. Does anyone have any ideas?
# Calculate aircraft component velocities
df['a11'] = np.cos(df['Pitch']) * np.cos(df['Yaw'])
df['a12'] = np.cos(df['Pitch']) * np.sin(df['Yaw'])
df['a13'] = -1 * np.sin(df['Pitch'])
df['a21'] = np.sin(df['Pitch']) * np.sin(df['Roll']) * np.cos(df['Yaw']) - np.cos(df['Roll']) * np.sin(df['Yaw'])
df['a22'] = np.sin(df['Pitch']) * np.sin(df['Roll']) * np.sin(df['Yaw']) + np.cos(df['Roll']) * np.cos(df['Yaw'])
df['a23'] = np.sin(df['Roll']) * np.cos(df['Pitch'])
df['a31'] = np.cos(df['Yaw']) * np.cos(df['Roll']) * np.sin(df['Pitch']) + np.sin(df['Roll']) * np.sin(df['Yaw'])
df['a32'] = np.sin(df['Yaw']) * np.cos(df['Roll']) * np.sin(df['Pitch']) - np.sin(df['Roll']) * np.cos(df['Yaw'])
df['a33'] = np.cos(df['Roll']) * np.cos(df['Pitch'])
df['Vxx'] = 0
df['Vyy'] = 0
df['Vzz'] = 0
for idx, row in df.iterrows():
A = [[row['a11'], row['a12'], row['a13']],
[row['a21'], row['a22'], row['a23']],
[row['a31'], row['a32'], row['a33']]]
B = [[row['Vx']], [row['Vy']], [row['Vz']]]
result = list()
for i in range(len(A)):
result.append([0])
for i in range(3):
for j in range(1):
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]
df.loc[idx, 'Vxx'] = result[0][0]
df.loc[idx, 'Vyy'] = result[1][0]
df.loc[idx, 'Vzz'] = result[2][0]