GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
math_rotation_matrix_test.h
[詳解]
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
8#ifndef DESIGNLAB_MATH_ROTATION_MATRIX_TEST_H_
9#define DESIGNLAB_MATH_ROTATION_MATRIX_TEST_H_
10
11#include <doctest.h>
12
14
15TEST_SUITE("RotationMatrix3x3")
16{
18
19 TEST_CASE("ConstructorTest_ShouldCreateIdentityMatrix")
20 {
21 // デフォルトコンストラクタで単位行列が生成される.
22 const RotationMatrix3x3 rot_mat;
23
24 // 単位行列の確認.
25 CHECK(rot_mat.element[0][0] == doctest::Approx(1.0f));
26 CHECK(rot_mat.element[0][1] == doctest::Approx(0.0f));
27 CHECK(rot_mat.element[0][2] == doctest::Approx(0.0f));
28
29 CHECK(rot_mat.element[1][0] == doctest::Approx(0.0f));
30 CHECK(rot_mat.element[1][1] == doctest::Approx(1.0f));
31 CHECK(rot_mat.element[1][2] == doctest::Approx(0.0f));
32
33 CHECK(rot_mat.element[2][0] == doctest::Approx(0.0f));
34 CHECK(rot_mat.element[2][1] == doctest::Approx(0.0f));
35 CHECK(rot_mat.element[2][2] == doctest::Approx(1.0f));
36 }
37
38 TEST_CASE("ConstructorTest_ShouldCreateArbitraryMatrix")
39 {
40 // 任意の行列を生成する.
41 const RotationMatrix3x3 rot_mat(1.0f, 2.0f, 3.0f,
42 4.0f, 5.0f, 6.0f,
43 7.0f, 8.0f, 9.0f);
44
45 // 任意の行列の確認.
46 CHECK(rot_mat.element[0][0] == doctest::Approx(1.0f));
47 CHECK(rot_mat.element[0][1] == doctest::Approx(2.0f));
48 CHECK(rot_mat.element[0][2] == doctest::Approx(3.0f));
49
50 CHECK(rot_mat.element[1][0] == doctest::Approx(4.0f));
51 CHECK(rot_mat.element[1][1] == doctest::Approx(5.0f));
52 CHECK(rot_mat.element[1][2] == doctest::Approx(6.0f));
53
54 CHECK(rot_mat.element[2][0] == doctest::Approx(7.0f));
55 CHECK(rot_mat.element[2][1] == doctest::Approx(8.0f));
56 CHECK(rot_mat.element[2][2] == doctest::Approx(9.0f));
57 }
58
59 TEST_CASE("ArithmeticOperatorTest")
60 {
61 SUBCASE("Multiplication")
62 {
63 // 任意の行列を生成する.
64 const RotationMatrix3x3 rot_mat1(1.0f, 2.0f, 3.0f,
65 4.0f, 5.0f, 6.0f,
66 7.0f, 8.0f, 9.0f);
67
68 // 任意の行列を生成する.
69 const RotationMatrix3x3 rot_mat2(9.0f, 8.0f, 7.0f,
70 6.0f, 5.0f, 4.0f,
71 3.0f, 2.0f, 1.0f);
72
73 const RotationMatrix3x3 actual = rot_mat1 * rot_mat2;
74
75 // 任意の行列を生成する.
76 const RotationMatrix3x3 expect(30.0f, 24.0f, 18.0f,
77 84.0f, 69.0f, 54.0f,
78 138.0f, 114.0f, 90.0f);
79
80 // 任意の行列の確認.
81 CHECK(actual.element[0][0] == doctest::Approx(expect.element[0][0]));
82 CHECK(actual.element[0][1] == doctest::Approx(expect.element[0][1]));
83 CHECK(actual.element[0][2] == doctest::Approx(expect.element[0][2]));
84
85 CHECK(actual.element[1][0] == doctest::Approx(expect.element[1][0]));
86 CHECK(actual.element[1][1] == doctest::Approx(expect.element[1][1]));
87 CHECK(actual.element[1][2] == doctest::Approx(expect.element[1][2]));
88
89 CHECK(actual.element[2][0] == doctest::Approx(expect.element[2][0]));
90 CHECK(actual.element[2][1] == doctest::Approx(expect.element[2][1]));
91 CHECK(actual.element[2][2] == doctest::Approx(expect.element[2][2]));
92 }
93 }
94
95 TEST_CASE("CreateRotationMatrixXTest")
96 {
98
99 constexpr float angle = ConvertDegToRad(30.0f);
100
101 const RotationMatrix3x3 rot_mat = RotationMatrix3x3::CreateRotationMatrixX(angle);
102
103 const float cos_angle = std::cos(angle);
104 const float sin_angle = std::sin(angle);
105
106 CHECK(rot_mat.element[0][0] == doctest::Approx(1.0f));
107 CHECK(rot_mat.element[0][1] == doctest::Approx(0.0f));
108 CHECK(rot_mat.element[0][2] == doctest::Approx(0.0f));
109
110 CHECK(rot_mat.element[1][0] == doctest::Approx(0.0f));
111 CHECK(rot_mat.element[1][1] == doctest::Approx(cos_angle));
112 CHECK(rot_mat.element[1][2] == doctest::Approx(-sin_angle));
113
114 CHECK(rot_mat.element[2][0] == doctest::Approx(0.0f));
115 CHECK(rot_mat.element[2][1] == doctest::Approx(sin_angle));
116 CHECK(rot_mat.element[2][2] == doctest::Approx(cos_angle));
117 }
118
119 TEST_CASE("CreateRotationMatrixYTest")
120 {
122
123 constexpr float angle = ConvertDegToRad(30.0f);
124
125 const RotationMatrix3x3 rot_mat = RotationMatrix3x3::CreateRotationMatrixY(angle);
126
127 const float cos_angle = std::cos(angle);
128 const float sin_angle = std::sin(angle);
129
130 CHECK(rot_mat.element[0][0] == doctest::Approx(cos_angle));
131 CHECK(rot_mat.element[0][1] == doctest::Approx(0.0f));
132 CHECK(rot_mat.element[0][2] == doctest::Approx(sin_angle));
133
134 CHECK(rot_mat.element[1][0] == doctest::Approx(0.0f));
135 CHECK(rot_mat.element[1][1] == doctest::Approx(1.0f));
136 CHECK(rot_mat.element[1][2] == doctest::Approx(0.0f));
137
138 CHECK(rot_mat.element[2][0] == doctest::Approx(-sin_angle));
139 CHECK(rot_mat.element[2][1] == doctest::Approx(0.0f));
140 CHECK(rot_mat.element[2][2] == doctest::Approx(cos_angle));
141 }
142
143 TEST_CASE("CreateRotationMatrixZTest")
144 {
146
147 constexpr float angle = ConvertDegToRad(30.0f);
148
149 const RotationMatrix3x3 rot_mat = RotationMatrix3x3::CreateRotationMatrixZ(angle);
150
151 const float cos_angle = std::cos(angle);
152 const float sin_angle = std::sin(angle);
153
154 CHECK(rot_mat.element[0][0] == doctest::Approx(cos_angle));
155 CHECK(rot_mat.element[0][1] == doctest::Approx(-sin_angle));
156 CHECK(rot_mat.element[0][2] == doctest::Approx(0.0f));
157
158 CHECK(rot_mat.element[1][0] == doctest::Approx(sin_angle));
159 CHECK(rot_mat.element[1][1] == doctest::Approx(cos_angle));
160 CHECK(rot_mat.element[1][2] == doctest::Approx(0.0f));
161
162 CHECK(rot_mat.element[2][0] == doctest::Approx(0.0f));
163 CHECK(rot_mat.element[2][1] == doctest::Approx(0.0f));
164 CHECK(rot_mat.element[2][2] == doctest::Approx(1.0f));
165 }
166}
167
168#endif // DESIGNLAB_MATH_ROTATION_MATRIX_TEST_H_
TEST_SUITE("RotationMatrix3x3")
constexpr T ConvertDegToRad(const T deg) noexcept
角度を [deg] から [rad] に変換する関数.
Definition math_util.h:126
3次元の回転行列を表す構造体.