UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
Utils_GG2D.hh
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2017 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Università degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
20//
21// file: Utils_GG2D.hh
22//
23#pragma once
24
25#ifndef UTILS_GG2D_dot_HH
26#define UTILS_GG2D_dot_HH
27
28#include "Utils_eigen.hh"
29
30namespace Utils {
31
36
37 /*\
38 | ____ _ _ ____ ____
39 | | _ \ ___ (_)_ __ | |_|___ \| _ \
40 | | |_) / _ \| | '_ \| __| __) | | | |
41 | | __/ (_) | | | | | |_ / __/| |_| |
42 | |_| \___/|_|_| |_|\__|_____|____/
43 \*/
44
97 template <typename Real>
98 class Point2D : public Eigen::Matrix<Real,2,1> {
99 using P2D = Eigen::Matrix<Real,2,1>;
100 public:
101 Point2D() = default;
102
103 Real x() const { return this->coeff(0); }
104 Real y() const { return this->coeff(1); }
105
106 P2D const & to_eigen() const { return *static_cast<P2D const *>(this); }
107 P2D & to_eigen() { return *static_cast<P2D*>(this); }
108 };
109
110 /*\
111 | ____ _ ____ ____
112 | / ___| ___ __ _ _ __ ___ ___ _ __ | |_|___ \| _ \
113 | \___ \ / _ \/ _` | '_ ` _ \ / _ \ '_ \| __| __) | | | |
114 | ___) | __/ (_| | | | | | | __/ | | | |_ / __/| |_| |
115 | |____/ \___|\__, |_| |_| |_|\___|_| |_|\__|_____|____/
116 | |___/
117 \*/
210
211 template <typename Real>
212 class Segment2D {
213 Point2D<Real> m_Pa;
214 Point2D<Real> m_Pb;
215 public:
216
222 Segment2D() = default;
223 //~Segment2D() = default;
224
231 : m_Pa(S.m_Pa)
232 , m_Pb(S.m_Pb)
233 {}
234
241 Segment2D( Point2D<Real> const & A, Point2D<Real> const & B )
242 : m_Pa(A)
243 , m_Pb(B)
244 {}
245
252 void
253 setup( Point2D<Real> const & A, Point2D<Real> const & B ) {
254 m_Pa = A;
255 m_Pb = B;
256 }
257
264 void
265 setup( Real const A[], Real const B[] ) {
266 m_Pa.coeffRef(0) = A[0]; m_Pa.coeffRef(1) = A[1];
267 m_Pb.coeffRef(0) = B[0]; m_Pb.coeffRef(1) = B[1];
268 }
269
270 //Real signed_distance( Point2D<Real> const & P ) const;
271
280 bool projection( Point2D<Real> const & P, Real & s ) const;
281
291 Point2D<Real> projection( Point2D<Real> const & P, Real & s, Real & t ) const;
292
300 Point2D<Real> eval( Real & s ) const;
301
310 Point2D<Real> eval( Real & s, Real & t ) const;
311
317 Point2D<Real> const & Pa() const { return m_Pa; }
318
319
325 Point2D<Real> const & Pb() const { return m_Pb; }
326
333 void bbox( Point2D<Real> & pmin, Point2D<Real> & pmax ) const;
334
344 bool intersect( Segment2D<Real> const & S, Real & s, Real & t ) const;
345
346 };
347
348 /*\
349 | ____ ____ ____
350 | | __ ) _____ _|___ \| _ \
351 | | _ \ / _ \ \/ / __) | | | |
352 | | |_) | (_) > < / __/| |_| |
353 | |____/ \___/_/\_\_____|____/
354 \*/
355
367 template <typename Real>
368 class Box2D {
369 Point2D<Real> m_Pmin;
370 Point2D<Real> m_Pmax;
371
372 public:
379 Box2D() {}
380 };
381
382 /*\
383 | _____ _ _ ____ ____
384 | |_ _| __(_) __ _ _ __ __ _| | ___|___ \| _ \
385 | | || '__| |/ _` | '_ \ / _` | |/ _ \ __) | | | |
386 | | || | | | (_| | | | | (_| | | __// __/| |_| |
387 | |_||_| |_|\__,_|_| |_|\__, |_|\___|_____|____/
388 | |___/
389 \*/
390
403 template <typename Real>
405 Point2D<Real> m_Pa;
406 Point2D<Real> m_Pb;
407 Point2D<Real> m_Pc;
408
409 public:
417 };
418
419 /*\
420 | ____ _ ____ ____
421 | | _ \ ___ | |_ _ __ _ ___ _ __ |___ \| _ \
422 | | |_) / _ \| | | | |/ _` |/ _ \| '_ \ __) | | | |
423 | | __/ (_) | | |_| | (_| | (_) | | | |/ __/| |_| |
424 | |_| \___/|_|\__, |\__, |\___/|_| |_|_____|____/
425 | |___/ |___/
426 \*/
427
440 template <typename Real>
441 class Polygon2D : public Eigen::Matrix<Real, 2, Eigen::Dynamic> {
442 public:
450 };
451
452 /*
453 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
454 */
455
456 #ifndef UTILS_OS_WINDOWS
457 extern template class Point2D<float>;
458 extern template class Point2D<double>;
459
460 extern template class Segment2D<float>;
461 extern template class Segment2D<double>;
462
463 extern template class Box2D<float>;
464 extern template class Box2D<double>;
465
466 extern template class Triangle2D<float>;
467 extern template class Triangle2D<double>;
468
469 extern template class Polygon2D<float>;
470 extern template class Polygon2D<double>;
471 #endif
472
474
475}
476
477#endif
478
479//
480// eof: Utils_GG2D.hh
481//
Box2D()
Default constructor for the bounding box.
Definition Utils_GG2D.hh:379
A class representing a 2D point in space.
Definition Utils_GG2D.hh:98
Real x() const
Definition Utils_GG2D.hh:103
Point2D()=default
P2D const & to_eigen() const
Definition Utils_GG2D.hh:106
Real y() const
Definition Utils_GG2D.hh:104
P2D & to_eigen()
Definition Utils_GG2D.hh:107
Polygon2D()
Default constructor for the polygon.
Definition Utils_GG2D.hh:449
A class representing a 2D line segment defined by two endpoints.
Definition Utils_GG2D.hh:212
Segment2D(Segment2D< Real > const &S)
Copy constructor for the segment.
Definition Utils_GG2D.hh:230
Segment2D(Point2D< Real > const &A, Point2D< Real > const &B)
Constructor to create a segment from two points.
Definition Utils_GG2D.hh:241
bool projection(Point2D< Real > const &P, Real &s) const
Projects a point onto the segment.
Definition Utils_GG2D.cc:57
void setup(Real const A[], Real const B[])
Setup the endpoints of the segment using arrays.
Definition Utils_GG2D.hh:265
Point2D< Real > const & Pa() const
Returns the first endpoint of the segment.
Definition Utils_GG2D.hh:317
bool intersect(Segment2D< Real > const &S, Real &s, Real &t) const
Checks for intersection with another segment.
Definition Utils_GG2D.cc:125
Point2D< Real > const & Pb() const
Returns the second endpoint of the segment.
Definition Utils_GG2D.hh:325
Segment2D()=default
Default constructor for the segment.
void bbox(Point2D< Real > &pmin, Point2D< Real > &pmax) const
Computes the bounding box of the segment.
Definition Utils_GG2D.cc:118
Point2D< Real > eval(Real &s) const
Evaluates the segment at a given parameter s.
Definition Utils_GG2D.cc:97
void setup(Point2D< Real > const &A, Point2D< Real > const &B)
Setup the endpoints of the segment using Point2D objects.
Definition Utils_GG2D.hh:253
Triangle2D()
Default constructor for the triangle.
Definition Utils_GG2D.hh:416
Definition SystemUtils.cc:39