GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
math_rotation_matrix.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
9
10#include <cmath>
11
12#include "math_util.h"
13
14
15namespace designlab
16{
17
19{
21
22 for (size_t i = 0; i < 3; i++)
23 {
24 for (size_t j = 0; j < 3; j++)
25 {
26 res.element[i][j] = 0.0f;
27
28 for (size_t k = 0; k < 3; k++)
29 {
30 res.element[i][j] += element[i][k] * other.element[k][j];
31 }
32 }
33 }
34
35 return res;
36}
37
39{
40 // cosは重いので,使うときはキャッシュしておく.
41 const float cos_angle = std::cos(angle);
42 const float sin_angle = std::sin(angle); // 同上.
43
44 return RotationMatrix3x3(
45 1.0f, 0.0f, 0.0f,
46 0.0f, cos_angle, -sin_angle,
47 0.0f, sin_angle, cos_angle);
48}
49
51{
52 // cosは重いので,使うときはキャッシュしておく.
53 const float cos_angle = std::cos(angle);
54 const float sin_angle = std::sin(angle); // 同上.
55
56 return RotationMatrix3x3(
57 cos_angle, 0.0f, sin_angle,
58 0.0f, 1.0f, 0.0f,
59 -sin_angle, 0.0f, cos_angle);
60}
61
63{
64 // cosは重いので,使うときはキャッシュしておく.
65 const float cos_angle = std::cos(angle);
66 const float sin_angle = std::sin(angle); // 同上.
67
68 return RotationMatrix3x3(
69 cos_angle, -sin_angle, 0.0f,
70 sin_angle, cos_angle, 0.0f,
71 0.0f, 0.0f, 1.0f);
72}
73
74std::string RotationMatrix3x3::ToString() const
75{
76 std::string res;
77
81
85
89
90 return res;
91}
92
94{
95 Vector3 res;
96
97 res.x = rot.element[0][0] * vec.x +
98 rot.element[0][1] * vec.y + rot.element[0][2] * vec.z;
99 res.y = rot.element[1][0] * vec.x +
100 rot.element[1][1] * vec.y + rot.element[1][2] * vec.z;
101 res.z = rot.element[2][0] * vec.x +
102 rot.element[2][1] * vec.y + rot.element[2][2] * vec.z;
103
104 return res;
105}
106
107} // namespace designlab
std::string FloatingPointNumToString(const T num, const int digit=kDigit, const int width=kWidth)
小数を文字列に変換する関数. C++ では C のフォーマットのように %3.3f とかで小数を文字列に変換できないため自作する.
Definition math_util.h:161
Vector3 RotateVector3(const Vector3 &vec, const EulerXYZ &rot)
回転させたベクトルを返す.三角関数の処理が多く重たいので注意.
3次元の回転行列を表す構造体.
RotationMatrix3x3()
単位行列を生成する.
RotationMatrix3x3 operator*(const RotationMatrix3x3 &other) const
static RotationMatrix3x3 CreateRotationMatrixZ(float angle)
z軸周りに回転する回転行列を生成する.
std::array< std::array< float, 3 >, 3 > element
static RotationMatrix3x3 CreateRotationMatrixY(float angle)
y軸周りに回転する回転行列を生成する.
static RotationMatrix3x3 CreateRotationMatrixX(float angle)
x軸周りに回転する回転行列を生成する.
std::string ToString() const
回転行列を文字列に変換する.
3次元の位置ベクトルを表す構造体.
float x
ロボットの正面方向に正.
float z
ロボットの上向きに正.
float y
ロボットの左向きに正.