GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
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
16namespace designlab {
17
30struct EulerXYZ final {
32 constexpr EulerXYZ() : x_angle(0.f), y_angle(0.f), z_angle(0.f) {}
33
38 constexpr EulerXYZ(const float x, const float y, const float z)
39 : x_angle(x), y_angle(y), z_angle(z) {}
40
41 constexpr EulerXYZ(const EulerXYZ& other) = default;
42 constexpr EulerXYZ(EulerXYZ&& other) noexcept = default;
43 constexpr EulerXYZ& operator=(const EulerXYZ& other) = default;
44
45 ~EulerXYZ() = default;
46
47 constexpr EulerXYZ operator*(const float s) const noexcept {
48 return {x_angle * s, y_angle * s, z_angle * s};
49 }
50
51 constexpr bool operator==(const EulerXYZ& other) const noexcept {
53
54 return IsEqual(x_angle, other.x_angle) && IsEqual(y_angle, other.y_angle) &&
55 IsEqual(z_angle, other.z_angle);
56 }
57
58 constexpr bool operator!=(const EulerXYZ& other) const noexcept {
59 return !(*this == other);
60 }
61
66 constexpr void SetDeg(const float x, const float y, const float z) {
70 }
71
75 [[nodiscard]] std::string ToString() const;
76
80 [[nodiscard]] std::string ToCsvString() const;
81
85 [[nodiscard]] std::string ToStringDeg() const;
86
92 [[nodiscard]] static constexpr EulerXYZ MakeEulerXYZDeg(const float x,
93 const float y,
94 const float z) {
96 return EulerXYZ{ConvertDegToRad(x), ConvertDegToRad(y), ConvertDegToRad(z)};
97 }
98
99 float x_angle;
100 float y_angle;
101 float z_angle;
102};
103
105template <class Char>
106inline std::basic_ostream<Char>& operator<<(std::basic_ostream<Char>& os,
107 const EulerXYZ& r) {
109
110 os << FloatingPointNumToString(r.x_angle) << Char(',')
111 << FloatingPointNumToString(r.y_angle) << Char(',')
112 << FloatingPointNumToString(r.z_angle);
113
114 return os;
115}
116
118template <class Char>
119inline std::basic_istream<Char>& operator>>(std::basic_istream<Char>& is,
120 EulerXYZ& r) {
121 Char unused = 0;
122 return is >> unused >> r.x_angle >> unused >> r.y_angle >> unused >>
123 r.z_angle >> unused;
124}
125
130[[nodiscard]] Vector3 RotateVector3(const Vector3& vec, const EulerXYZ& rot);
131
132} // namespace designlab
133
134#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:152
constexpr T ConvertDegToRad(const T deg) noexcept
角度を [deg] から [rad] に変換する関数.
Definition math_util.h:119
constexpr bool IsEqual(const T num1, const T num2) noexcept
C++において,小数同士の計算は誤差が出てしまう. 誤差込みで値が等しいか調べる.
Definition math_util.h:42
Vector3 RotateVector3(const Vector3 &vec, const EulerXYZ &rot)
回転させたベクトルを返す.三角関数の処理が多く重たいので注意.
std::basic_istream< Char > & operator>>(std::basic_istream< Char > &is, EulerXYZ &r)
入力ストリーム
Definition math_euler.h:119
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &os, const EulerXYZ &r)
出力ストリーム.Csv形式で出力する.カンマ区切り.単位は [rad].
Definition math_euler.h:106
XYZオイラー角を用いた回転を表す構造体.
Definition math_euler.h:30
float x_angle
X 軸周りの回転 [rad]
Definition math_euler.h:99
static constexpr EulerXYZ MakeEulerXYZDeg(const float x, const float y, const float z)
オイラー角を 単位[deg] で作成する.
Definition math_euler.h:92
float y_angle
Y 軸周りの回転 [rad]
Definition math_euler.h:100
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:47
constexpr EulerXYZ(const EulerXYZ &other)=default
constexpr EulerXYZ()
デフォルトコンストラクタでは 0,0,0 で初期化する.
Definition math_euler.h:32
std::string ToString() const
オイラー角を文字列に変換する. 単位は ラジアン [rad]
float z_angle
Z 軸周りの回転 [rad]
Definition math_euler.h:101
constexpr bool operator!=(const EulerXYZ &other) const noexcept
Definition math_euler.h:58
constexpr EulerXYZ(EulerXYZ &&other) noexcept=default
constexpr void SetDeg(const float x, const float y, const float z)
オイラー角を 単位 度 [deg] で初期化する.
Definition math_euler.h:66
constexpr EulerXYZ(const float x, const float y, const float z)
rad単位で初期化する.
Definition math_euler.h:38
constexpr bool operator==(const EulerXYZ &other) const noexcept
Definition math_euler.h:51