Go to the documentation of this file.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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
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 DenseIndex Index;
00051 typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
00052
00053
00054 inline explicit ParametrizedLine() {}
00055
00056
00057
00058 inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {}
00059
00060
00061
00062
00063 ParametrizedLine(const VectorType& origin, const VectorType& direction)
00064 : m_origin(origin), m_direction(direction) {}
00065
00066 explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane);
00067
00068
00069 static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
00070 { return ParametrizedLine(p0, (p1-p0).normalized()); }
00071
00072 ~ParametrizedLine() {}
00073
00074
00075 inline Index dim() const { return m_direction.size(); }
00076
00077 const VectorType& origin() const { return m_origin; }
00078 VectorType& origin() { return m_origin; }
00079
00080 const VectorType& direction() const { return m_direction; }
00081 VectorType& direction() { return m_direction; }
00082
00083
00084
00085
00086 RealScalar squaredDistance(const VectorType& p) const
00087 {
00088 VectorType diff = p - origin();
00089 return (diff - direction().dot(diff) * direction()).squaredNorm();
00090 }
00091
00092
00093
00094 RealScalar distance(const VectorType& p) const { return internal::sqrt(squaredDistance(p)); }
00095
00096
00097 VectorType projection(const VectorType& p) const
00098 { return origin() + direction().dot(p-origin()) * direction(); }
00099
00100 Scalar intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane);
00101
00102
00103
00104
00105
00106
00107 template<typename NewScalarType>
00108 inline typename internal::cast_return_type<ParametrizedLine,
00109 ParametrizedLine<NewScalarType,AmbientDimAtCompileTime> >::type cast() const
00110 {
00111 return typename internal::cast_return_type<ParametrizedLine,
00112 ParametrizedLine<NewScalarType,AmbientDimAtCompileTime> >::type(*this);
00113 }
00114
00115
00116 template<typename OtherScalarType>
00117 inline explicit ParametrizedLine(const ParametrizedLine<OtherScalarType,AmbientDimAtCompileTime>& other)
00118 {
00119 m_origin = other.origin().template cast<Scalar>();
00120 m_direction = other.direction().template cast<Scalar>();
00121 }
00122
00123
00124
00125
00126
00127 bool isApprox(const ParametrizedLine& other, typename NumTraits<Scalar>::Real prec = NumTraits<Scalar>::dummy_precision()) const
00128 { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
00129
00130 protected:
00131
00132 VectorType m_origin, m_direction;
00133 };
00134
00135
00136
00137
00138
00139 template <typename _Scalar, int _AmbientDim>
00140 inline ParametrizedLine<_Scalar, _AmbientDim>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane)
00141 {
00142 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
00143 direction() = hyperplane.normal().unitOrthogonal();
00144 origin() = -hyperplane.normal()*hyperplane.offset();
00145 }
00146
00147
00148
00149 template <typename _Scalar, int _AmbientDim>
00150 inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane)
00151 {
00152 return -(hyperplane.offset()+hyperplane.normal().dot(origin()))
00153 / hyperplane.normal().dot(direction());
00154 }
00155
00156 #endif // EIGEN_PARAMETRIZEDLINE_H