GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
math_line_segment2.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_LINE_SEGMENT2_H_
9#define DESIGNLAB_MATH_LINE_SEGMENT2_H_
10
11#include "math_vector2.h"
12#include "math_util.h"
13
14
15namespace designlab
16{
17
20struct LineSegment2 final
21{
22 LineSegment2() = default;
23 constexpr LineSegment2(const Vector2& start, const Vector2& end) :
24 start(start), end(end) {}
25 constexpr LineSegment2(float start_x, float start_y, float end_x, float end_y) :
26 start(start_x, start_y), end(end_x, end_y) {}
27 constexpr LineSegment2(const LineSegment2& other) = default;
28 constexpr LineSegment2(LineSegment2&& other) noexcept = default;
29 constexpr LineSegment2& operator=(const LineSegment2& other) = default;
30
31 constexpr bool operator==(const LineSegment2& other) const
32 {
33 return start == other.start && end == other.end;
34 }
35
36 constexpr bool operator!=(const LineSegment2& other) const
37 {
38 return !(*this == other);
39 }
40
41
44 inline float GetLength() const
45 {
46 return (end - start).GetLength();
47 }
48
54 constexpr bool IsParallel(const LineSegment2& other) const
55 {
56 // 外積が0なら平行.
57 return math_util::IsEqual(
58 (end - start).Cross(other.end - other.start), 0.0f);
59 }
60
67 Vector2 GetIntersection(const LineSegment2& other) const;
68
73 bool HasIntersection(const LineSegment2& other) const;
74
80 bool CheckAndGetIntersection(const LineSegment2& other,
81 Vector2* intersection) const;
82
83
86};
87
88} // namespace designlab
89
90
91#endif // DESIGNLAB_MATH_LINE_SEGMENT2_H_
constexpr bool IsEqual(const T num1, const T num2) noexcept
C++において,小数同士の計算は誤差が出てしまう. 誤差込みで値が等しいか調べる.
Definition math_util.h:45
2次元の線分を表す構造体.
Vector2 start
線分の始点.
constexpr LineSegment2(float start_x, float start_y, float end_x, float end_y)
Vector2 GetIntersection(const LineSegment2 &other) const
他の線分との交点を求める.
bool CheckAndGetIntersection(const LineSegment2 &other, Vector2 *intersection) const
他の線分と交点が存在しているかどうか調べ,交点を返す関数.
constexpr LineSegment2(const Vector2 &start, const Vector2 &end)
constexpr LineSegment2(const LineSegment2 &other)=default
constexpr LineSegment2(LineSegment2 &&other) noexcept=default
constexpr LineSegment2 & operator=(const LineSegment2 &other)=default
constexpr bool IsParallel(const LineSegment2 &other) const
引数の線分と自身が平行かどうか調べる関数. 全て constexpr 関数で処理できるため非常に高速.
Vector2 end
線分の終点.
bool HasIntersection(const LineSegment2 &other) const
他の線分と交点が存在しているかどうか調べる関数.
constexpr bool operator==(const LineSegment2 &other) const
constexpr bool operator!=(const LineSegment2 &other) const
float GetLength() const
線分の長さを求める関数.
2次元の位置ベクトルを表す構造体.