Apollo 11.0
自动驾驶开放平台
math_util.h
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 The Apollo Authors. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16#pragma once
17
22namespace apollo {
23namespace localization {
24namespace msf {
25
26struct math {
27 static void EulerToQuaternion(const double x_euler, const double y_euler,
28 const double z_euler, double qbn[4]) {
29 qbn[0] = sin(x_euler / 2.0) * sin(y_euler / 2.0) * sin(z_euler / 2.0) +
30 cos(x_euler / 2.0) * cos(y_euler / 2.0) * cos(z_euler / 2.0);
31 qbn[1] = cos(y_euler / 2.0) * cos(z_euler / 2.0) * sin(x_euler / 2.0) +
32 cos(x_euler / 2.0) * sin(y_euler / 2.0) * sin(z_euler / 2.0);
33 qbn[2] = cos(x_euler / 2.0) * cos(z_euler / 2.0) * sin(y_euler / 2.0) -
34 cos(y_euler / 2.0) * sin(x_euler / 2.0) * sin(z_euler / 2.0);
35 qbn[3] = cos(z_euler / 2.0) * sin(x_euler / 2.0) * sin(y_euler / 2.0) -
36 cos(x_euler / 2.0) * cos(y_euler / 2.0) * sin(z_euler / 2.0);
37
38 return;
39 }
40
41 static void QuaternionToDcm(const double *quaternion, double dcm[3][3]) {
42 dcm[0][0] = quaternion[0] * quaternion[0] + quaternion[1] * quaternion[1] -
43 quaternion[2] * quaternion[2] - quaternion[3] * quaternion[3];
44 dcm[0][1] =
45 2 * (quaternion[1] * quaternion[2] - quaternion[0] * quaternion[3]);
46 dcm[0][2] =
47 2 * (quaternion[1] * quaternion[3] + quaternion[0] * quaternion[2]);
48
49 dcm[1][0] =
50 2 * (quaternion[1] * quaternion[2] + quaternion[0] * quaternion[3]);
51 dcm[1][1] = quaternion[0] * quaternion[0] - quaternion[1] * quaternion[1] +
52 quaternion[2] * quaternion[2] - quaternion[3] * quaternion[3];
53 dcm[1][2] =
54 2 * (quaternion[2] * quaternion[3] - quaternion[0] * quaternion[1]);
55
56 dcm[2][0] =
57 2 * (quaternion[1] * quaternion[3] - quaternion[0] * quaternion[2]);
58 dcm[2][1] =
59 2 * (quaternion[2] * quaternion[3] + quaternion[0] * quaternion[1]);
60 dcm[2][2] = quaternion[0] * quaternion[0] - quaternion[1] * quaternion[1] -
61 quaternion[2] * quaternion[2] + quaternion[3] * quaternion[3];
62 return;
63 }
64};
65
66} // namespace msf
67} // namespace localization
68} // namespace apollo
class register implement
Definition arena_queue.h:37
static void QuaternionToDcm(const double *quaternion, double dcm[3][3])
Definition math_util.h:41
static void EulerToQuaternion(const double x_euler, const double y_euler, const double z_euler, double qbn[4])
Definition math_util.h:27