ParametrizedLine.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // Eigen is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 3 of the License, or (at your option) any later version.
11 //
12 // Alternatively, you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License as
14 // published by the Free Software Foundation; either version 2 of
15 // the License, or (at your option) any later version.
16 //
17 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public
23 // License and a copy of the GNU General Public License along with
24 // Eigen. If not, see <http://www.gnu.org/licenses/>.
25 
26 #ifndef EIGEN_PARAMETRIZEDLINE_H
27 #define EIGEN_PARAMETRIZEDLINE_H
28 
29 namespace Eigen {
30 
44 template <typename _Scalar, int _AmbientDim, int _Options>
46 {
47 public:
49  enum {
50  AmbientDimAtCompileTime = _AmbientDim,
51  Options = _Options
52  };
53  typedef _Scalar Scalar;
55  typedef DenseIndex Index;
57 
59  inline explicit ParametrizedLine() {}
60 
61  template<int OtherOptions>
63  : m_origin(other.origin()), m_direction(other.direction())
64  {}
65 
68  inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {}
69 
74  : m_origin(origin), m_direction(direction) {}
75 
76  template <int OtherOptions>
78 
80  static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
81  { return ParametrizedLine(p0, (p1-p0).normalized()); }
82 
84 
86  inline Index dim() const { return m_direction.size(); }
87 
88  const VectorType& origin() const { return m_origin; }
89  VectorType& origin() { return m_origin; }
90 
91  const VectorType& direction() const { return m_direction; }
93 
98  {
99  VectorType diff = p - origin();
100  return (diff - direction().dot(diff) * direction()).squaredNorm();
101  }
106 
109  { return origin() + direction().dot(p-origin()) * direction(); }
110 
111  VectorType pointAt( Scalar t ) const;
112 
113  template <int OtherOptions>
115 
116  template <int OtherOptions>
118 
119  template <int OtherOptions>
121 
127  template<typename NewScalarType>
128  inline typename internal::cast_return_type<ParametrizedLine,
130  {
131  return typename internal::cast_return_type<ParametrizedLine,
133  }
134 
136  template<typename OtherScalarType,int OtherOptions>
138  {
139  m_origin = other.origin().template cast<Scalar>();
140  m_direction = other.direction().template cast<Scalar>();
141  }
142 
148  { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
149 
150 protected:
151 
153 };
154 
159 template <typename _Scalar, int _AmbientDim, int _Options>
160 template <int OtherOptions>
162 {
164  direction() = hyperplane.normal().unitOrthogonal();
165  origin() = -hyperplane.normal()*hyperplane.offset();
166 }
167 
170 template <typename _Scalar, int _AmbientDim, int _Options>
173 {
174  return origin() + (direction()*t);
175 }
176 
179 template <typename _Scalar, int _AmbientDim, int _Options>
180 template <int OtherOptions>
182 {
183  return -(hyperplane.offset()+hyperplane.normal().dot(origin()))
184  / hyperplane.normal().dot(direction());
185 }
186 
187 
191 template <typename _Scalar, int _AmbientDim, int _Options>
192 template <int OtherOptions>
194 {
195  return intersectionParameter(hyperplane);
196 }
197 
200 template <typename _Scalar, int _AmbientDim, int _Options>
201 template <int OtherOptions>
204 {
205  return pointAt(intersectionParameter(hyperplane));
206 }
207 
208 } // end namespace Eigen
209 
210 #endif // EIGEN_PARAMETRIZEDLINE_H