KisaragiLibrary
 
読み取り中…
検索中…
一致する文字列を見つけられません
Polygon2D.hpp
[詳解]
1#pragma once
2
4#include "../Matrix2D.hpp"
5
6
7namespace Kisaragi_Lib
8{
9 template <typename T>
11 {
12 private:
15
16 //中心マトリックス3x3
18
19 //時計回りの頂点
20 vector<Vertex>vertex;
21
22
23 public:
24
25 /// <summary>
26 /// コンストラクタ
27 /// </summary>
28 /// <param name="_center">中心回転スケール座標</param>
29 /// <param name="_vertex">中心座標から見た時計回りの頂点座標(回転/スケール無し)</param>
30 Polygon2D(Matrix2D* _center, vector<Vertex> _vertex) :center(_center), vertex(_vertex)
31 {
32
33 }
34
35 vector<Edge> GetEdge()
36 {
37 vector<Edge> edge;
38
39 Matrix2D mat01 = *center;
40 Matrix2D mat02 = *center;
41
42 //最後の頂点に移動
43 mat01 *= Matrix2D::CreateMoveMatrix(vertex[vertex.size() - 1].x, vertex[vertex.size() - 1].y);
44
45 //最初の頂点
46 mat02 *= Matrix2D::CreateMoveMatrix(vertex.front().x, vertex.front().y);
47
48
49 Edge finalEdge = Edge(Point2D<T>(mat01.
50 ().x, mat01.Position().y),
52 Point2D<T>(mat02.Position().x, mat02.Position().y))));
53
54
55 //他の辺を求める
56 for (int i = 1; i < vertex.size(); i++)
57 {
58 //頂点の更新
59 mat01 = mat02;
60
61 //頂点の初期化
62 mat02 = *center;
63
64 //頂点分移動
65 mat02 *= Matrix2D::CreateMoveMatrix(vertex[i].x, vertex[i].y);
66
67 //辺を追加
68 edge.push_back(Edge(Point2D<T>(mat01.Position().x, mat01.Position().y),
70 Point2D<T>(mat02.Position().x, mat02.Position().y)))));
71 }
72
73
74 //最後の頂点と最初の頂点の辺を代入.
75 edge.push_back(finalEdge);
76
77
78 return edge;
79 }
80
81
82 };
83
84 /// <summary>
85 /// 2つの多角形の分離軸を取得する
86 /// </summary>
87 /// <returns>正規化された分離軸</returns>
88 template<typename T>
89 vector<Segment2D<T>> GetSeparationAxis(Polygon2D<T> _pol01, Polygon2D<T> _pol02)
90 {
91 //TODO ここの型を変えて重複禁止にしようず
92 //でも小数点型なんだよなぁ...
93 //しかもベクトル...
94 vector<Segment2D<T>> axis;
95
96 for (auto& edge : _pol01.GetEdge())
97 {
98 //線分のベクトルを法線ベクトルに変更
99 edge.direction = Vector2D<T>::GetNormalVector(edge.direction);
100 axis.push_back(edge);
101 }
102
103 for (auto& edge : _pol02.GetEdge())
104 {
105 //線分のベクトルを法線ベクトルに変更
106 edge.direction = Vector2D<T>::GetNormalVector(edge.direction);
107 axis.push_back(edge);
108 }
109
110 return axis;
111 }
112}
図形の形状を表すためのクラスを提供するヘッダ
Definition Matrix2D.hpp:24
Point2D< double > Position()
Definition Matrix2D.hpp:87
Matrix2D CreateMoveMatrix()
Definition Matrix2D.hpp:197
Definition Polygon2D.hpp:11
Matrix2D * center
Definition Polygon2D.hpp:17
Point2D< T > Vertex
Definition Polygon2D.hpp:13
Segment2D< T > Edge
Definition Polygon2D.hpp:14
vector< Vertex > vertex
Definition Polygon2D.hpp:20
vector< Edge > GetEdge()
Definition Polygon2D.hpp:35
Polygon2D(Matrix2D *_center, vector< Vertex > _vertex)
コンストラクタ
Definition Polygon2D.hpp:30
Definition Accessor.hpp:110
vector< Segment2D< T > > GetSeparationAxis(Polygon2D< T > _pol01, Polygon2D< T > _pol02)
2つの多角形の分離軸を取得する
Definition Polygon2D.hpp:89
点を表すプリミティブ型
Definition Primitive.hpp:29
T y
Definition Primitive.hpp:30
T x
Definition Primitive.hpp:30
始点と方向ベクトルで示される有限の直線を表すプリミティブ型
Definition Primitive.hpp:402
ベクトルを表すプリミティブ型
Definition Primitive.hpp:203
static Vector2D< T > GetNormalVector(Vector2D< T > _vec, bool _clockwise=true)
ベクトルから法線ベクトルを求める
Definition Primitive.hpp:252
static Vector2D< Type > PointToVector(const Point2D< Type > _startPoint, const Point2D< Type > _endPoint)
2点から方向ベクトル(非正規)を得る
Definition Primitive.hpp:280