00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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);
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)
00163 {
00164 return -(hyperplane.offset()+hyperplane.normal().dot(origin()))
00165 / hyperplane.normal().dot(direction());
00166 }
00167
00168 #endif // EIGEN_PARAMETRIZEDLINE_H