Due to the lapse in federal government funding, NASA is not updating this website. We sincerely regret this inconvenience.
NASA Logo
Ocean Color Science Software

ocssw V2022
qprod.py
Go to the documentation of this file.
1 def qprod(q1,q2):
2  # Compute the product of two quaternions q3 = q1*q2
3  # input: q1, q2
4  # output: q3
5  # Liang Hong, 2/19/2020
6 
7  import numpy as np
8 
9  q3 = np.copy(q1)
10 
11  if np.size(q1)<=4:
12  q3[0] = q1[0]*q2[3] + q1[1]*q2[2] - q1[2]*q2[1] + q1[3]*q2[0]
13  q3[1] = -q1[0]*q2[2] + q1[1]*q2[3] + q1[2]*q2[0] + q1[3]*q2[1]
14  q3[2] = q1[0]*q2[1] - q1[1]*q2[0] + q1[2]*q2[3] + q1[3]*q2[2]
15  q3[3] = -q1[0]*q2[0] - q1[1]*q2[1] - q1[2]*q2[2] + q1[3]*q2[3]
16  else:
17  q3[:,0] = q1[:,0]*q2[:,3] + q1[:,1]*q2[:,2] - q1[:,2]*q2[:,1] + q1[:,3]*q2[:,0]
18  q3[:,1] = -q1[:,0]*q2[:,2] + q1[:,1]*q2[:,3] + q1[:,2]*q2[:,0] + q1[:,3]*q2[:,1]
19  q3[:,2] = q1[:,0]*q2[:,1] - q1[:,1]*q2[:,0] + q1[:,2]*q2[:,3] + q1[:,3]*q2[:,2]
20  q3[:,3] = -q1[:,0]*q2[:,0] - q1[:,1]*q2[:,1] - q1[:,2]*q2[:,2] + q1[:,3]*q2[:,3]
21 
22  return q3
def qprod(q1, q2)
Definition: qprod.py:1