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.
00003 //
00004 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.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 #ifndef EIGEN_PARAMETRIZEDLINE_H
00027 #define EIGEN_PARAMETRIZEDLINE_H
00028 
00042 template <typename _Scalar, int _AmbientDim, int _Options>
00043 class ParametrizedLine
00044 {
00045 public:
00046   EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
00047   enum {
00048     AmbientDimAtCompileTime = _AmbientDim,
00049     Options = _Options
00050   };
00051   typedef _Scalar Scalar;
00052   typedef typename NumTraits<Scalar>::Real RealScalar;
00053   typedef DenseIndex Index;
00054   typedef Matrix<Scalar,AmbientDimAtCompileTime,1,Options> VectorType;
00055 
00057   inline explicit ParametrizedLine() {}
00058   
00059   template<int OtherOptions>
00060   ParametrizedLine(const ParametrizedLine<Scalar,AmbientDimAtCompileTime,OtherOptions>& other)
00061    : m_origin(other.origin()), m_direction(other.direction())
00062   {}
00063 
00066   inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {}
00067 
00071   ParametrizedLine(const VectorType& origin, const VectorType& direction)
00072     : m_origin(origin), m_direction(direction) {}
00073 
00074   template <int OtherOptions>
00075   explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane);
00076 
00078   static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
00079   { return ParametrizedLine(p0, (p1-p0).normalized()); }
00080 
00081   ~ParametrizedLine() {}
00082 
00084   inline Index dim() const { return m_direction.size(); }
00085 
00086   const VectorType& origin() const { return m_origin; }
00087   VectorType& origin() { return m_origin; }
00088 
00089   const VectorType& direction() const { return m_direction; }
00090   VectorType& direction() { return m_direction; }
00091 
00095   RealScalar squaredDistance(const VectorType& p) const
00096   {
00097     VectorType diff = p - origin();
00098     return (diff - direction().dot(diff) * direction()).squaredNorm();
00099   }
00103   RealScalar distance(const VectorType& p) const { return internal::sqrt(squaredDistance(p)); }
00104 
00106   VectorType projection(const VectorType& p) const
00107   { return origin() + direction().dot(p-origin()) * direction(); }
00108 
00109   template <int OtherOptions>
00110   Scalar intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
00111 
00117   template<typename NewScalarType>
00118   inline typename internal::cast_return_type<ParametrizedLine,
00119            ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type cast() const
00120   {
00121     return typename internal::cast_return_type<ParametrizedLine,
00122                     ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this);
00123   }
00124 
00126   template<typename OtherScalarType,int OtherOptions>
00127   inline explicit ParametrizedLine(const ParametrizedLine<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other)
00128   {
00129     m_origin = other.origin().template cast<Scalar>();
00130     m_direction = other.direction().template cast<Scalar>();
00131   }
00132 
00137   bool isApprox(const ParametrizedLine& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00138   { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
00139 
00140 protected:
00141 
00142   VectorType m_origin, m_direction;
00143 };
00144 
00149 template <typename _Scalar, int _AmbientDim, int _Options>
00150 template <int OtherOptions>
00151 inline ParametrizedLine<_Scalar, _AmbientDim,_Options>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim,OtherOptions>& hyperplane)
00152 {
00153   EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
00154   direction() = hyperplane.normal().unitOrthogonal();
00155   origin() = -hyperplane.normal()*hyperplane.offset();
00156 }
00157 
00160 template <typename _Scalar, int _AmbientDim, int _Options>
00161 template <int OtherOptions>
00162 inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const
00163 {
00164   return -(hyperplane.offset()+hyperplane.normal().dot(origin()))
00165           / hyperplane.normal().dot(direction());
00166 }
00167 
00168 #endif // EIGEN_PARAMETRIZEDLINE_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:33:08