def euler_to_quaternion(r):
(yaw, pitch, roll) = (r[0], r[1], r[2])
qx = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
qy = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)
qz = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)
qw = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
return [qx, qy, qz, qw]
def quaternion_to_euler(q):
(x, y, z, w) = (q[0], q[1], q[2], q[3])
t0 = +2.0 * (w * x + y * z)
t1 = +1.0 - 2.0 * (x * x + y * y)
roll = math.atan2(t0, t1)
t2 = +2.0 * (w * y - z * x)
t2 = +1.0 if t2 > +1.0 else t2
t2 = -1.0 if t2 < -1.0 else t2
pitch = math.asin(t2)
t3 = +2.0 * (w * z + x * y)
t4 = +1.0 - 2.0 * (y * y + z * z)
yaw = math.atan2(t3, t4)
return [yaw, pitch, roll]
>>> q = euler_to_quaternion([0.2,1.12,2.31])
>>> r = quaternion_to_euler(q)
>>> r
[0.20000000000000026, 1.1200000000000006, 2.3100000000000005]
'Autonomous Vehicle' 카테고리의 다른 글
Polynomial Line Fitting Removing Outliers Using RANSAC (Python Code) (0) | 2021.11.15 |
---|---|
Points Polynomial Line Fitting (Python Code) (0) | 2021.11.15 |
ZED F9P with RTK - WGS to UTM (0) | 2021.11.09 |
Docker exec 명령어 : 외장그래픽 연결, 디스플레이 연결, 폴더 공유 설정 (0) | 2021.10.21 |
Docker 도커 이미지, 컨테이너 백업하고 삭제하는 방법 (0) | 2021.10.12 |