PeriDyno 1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Primitive2D.h
Go to the documentation of this file.
1
17
18#pragma once
19#include "Vector.h"
20#include "Matrix.h"
21#include "Quat.h"
22
23namespace dyno
24{
29 template <typename Real> class TPoint2D;
30
35 template <typename Real> class TLine2D;
36 template <typename Real> class TRay2D;
37 template <typename Real> class TSegment2D;
38 template <typename Real> class TCircle2D;
39
44 template <typename Real> class TTriangle2D;
45 template <typename Real> class TRectangle2D;
46 template <typename Real> class TDisk2D;
47
48
49 template<typename Real>
51 {
52 public:
53 typedef typename Vector<Real, 2> Coord2D;
54
55 public:
56 DYN_FUNC TPoint2D();
57 DYN_FUNC TPoint2D(const Real& c0, const Real& c1);
58 DYN_FUNC TPoint2D(const TPoint2D& pt);
59
60 DYN_FUNC TPoint2D& operator = (const Coord2D& p);
61
62 explicit DYN_FUNC TPoint2D(const Real& val);
63 explicit DYN_FUNC TPoint2D(const Coord2D& pos);
64
65
72 DYN_FUNC TPoint2D<Real> project(const TLine2D<Real>& line) const;
73 DYN_FUNC TPoint2D<Real> project(const TRay2D<Real>& ray) const;
74 DYN_FUNC TPoint2D<Real> project(const TSegment2D<Real>& segment) const;
75 DYN_FUNC TPoint2D<Real> project(const TCircle2D<Real>& circle) const;
76
77 DYN_FUNC Real distance(const TPoint2D<Real>& pt) const;
78 DYN_FUNC Real distance(const TLine2D<Real>& line) const;
79 DYN_FUNC Real distance(const TRay2D<Real>& ray) const;
80 DYN_FUNC Real distance(const TSegment2D<Real>& segment) const;
81 DYN_FUNC Real distance(const TCircle2D<Real>& circle) const;
82
83 DYN_FUNC Real distanceSquared(const TPoint2D<Real>& pt) const;
84 DYN_FUNC Real distanceSquared(const TLine2D<Real>& line) const;
85 DYN_FUNC Real distanceSquared(const TRay2D<Real>& ray) const;
86 DYN_FUNC Real distanceSquared(const TSegment2D<Real>& segment) const;
87 DYN_FUNC Real distanceSquared(const TCircle2D<Real>& circle) const;
88
95 DYN_FUNC bool inside(const TLine2D<Real>& line) const;
96 DYN_FUNC bool inside(const TRay2D<Real>& ray) const;
97 DYN_FUNC bool inside(const TSegment2D<Real>& segment) const;
98 DYN_FUNC bool inside(const TCircle2D<Real>& circle) const;
99
100 DYN_FUNC const TSegment2D<Real> operator-(const TPoint2D<Real>& pt) const;
101
103 };
104
105 template<typename Real>
107 {
108 public:
109 typedef typename Vector<Real, 2> Coord2D;
110
111 public:
112 DYN_FUNC TLine2D();
119 DYN_FUNC TLine2D(const Coord2D& pos, const Coord2D& dir);
120 DYN_FUNC TLine2D(const TLine2D<Real>& line);
121
122 DYN_FUNC TSegment2D<Real> proximity(const TLine2D<Real>& line) const;
123 DYN_FUNC TSegment2D<Real> proximity(const TRay2D<Real>& ray) const;
124 DYN_FUNC TSegment2D<Real> proximity(const TSegment2D<Real>& segment) const;
125 DYN_FUNC TSegment2D<Real> proximity(const TCircle2D<Real>& circle) const;
126
127 DYN_FUNC Real distance(const TPoint2D<Real>& pt) const;
128 DYN_FUNC Real distance(const TLine2D<Real>& line) const;
129 DYN_FUNC Real distance(const TRay2D<Real>& ray) const;
130 DYN_FUNC Real distance(const TSegment2D<Real>& segment) const;
131
132 DYN_FUNC Real distanceSquared(const TPoint2D<Real>& pt) const;
133 DYN_FUNC Real distanceSquared(const TLine2D<Real>& line) const;
134 DYN_FUNC Real distanceSquared(const TRay2D<Real>& ray) const;
135 DYN_FUNC Real distanceSquared(const TSegment2D<Real>& segment) const;
136
137 DYN_FUNC int intersect(const TCircle2D<Real>& circle, TSegment2D<Real>& interSeg) const;
138
139 DYN_FUNC Real parameter(const Coord2D& pos) const;
140
141 DYN_FUNC bool isValid() const;
142
144
145 //direction will be normalized during construction
147 };
148
149 template<typename Real>
150 class TRay2D
151 {
152 public:
153 typedef typename Vector<Real, 2> Coord2D;
154
155 public:
156 DYN_FUNC TRay2D();
157
158 struct Param
159 {
161 };
162
170 DYN_FUNC TRay2D(const Coord2D& pos, const Coord2D& dir);
171 DYN_FUNC TRay2D(const TRay2D<Real>& ray);
172
173 DYN_FUNC TSegment2D<Real> proximity(const TRay2D<Real>& ray) const;
174 DYN_FUNC TSegment2D<Real> proximity(const TSegment2D<Real>& segment) const;
175
176 DYN_FUNC Real distance(const TPoint2D<Real>& pt) const;
177 DYN_FUNC Real distance(const TSegment2D<Real>& segment) const;
178
179 DYN_FUNC Real distanceSquared(const TPoint2D<Real>& pt) const;
180 DYN_FUNC Real distanceSquared(const TSegment2D<Real>& segment) const;
181
182 DYN_FUNC int intersect(const TCircle2D<Real>& sphere, TSegment2D<Real>& interSeg) const;
183
184 DYN_FUNC Real parameter(const Coord2D& pos) const;
185
186 DYN_FUNC bool isValid() const;
187
189
190 //guarantee direction is a unit vector
192 };
193
194 template<typename Real>
196 {
197 public:
198 typedef typename Vector<Real, 2> Coord2D;
199
200 public:
201 DYN_FUNC TSegment2D();
202 DYN_FUNC TSegment2D(const Coord2D& p0, const Coord2D& p1);
203 DYN_FUNC TSegment2D(const TSegment2D<Real>& segment);
204
205 DYN_FUNC TSegment2D<Real> proximity(const TSegment2D<Real>& segment) const;
206
207 DYN_FUNC Real distance(const TSegment2D<Real>& segment) const;
208
209 DYN_FUNC Real distanceSquared(const TSegment2D<Real>& segment) const;
210
211 DYN_FUNC Real length() const;
212 DYN_FUNC Real lengthSquared() const;
213
214 DYN_FUNC int intersect(const TCircle2D<Real>& circle, TSegment2D<Real>& interSeg) const;
215
216 DYN_FUNC Real parameter(const Coord2D& pos) const;
217
218 inline DYN_FUNC Coord2D& startPoint() { return v0; }
219 inline DYN_FUNC Coord2D& endPoint() { return v1; }
220
221 inline DYN_FUNC Coord2D startPoint() const { return v0; }
222 inline DYN_FUNC Coord2D endPoint() const { return v1; }
223
224 inline DYN_FUNC Coord2D direction() const { return v1 - v0; }
225
226 inline DYN_FUNC TSegment2D<Real> operator-(void) const;
227
228 DYN_FUNC bool isValid() const;
229
232 };
233
234 template<typename Real>
236 {
237 public:
238 typedef typename Vector<Real, 2> Coord2D;
239
240 public:
241 DYN_FUNC TCircle2D();
242 DYN_FUNC TCircle2D(const Coord2D& c, const Real& r);
243 DYN_FUNC TCircle2D(const TCircle2D<Real>& circle);
244
248 };
249
250 template<typename Real>
252 {
253 public:
254 typedef typename Vector<Real, 2> Coord2D;
255
256 public:
257 DYN_FUNC TAlignedBox2D();
258 DYN_FUNC TAlignedBox2D(const Coord2D& p0, const Coord2D& p1);
259 DYN_FUNC TAlignedBox2D(const TAlignedBox2D<Real>& box);
260
261
264 };
265
266#define MAX_POLYGON_VERTEX_NUM 8
267
268 template<typename Real>
270 {
271 public:
272 typedef typename Vector<Real, 2> Coord2D;
273
274 public:
275 TPolygon2D();
276 ~TPolygon2D();
277
278 void setAsBox(Real hx, Real hy);
279
280 void setAsPentagon(const Coord2D& v0, const Coord2D& v1, const Coord2D& v2, const Coord2D& v3, const Coord2D& v4);
281
282 void setAsTriangle(const Coord2D& v0, const Coord2D& v1, const Coord2D& v2);
283
284 void setAsLine(const Coord2D& v0, const Coord2D& v1);
285
286 const uint vertexSize() const { return size; };
287
288 inline const Coord2D& vertex(uint i) const { return _vertices[i]; }
289 inline const Coord2D& normal(uint i) const { return _normals[i]; }
290 inline const Coord2D& center() const { return _center; }
291
292 inline void setCenter(const Coord2D& c) { _center = c; }
293 inline void setVertex(const uint i, const Coord2D& v) { _vertices[i] = v; }
294
295 inline Real radius() const { return _radius; }
296
298
299 private:
303
305 Real _radius = 0.005f;
306 };
307
308 template class TAlignedBox2D<float>;
309 template class TAlignedBox2D<double>;
310}
311
312#include "Primitive2D.inl"
#define MAX_POLYGON_VERTEX_NUM
Implementation of quaternion.
double Real
Definition Typedef.inl:23
Vector< Real, 2 > Coord2D
DYN_FUNC TCircle2D()
Vector< Real, 2 > Coord2D
1D geometric primitives in two-dimensional space
DYN_FUNC bool isValid() const
DYN_FUNC Real distance(const TPoint2D< Real > &pt) const
DYN_FUNC Real distanceSquared(const TPoint2D< Real > &pt) const
Vector< Real, 2 > Coord2D
Coord2D direction
DYN_FUNC int intersect(const TCircle2D< Real > &circle, TSegment2D< Real > &interSeg) const
DYN_FUNC TLine2D()
DYN_FUNC TSegment2D< Real > proximity(const TLine2D< Real > &line) const
DYN_FUNC Real parameter(const Coord2D &pos) const
0D geometric primitive in two-dimensional space
Definition Primitive2D.h:51
DYN_FUNC TPoint2D()
DYN_FUNC TPoint2D< Real > project(const TLine2D< Real > &line) const
project a point onto linear components – lines, rays and segments
DYN_FUNC bool inside(const TLine2D< Real > &line) const
check whether a point strictly lies inside (excluding boundary) a 1D geometric primitive
DYN_FUNC Real distance(const TPoint2D< Real > &pt) const
DYN_FUNC TPoint2D & operator=(const Coord2D &p)
Vector< Real, 2 > Coord2D
Definition Primitive2D.h:53
DYN_FUNC Real distanceSquared(const TPoint2D< Real > &pt) const
DYN_FUNC const TSegment2D< Real > operator-(const TPoint2D< Real > &pt) const
Coord2D _normals[MAX_POLYGON_VERTEX_NUM]
TAlignedBox2D< Real > aabb()
const Coord2D & center() const
void setAsLine(const Coord2D &v0, const Coord2D &v1)
void setVertex(const uint i, const Coord2D &v)
Real radius() const
Vector< Real, 2 > Coord2D
void setCenter(const Coord2D &c)
const uint vertexSize() const
void setAsTriangle(const Coord2D &v0, const Coord2D &v1, const Coord2D &v2)
const Coord2D & vertex(uint i) const
const Coord2D & normal(uint i) const
void setAsPentagon(const Coord2D &v0, const Coord2D &v1, const Coord2D &v2, const Coord2D &v3, const Coord2D &v4)
void setAsBox(Real hx, Real hy)
Coord2D _vertices[MAX_POLYGON_VERTEX_NUM]
DYN_FUNC TSegment2D< Real > proximity(const TRay2D< Real > &ray) const
Coord2D origin
DYN_FUNC Real parameter(const Coord2D &pos) const
Vector< Real, 2 > Coord2D
DYN_FUNC Real distance(const TPoint2D< Real > &pt) const
DYN_FUNC bool isValid() const
DYN_FUNC TRay2D()
DYN_FUNC int intersect(const TCircle2D< Real > &sphere, TSegment2D< Real > &interSeg) const
Coord2D direction
DYN_FUNC Real distanceSquared(const TPoint2D< Real > &pt) const
DYN_FUNC Coord2D & startPoint()
DYN_FUNC Real parameter(const Coord2D &pos) const
DYN_FUNC Coord2D direction() const
DYN_FUNC Real length() const
DYN_FUNC bool isValid() const
DYN_FUNC TSegment2D< Real > proximity(const TSegment2D< Real > &segment) const
DYN_FUNC int intersect(const TCircle2D< Real > &circle, TSegment2D< Real > &interSeg) const
DYN_FUNC Coord2D startPoint() const
DYN_FUNC TSegment2D()
DYN_FUNC Coord2D & endPoint()
DYN_FUNC Real lengthSquared() const
DYN_FUNC Coord2D endPoint() const
DYN_FUNC Real distanceSquared(const TSegment2D< Real > &segment) const
DYN_FUNC TSegment2D< Real > operator-(void) const
DYN_FUNC Real distance(const TSegment2D< Real > &segment) const
Vector< Real, 2 > Coord2D
2D geometric primitives in two-dimensional space
Definition Primitive2D.h:44
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
unsigned int uint
Definition VkProgram.h:14