UGDK
src/pyramidworks/geometry/convexpolygon.h
Go to the documentation of this file.
00001 #ifndef PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_
00002 #define PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_
00003 
00004 #include <pyramidworks/geometry/geometricshape.h>
00005 #include <vector>
00006 
00007 namespace pyramidworks {
00008 namespace geometry {
00009 
00012 class ConvexPolygon : public GeometricShape {
00013   public:
00017         ConvexPolygon(const std::vector<ugdk::Vector2D>& vertices);
00018 
00019         void set_vertices(const std::vector<ugdk::Vector2D>& vertices) { vertices_ = vertices; this->calculateSize(); }
00020 
00021     bool Intersects(const ugdk::Vector2D& this_pos, const GeometricShape *obj, const ugdk::Vector2D& that_pos) const;
00022     bool Intersects(const ugdk::Vector2D& this_pos, const           Rect *obj, const ugdk::Vector2D& that_pos) const;
00023     bool Intersects(const ugdk::Vector2D& this_pos, const         Circle *obj, const ugdk::Vector2D& that_pos) const;
00024         bool Intersects(const ugdk::Vector2D& this_pos, const  ConvexPolygon *obj, const ugdk::Vector2D& that_pos) const;
00025     ugdk::ikdtree::Box<2> GetBoundingBox(const ugdk::Vector2D& position) const;
00026 
00027         double bbox_width() { return bbox_half_width_*2; }
00028         double bbox_height() { return bbox_half_height_*2; }
00029 
00030   private:
00031     std::vector<ugdk::Vector2D> vertices_;
00032         double bbox_half_width_, bbox_half_height_;
00033 
00034         void calculateSize();
00035 
00038 
00045         bool checkAxisSeparation(const std::vector<ugdk::Vector2D>& obj1, const ugdk::Vector2D& obj1pos, 
00046                                                          const std::vector<ugdk::Vector2D>& obj2, const ugdk::Vector2D& obj2pos) const;
00047         bool axisSeparationTest(const ugdk::Vector2D& p1, const ugdk::Vector2D& p2, const ugdk::Vector2D& ref,
00048                                                         const std::vector<ugdk::Vector2D>& obj, const ugdk::Vector2D& obj2pos) const;
00049         bool insideSameSpace(const ugdk::Vector2D& line, const ugdk::Vector2D& point) const;
00050 };
00051 
00052 } // namespace geometry
00053 } // namespace pyramidworks
00054 
00055 
00056 #endif /* PYRAMIDWORKS_GEOMETRY_CONVEXPOLYGON_H_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines