GaitGeneration by Graph Search
全て クラス 名前空間 ファイル 関数 変数 型定義 列挙型 列挙値 マクロ定義 ページ Concepts
math_euler.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_EULER_H_
9#define DESIGNLAB_MATH_EULER_H_
10
11#include <string>
12
13#include "math_util.h"
14#include "math_vector3.h"
15
16
17namespace designlab
18{
19
32struct EulerXYZ final
33{
35 constexpr EulerXYZ() : x_angle(0.f), y_angle(0.f), z_angle(0.f) {}
36
41 constexpr EulerXYZ(const float x, const float y, const float z) :
42 x_angle(x),
43 y_angle(y),
44 z_angle(z)
45 {
46 }
47
48 constexpr EulerXYZ(const EulerXYZ& other) = default;
49 constexpr EulerXYZ(EulerXYZ&& other) noexcept = default;
50 constexpr EulerXYZ& operator =(const EulerXYZ& other) = default;
51
52 ~EulerXYZ() = default;
53
54 constexpr EulerXYZ operator *(const float s) const noexcept
55 {
56 return { x_angle * s, y_angle * s, z_angle * s };
57 }
58
59
60 constexpr bool operator ==(const EulerXYZ& other) const noexcept
61 {
63
64 return IsEqual(x_angle, other.x_angle) && IsEqual(y_angle, other.y_angle) && IsEqual(z_angle, other.z_angle);
65 }
66
67 constexpr bool operator !=(const EulerXYZ& other) const noexcept
68 {
69 return !(*this == other);
70 }
71
72
77 constexpr void SetDeg(const float x, const float y, const float z)
78 {
82 }
83
87 [[nodiscard]] std::string ToString() const;
88
92 [[nodiscard]] std::string ToCsvString() const;
93
97 [[nodiscard]] std::string ToStringDeg() const;
98
104 [[nodiscard]] static constexpr EulerXYZ MakeEulerXYZDeg(const float x, const float y, const float z)
105 {
107 }
108
109 float x_angle;
110 float y_angle;
111 float z_angle;
112};
113
114
116template <class Char>
117inline std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const EulerXYZ& r)
118{
120
121 os << FloatingPointNumToString(r.x_angle) << Char(',') << FloatingPointNumToString(r.y_angle) << Char(',') << FloatingPointNumToString(r.z_angle);
122
123 return os;
124}
125
127template <class Char>
128inline std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, EulerXYZ& r)
129{
130 Char unused = 0;
131 return is >> unused >> r.x_angle >> unused >> r.y_angle >> unused >> r.z_angle >> unused;
132}
133
134
139[[nodiscard]] Vector3 RotateVector3(const Vector3& vec, const EulerXYZ& rot);
140
141} // namespace designlab
142
143
144#endif // DESIGNLAB_MATH_EULER_H_
std::string FloatingPointNumToString(const T num, const int digit=kDigit, const int width=kWidth)
小数を文字列に変換する関数. C++ では C のフォーマットのように %3.3f とかで小数を文字列に変換できないため自作する.
Definition math_util.h:161
constexpr T ConvertDegToRad(const T deg) noexcept
角度を [deg] から [rad] に変換する関数.
Definition math_util.h:126
constexpr bool IsEqual(const T num1, const T num2) noexcept
C++において,小数同士の計算は誤差が出てしまう. 誤差込みで値が等しいか調べる.
Definition math_util.h:45
Vector3 RotateVector3(const Vector3 &vec, const EulerXYZ &rot)
回転させたベクトルを返す.三角関数の処理が多く重たいので注意.
std::basic_istream< Char > & operator>>(std::basic_istream< Char > &is, EulerXYZ &r)
入力ストリーム
Definition math_euler.h:128
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &os, const EulerXYZ &r)
出力ストリーム.Csv形式で出力する.カンマ区切り.単位は [rad].
Definition math_euler.h:117
XYZオイラー角を用いた回転を表す構造体.
Definition math_euler.h:33
float x_angle
X 軸周りの回転 [rad]
Definition math_euler.h:109
static constexpr EulerXYZ MakeEulerXYZDeg(const float x, const float y, const float z)
オイラー角を 単位[deg] で作成する.
Definition math_euler.h:104
float y_angle
Y 軸周りの回転 [rad]
Definition math_euler.h:110
constexpr EulerXYZ & operator=(const EulerXYZ &other)=default
std::string ToStringDeg() const
オイラー角を文字列に変換する. 単位は 度 [deg].
std::string ToCsvString() const
オイラー角をCsv形式の文字列に変換する.カンマ区切り. 単位は ラジアン [rad]
constexpr EulerXYZ operator*(const float s) const noexcept
Definition math_euler.h:54
constexpr EulerXYZ(const EulerXYZ &other)=default
constexpr EulerXYZ()
デフォルトコンストラクタでは 0,0,0 で初期化する.
Definition math_euler.h:35
std::string ToString() const
オイラー角を文字列に変換する. 単位は ラジアン [rad]
float z_angle
Z 軸周りの回転 [rad]
Definition math_euler.h:111
constexpr bool operator!=(const EulerXYZ &other) const noexcept
Definition math_euler.h:67
constexpr EulerXYZ(EulerXYZ &&other) noexcept=default
constexpr void SetDeg(const float x, const float y, const float z)
オイラー角を 単位 度 [deg] で初期化する.
Definition math_euler.h:77
constexpr EulerXYZ(const float x, const float y, const float z)
rad単位で初期化する.
Definition math_euler.h:41
constexpr bool operator==(const EulerXYZ &other) const noexcept
Definition math_euler.h:60