All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Plane.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _IGNITION_PLANE_HH_
19 #define _IGNITION_PLANE_HH_
20 
21 #include <ignition/math/Vector3.hh>
22 #include <ignition/math/Vector2.hh>
23 
24 namespace ignition
25 {
26  namespace math
27  {
30  template<typename T>
31  class Plane
32  {
34  public: Plane()
35  {
36  this->d = 0.0;
37  }
38 
42  public: Plane(const Vector3<T> &_normal, T _offset = 0.0)
43  {
44  this->normal = _normal;
45  this->d = _offset;
46  }
47 
52  public: Plane(const Vector3<T> &_normal, const Vector2<T> &_size,
53  T _offset)
54  {
55  this->Set(_normal, _size, _offset);
56  }
57 
59  public: virtual ~Plane() {}
60 
65  public: void Set(const Vector3<T> &_normal, const Vector2<T> &_size,
66  T _offset)
67  {
68  this->normal = _normal;
69  this->size = _size;
70  this->d = _offset;
71  }
72 
77  public: T Distance(const Vector3<T> &_origin,
78  const Vector3<T> &_dir) const
79  {
80  T denom = this->normal.Dot(_dir);
81 
82  if (std::abs(denom) < 1e-3)
83  {
84  // parallel
85  return 0;
86  }
87  else
88  {
89  T nom = _origin.Dot(this->normal) - this->d;
90  T t = -(nom/denom);
91  return t;
92  }
93  }
94 
96  public: inline const Vector2<T> &Size() const
97  {
98  return this->size;
99  }
100 
102  public: inline Vector2<T> &Size()
103  {
104  return this->size;
105  }
106 
108  public: inline const Vector3<T> &Normal() const
109  {
110  return this->normal;
111  }
112 
114  public: inline Vector3<T> &Normal()
115  {
116  return this->normal;
117  }
118 
120  public: inline T Offset() const
121  {
122  return this->d;
123  }
124 
128  public: Plane<T> &operator=(const Plane<T> &_p)
129  {
130  this->normal = _p.normal;
131  this->size = _p.size;
132  this->d = _p.d;
133 
134  return *this;
135  }
136 
138  private: Vector3<T> normal;
139 
141  private: Vector2<T> size;
142 
144  private: T d;
145  };
146 
150  }
151 }
152 
153 #endif
Plane(const Vector3< T > &_normal, T _offset=0.0)
Constructor from a normal and a distanec.
Definition: Plane.hh:42
Plane< float > Planef
Definition: Plane.hh:149
Two dimensional (x, y) vector.
Definition: Vector2.hh:29
A plane and related functions.
Definition: Plane.hh:31
Plane< double > Planed
Definition: Plane.hh:148
Plane()
Constructor.
Definition: Plane.hh:34
const Vector2< T > & Size() const
Get the plane size.
Definition: Plane.hh:96
T Distance(const Vector3< T > &_origin, const Vector3< T > &_dir) const
Get distance to the plane give an origin and direction.
Definition: Plane.hh:77
T Dot(const Vector3< T > &_v) const
Return the dot product of this vector and another vector.
Definition: Vector3.hh:191
T Offset() const
Get the plane offset.
Definition: Plane.hh:120
const Vector3< T > & Normal() const
Get the plane offset.
Definition: Plane.hh:108
Vector2< T > & Size()
Get the plane size.
Definition: Plane.hh:102
Plane(const Vector3< T > &_normal, const Vector2< T > &_size, T _offset)
Constructor.
Definition: Plane.hh:52
Vector3< T > & Normal()
Get the plane offset.
Definition: Plane.hh:114
virtual ~Plane()
Destructor.
Definition: Plane.hh:59
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:37
Plane< T > & operator=(const Plane< T > &_p)
Equal operator.
Definition: Plane.hh:128
Plane< int > Planei
Definition: Plane.hh:147
void Set(const Vector3< T > &_normal, const Vector2< T > &_size, T _offset)
Set the plane.
Definition: Plane.hh:65