ParametrizedLine.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra. Eigen itself is part of the KDE project.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <g.gael@free.fr>
00005 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
00006 //
00007 // Eigen is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU Lesser General Public
00009 // License as published by the Free Software Foundation; either
00010 // version 3 of the License, or (at your option) any later version.
00011 //
00012 // Alternatively, you can redistribute it and/or
00013 // modify it under the terms of the GNU General Public License as
00014 // published by the Free Software Foundation; either version 2 of
00015 // the License, or (at your option) any later version.
00016 //
00017 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00018 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00019 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00020 // GNU General Public License for more details.
00021 //
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License and a copy of the GNU General Public License along with
00024 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00025 
00026 // no include guard, we'll include this twice from All.h from Eigen2Support, and it's internal anyway
00027 
00028 
00042 template <typename _Scalar, int _AmbientDim>
00043 class ParametrizedLine
00044 {
00045 public:
00046   EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
00047   enum { AmbientDimAtCompileTime = _AmbientDim };
00048   typedef _Scalar Scalar;
00049   typedef typename NumTraits<Scalar>::Real RealScalar;
00050   typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
00051 
00053   inline explicit ParametrizedLine() {}
00054 
00057   inline explicit ParametrizedLine(int _dim) : m_origin(_dim), m_direction(_dim) {}
00058 
00062   ParametrizedLine(const VectorType& origin, const VectorType& direction)
00063     : m_origin(origin), m_direction(direction) {}
00064 
00065   explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane);
00066 
00068   static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
00069   { return ParametrizedLine(p0, (p1-p0).normalized()); }
00070 
00071   ~ParametrizedLine() {}
00072 
00074   inline int dim() const { return m_direction.size(); }
00075 
00076   const VectorType& origin() const { return m_origin; }
00077   VectorType& origin() { return m_origin; }
00078 
00079   const VectorType& direction() const { return m_direction; }
00080   VectorType& direction() { return m_direction; }
00081 
00085   RealScalar squaredDistance(const VectorType& p) const
00086   {
00087     VectorType diff = p-origin();
00088     return (diff - diff.eigen2_dot(direction())* direction()).squaredNorm();
00089   }
00093   RealScalar distance(const VectorType& p) const { return ei_sqrt(squaredDistance(p)); }
00094 
00096   VectorType projection(const VectorType& p) const
00097   { return origin() + (p-origin()).eigen2_dot(direction()) * direction(); }
00098 
00099   Scalar intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane);
00100 
00106   template<typename NewScalarType>
00107   inline typename internal::cast_return_type<ParametrizedLine,
00108            ParametrizedLine<NewScalarType,AmbientDimAtCompileTime> >::type cast() const
00109   {
00110     return typename internal::cast_return_type<ParametrizedLine,
00111                     ParametrizedLine<NewScalarType,AmbientDimAtCompileTime> >::type(*this);
00112   }
00113 
00115   template<typename OtherScalarType>
00116   inline explicit ParametrizedLine(const ParametrizedLine<OtherScalarType,AmbientDimAtCompileTime>& other)
00117   {
00118     m_origin = other.origin().template cast<Scalar>();
00119     m_direction = other.direction().template cast<Scalar>();
00120   }
00121 
00126   bool isApprox(const ParametrizedLine& other, typename NumTraits<Scalar>::Real prec = precision<Scalar>()) const
00127   { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
00128 
00129 protected:
00130 
00131   VectorType m_origin, m_direction;
00132 };
00133 
00138 template <typename _Scalar, int _AmbientDim>
00139 inline ParametrizedLine<_Scalar, _AmbientDim>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane)
00140 {
00141   EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
00142   direction() = hyperplane.normal().unitOrthogonal();
00143   origin() = -hyperplane.normal()*hyperplane.offset();
00144 }
00145 
00148 template <typename _Scalar, int _AmbientDim>
00149 inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane)
00150 {
00151   return -(hyperplane.offset()+origin().eigen2_dot(hyperplane.normal()))
00152           /(direction().eigen2_dot(hyperplane.normal()));
00153 }


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:32:03