8#ifndef DESIGNLAB_MATH_VECTOR3_H_
9#define DESIGNLAB_MATH_VECTOR3_H_
44 constexpr Vector3(
const float x_pos,
const float y_pos,
const float z_pos) :
76 return !(*
this == other);
92 return !(*
this > other);
97 return !(*
this < other);
107 return {
x + other.
x ,
y + other.y,
z + other.z };
112 return {
x - other.
x ,
y - other.y,
z - other.z };
117 return {
x * num,
y * num,
z * num };
122 return {
x / num,
y / num,
z / num };
136 return x *
x +
y *
y +
z *
z;
151 [[nodiscard]]
constexpr float Dot(
const Vector3& other)
const noexcept
153 return x * other.x +
y * other.y +
z * other.z;
162 return Vector3{
y * other.
z -
z * other.y,
z * other.x -
x * other.z,
x * other.y -
y * other.x };
170 return (*
this - other).GetLength();
182 [[nodiscard]] constexpr
bool IsZero() const noexcept
235 [[nodiscard]] std::string
ToString()
const;
255 return { s * vec.x, s * vec.y, s * vec.z };
262std::basic_ostream<Char>&
operator <<(std::basic_ostream<Char>& os,
const Vector3& v)
275 return is >> v.
x >> unused >> v.
y >> unused >> v.
z;
std::string FloatingPointNumToString(const T num, const int digit=kDigit, const int width=kWidth)
小数を文字列に変換する関数. C++ では C のフォーマットのように %3.3f とかで小数を文字列に変換できないため自作する.
constexpr bool IsEqual(const T num1, const T num2) noexcept
C++において,小数同士の計算は誤差が出てしまう. 誤差込みで値が等しいか調べる.
constexpr Quaternion operator*(float s, const Quaternion &q)
std::basic_istream< Char > & operator>>(std::basic_istream< Char > &is, EulerXYZ &r)
入力ストリーム
std::basic_ostream< Char > & operator<<(std::basic_ostream< Char > &os, const EulerXYZ &r)
出力ストリーム.Csv形式で出力する.カンマ区切り.単位は [rad].
constexpr Vector3 operator+() const noexcept
Vector3 & operator*=(const float num) noexcept
constexpr bool operator==(const Vector3 &v) const noexcept
2つのベクトルが等しいかどうかを返す.誤差を許容する.
constexpr Vector3 Cross(const Vector3 &other) const noexcept
自分×引数 の外積の結果を返す.
constexpr float GetSquaredLength() const noexcept
ベクトルの長さの2乗を返す.
bool operator<(const Vector3 &other) const noexcept
Vector3 & operator-=(const Vector3 &other) noexcept
static constexpr Vector3 GetUpVec() noexcept
上に進む単位ベクトルを返す. 静的な関数なので,Vector3::GetUpVec() と呼び出せる.
constexpr Vector3(const float x_pos, const float y_pos, const float z_pos)
constexpr bool IsZero() const noexcept
x,y,zともに絶対値が0ならば true を返す.
constexpr bool operator!=(const Vector3 &other) const noexcept
Vector3 GetNormalized() const noexcept
単位ベクトルを返す. normalizeとは,ベクトルを正規化(単位ベクトルに変換)する操作を表す. 絶対値が0のベクトルの場合,そのまま0ベクトルを返す.
constexpr Vector3 operator*(const float num) const noexcept
constexpr Vector3 operator-() const noexcept
constexpr Vector3 operator/(const float num) const
constexpr Vector3()
< デフォルトコンストラクタ.(0,0,0)で初期化される.
bool operator>=(const Vector3 &other) const noexcept
std::string ToCsvString() const
このベクトルをCSV形式の文字列にして返す. x, y, z の形式,小数点以下3桁まで.
static constexpr Vector3 GetFrontVec() noexcept
正面に進む単位ベクトルを返す. 静的な関数なので,Vector3::GetFrontVec() と呼び出せる.
constexpr Vector3(const Vector3 &other)=default
コピーコンストラクタ.
constexpr Vector3 & operator=(const Vector3 &other)=default
代入演算子.
constexpr float Dot(const Vector3 &other) const noexcept
自分・引数 の内積の結果を返す.
float GetLength() const noexcept
ベクトルの長さを返す.
float GetDistanceFrom(const Vector3 &other) const noexcept
別のベクトルと,このベクトルの距離を返す.
constexpr Vector2 ProjectedXY() const noexcept
XY平面に射影したベクトルを返す.
void Normalize() noexcept
このベクトルを正規化する. 絶対値が0のベクトルの場合,そのまま0ベクトルになる.
static constexpr Vector3 GetLeftVec() noexcept
左に進む単位ベクトルを返す. 静的な関数なので,Vector3::GetLeftVec() と呼び出せる.
bool operator<=(const Vector3 &other) const noexcept
Vector3 & operator+=(const Vector3 &other) noexcept
constexpr Vector3(Vector3 &&other) noexcept=default
ムーブコンストラクタ.
Vector3 & operator/=(const float num)
static constexpr Vector3 GetZeroVec() noexcept
零ベクトルを返す. 静的な関数なので,Vector3::GetZeroVec() と呼び出せる.
std::string ToString() const
このベクトルを文字列にして返す. (x, y, z) の形式,小数点以下3桁まで.
bool operator>(const Vector3 &other) const noexcept