libalmath  2.5.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shapes3d.h
Go to the documentation of this file.
1 
7 #ifndef LIB_ALMATH_GEOMETRICS_SHAPES_H
8 #define LIB_ALMATH_GEOMETRICS_SHAPES_H
9 
10 #include <string>
11 #include <stdexcept>
12 
13 namespace AL {
14 namespace Math {
15 
16 class Shape3DVisitor;
17 
18 class Shape3D {
19  public:
20  virtual ~Shape3D() {}
21  virtual void accept(const Shape3DVisitor &v) const = 0;
22 };
23 
24 // Defined by its radius. Centered at (0, 0, 0).
25 class Sphere : public Shape3D {
26  public:
27  Sphere(float pRadius);
28  virtual void accept(const Shape3DVisitor &v) const;
29  float getRadius() const;
30 
31  private:
32  float fRadius;
33 };
34 
35 // Minkowsky sum of a 2D rectangle with a 3D sphere.
36 // Centered. The normal to the plane is : (0, 0, 1).
37 // a.k.a Tab before (like a tactile tablet).
38 class RoundedRectangle : public Shape3D {
39  public:
40  RoundedRectangle(float pHalfExtentX, float pHalfExtentY, float pRadius);
41  virtual void accept(const Shape3DVisitor &v) const;
42  float getHalfExtentX() const;
43  float getHalfExtentY() const;
44  float getRadius() const;
45 
46  private:
47  float fHalfExtentX;
48  float fHalfExtentY;
49  float fRadius;
50 };
51 
52 // 3D convex hull of two spheres, oriented along z axis.
53 // The centers of the spheres have the coordinates in pill frame :
54 // upSphere(0, 0, fHalfExtent), downSpere(0, 0, -fhalfExtent).
55 class Pill : public Shape3D {
56  public:
57  Pill(float pHalfExtent, float pRadius);
58  virtual void accept(const Shape3DVisitor &v) const;
59  float getHalfExtent() const;
60  float getRadius() const;
61 
62  private:
63  float fHalfExtent;
64  float fRadius;
65 };
66 
67 // Equation z = 0, normal (0, 0, 1).
68 class Plane : public Shape3D {
69  public:
70  virtual void accept(const Shape3DVisitor &v) const;
71 };
72 
73 // Equation z <= 0, normal (0, 0, 1). (z > 0 is free space).
74 class HalfSpace : public Shape3D {
75  public:
76  virtual void accept(const Shape3DVisitor &v) const;
77 };
78 
79 // Equation z = 0, abs(x) < fHalfExtentX, abs(y) < fHalfExtentY,
80 class Rectangle : public Shape3D {
81  public:
82  Rectangle(float pHalfExtentX, float pHalfExtentY);
83  virtual void accept(const Shape3DVisitor &v) const;
84  float getHalfExtentX() const;
85  float getHalfExtentY() const;
86 
87  private:
88  float fHalfExtentX;
89  float fHalfExtentY;
90 };
91 
92 // Half line oriented along z axis, equation z >= 0, x = 0, y = 0.
93 class HalfLine : public Shape3D {
94  public:
95  virtual void accept(const Shape3DVisitor &v) const;
96 };
97 
99  public:
100  virtual void visit(const Pill &pShape) const = 0;
101  virtual void visit(const Sphere &pShape) const = 0;
102  virtual void visit(const RoundedRectangle &pShape) const = 0;
103  virtual void visit(const Plane &pShape) const = 0;
104  virtual void visit(const HalfSpace &pShape) const = 0;
105  virtual void visit(const Rectangle &pShape) const = 0;
106  virtual void visit(const HalfLine &pShape) const = 0;
107  virtual ~Shape3DVisitor() {}
108 };
109 
111  public:
112  NotImplementedShape3DVisitor(const std::string msg = "not implemented")
113  : fMsg(msg) {}
114  virtual void visit(const Pill &pShape) const {
115  throw std::runtime_error(fMsg);
116  }
117  virtual void visit(const Sphere &pShape) const {
118  throw std::runtime_error(fMsg);
119  }
120  virtual void visit(const RoundedRectangle &pShape) const {
121  throw std::runtime_error(fMsg);
122  }
123  virtual void visit(const Plane &pShape) const {
124  throw std::runtime_error(fMsg);
125  }
126  virtual void visit(const HalfSpace &pShape) const {
127  throw std::runtime_error(fMsg);
128  }
129  virtual void visit(const Rectangle &pShape) const {
130  throw std::runtime_error(fMsg);
131  }
132  virtual void visit(const HalfLine &pShape) const {
133  throw std::runtime_error(fMsg);
134  }
136 
137  private:
138  std::string fMsg;
139 };
140 
141 } // End namespace Math.
142 } // End namespace AL.
143 
144 #endif // LIB_ALMATH_GEOMETRICS_SHAPE_H
float getRadius() const
virtual void accept(const Shape3DVisitor &v) const
virtual void accept(const Shape3DVisitor &v) const =0
virtual void visit(const Pill &pShape) const =0
virtual void accept(const Shape3DVisitor &v) const
float getHalfExtentX() const
RoundedRectangle(float pHalfExtentX, float pHalfExtentY, float pRadius)
float getHalfExtentX() const
virtual void visit(const Sphere &pShape) const
Definition: shapes3d.h:117
Pill(float pHalfExtent, float pRadius)
NotImplementedShape3DVisitor(const std::string msg="not implemented")
Definition: shapes3d.h:112
virtual void visit(const RoundedRectangle &pShape) const
Definition: shapes3d.h:120
Sphere(float pRadius)
float getHalfExtentY() const
virtual void visit(const Rectangle &pShape) const
Definition: shapes3d.h:129
virtual void accept(const Shape3DVisitor &v) const
float getHalfExtentY() const
virtual void visit(const Plane &pShape) const
Definition: shapes3d.h:123
virtual ~Shape3D()
Definition: shapes3d.h:20
float getRadius() const
virtual void visit(const Pill &pShape) const
Definition: shapes3d.h:114
virtual void visit(const HalfLine &pShape) const
Definition: shapes3d.h:132
virtual void visit(const HalfSpace &pShape) const
Definition: shapes3d.h:126
virtual void accept(const Shape3DVisitor &v) const
virtual void accept(const Shape3DVisitor &v) const
virtual void accept(const Shape3DVisitor &v) const
Rectangle(float pHalfExtentX, float pHalfExtentY)
float getHalfExtent() const
virtual ~Shape3DVisitor()
Definition: shapes3d.h:107
virtual void accept(const Shape3DVisitor &v) const