Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Geometry2D.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright and trademark 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
44 #ifndef __GEOMETRY_2D_H__
45 #define __GEOMETRY_2D_H__
46 
47 #include "mengeCommon.h"
48 
49 namespace Menge {
50 
51  namespace Math {
52 
59  class MENGE_API Geometry2D {
60  public:
65 
69  virtual ~Geometry2D(){}
70 
78  virtual bool containsPoint( const Vector2 & pt ) const = 0;
79 
89  virtual bool containsPoint( const Vector2 & pt, const Vector2 & pos ) const = 0;
90  };
91 
93 
97  class MENGE_API CircleShape : public Geometry2D {
98  public:
102  CircleShape(): _center(0.f,0.f), _radSqd(1.f) {}
103 
110  CircleShape( const Vector2 & center, float radius ):Geometry2D(), _center(center), _radSqd(radius*radius) {}
111 
117  CircleShape( const CircleShape & shape );
118 
125  CircleShape( const CircleShape & shape, const Vector2 & offset );
126 
133  CircleShape operator+( const Vector2 & pt );
134 
140  void setRadius( float radius ) { _radSqd = radius * radius; }
141 
147  void setCenter( const Vector2 & center ) { _center.set( center ); }
148 
155  void set( const Vector2 & center, float radius ) { _center.set( center ); _radSqd = radius * radius; }
156 
164  virtual bool containsPoint( const Vector2 & pt ) const;
165 
174  virtual bool containsPoint( const Vector2 & pt, const Vector2 & pos ) const;
175 
176  protected:
181 
185  float _radSqd;
186  };
187 
189 
193  class MENGE_API AABBShape : public Geometry2D {
194  public:
198  AABBShape();
199 
208  AABBShape( const Vector2 & minPt, const Vector2 & maxPt );
209 
215  AABBShape( const AABBShape & shape );
216 
223  AABBShape( const AABBShape & shape, const Vector2 & offset );
224 
231  AABBShape operator+( const Vector2 & pt );
232 
240  virtual bool containsPoint( const Vector2 & pt ) const;
241 
250  virtual bool containsPoint( const Vector2 & pt, const Vector2 & pos ) const;
251 
258  void set( const Vector2 & minPt, const Vector2 & maxPt );
259 
268  void setSize( const Vector2 & size );
269 
270  protected:
275 
280 
285  };
286 
288 
292  class MENGE_API OBBShape : public Geometry2D {
293  public:
297  OBBShape();
298 
309  OBBShape( const Vector2 & pivot, const Vector2 & size, float angle );
310 
316  OBBShape( const OBBShape & shape );
317 
324  OBBShape( const OBBShape & shape, const Vector2 & offset );
325 
332  OBBShape operator+( const Vector2 & pt );
333 
341  virtual bool containsPoint( const Vector2 & pt ) const;
342 
351  virtual bool containsPoint( const Vector2 & pt, const Vector2 & pos ) const;
352 
361  void set( const Vector2 & pivot, float width, float height, float angle );
362 
370  void setSize( const Vector2 & size ) { _size.set( size ); }
371 
379  void setAngle( float angle );
380 
381  protected:
386 
391 
396 
401  float _cosTheta;
402 
407  float _sinTheta;
408  };
409  } // namespace Math
410 } // namespace Menge
411 
412 #endif // __GEOMETRY_2D_H__
Vector2 _minPt
The minimum extent of the bounding box.
Definition: Geometry2D.h:274
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
CircleShape()
Default constructor.
Definition: Geometry2D.h:102
void set(const Vector2 &center, float radius)
Sets the properties of the circle.
Definition: Geometry2D.h:155
Abstract 2d Geometry class for FSM queries.
Definition: Geometry2D.h:59
void setRadius(float radius)
Sets the radius of the circle.
Definition: Geometry2D.h:140
Vector2 _halfSize
The half width and height of the box.
Definition: Geometry2D.h:395
Vector2 _size
The width and height of the box (along its local coordinate system).
Definition: Geometry2D.h:390
Oriented bounding box.
Definition: Geometry2D.h:292
The namespace for math primitives for simulation and visualization.
Vector2 _halfSize
The size of the bounding box (along the x- and y- axes).
Definition: Geometry2D.h:284
float _cosTheta
The cosine of the box's angle of rotation (used for accelerating queries).
Definition: Geometry2D.h:401
CircleShape(const Vector2 &center, float radius)
Constructor.
Definition: Geometry2D.h:110
void setCenter(const Vector2 &center)
Sets the center of the circle.
Definition: Geometry2D.h:147
Geometry2D()
Constructor.
Definition: Geometry2D.h:64
void setSize(const Vector2 &size)
Sets the size of the OBB.
Definition: Geometry2D.h:370
float _radSqd
Squared radius of the circle.
Definition: Geometry2D.h:185
Vector2 _maxPt
The maximum extent of the bounding box.
Definition: Geometry2D.h:279
Axis-aligned bounding box.
Definition: Geometry2D.h:193
float _sinTheta
The sine of the box's angle of rotation (used for accelerating queries).
Definition: Geometry2D.h:407
virtual ~Geometry2D()
Simple destructor.
Definition: Geometry2D.h:69
Circle shape.
Definition: Geometry2D.h:97
Vector2 _center
Center of the circle.
Definition: Geometry2D.h:180
Vector2 _pivot
The minimum corners of the bounding box (the box is rotated around this point).
Definition: Geometry2D.h:385