From 0c5a09d93f3efe85b7666b0f45a43abb48def18c Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Sat, 25 Oct 2008 00:08:52 +0000 Subject: some cleaning and doc in ParametrizedLine and HyperPlane Just a thought: what about ParamLine instead of the verbose ParametrizedLine ? --- Eigen/src/Geometry/Hyperplane.h | 49 ++++++++++++++++++++++++++--------- Eigen/src/Geometry/ParametrizedLine.h | 30 ++++++++++++++------- bench/sparse_lu.cpp | 10 +++---- 3 files changed, 63 insertions(+), 26 deletions(-) diff --git a/Eigen/src/Geometry/Hyperplane.h b/Eigen/src/Geometry/Hyperplane.h index e099d10ce..d78b18a84 100644 --- a/Eigen/src/Geometry/Hyperplane.h +++ b/Eigen/src/Geometry/Hyperplane.h @@ -61,8 +61,12 @@ class Hyperplane typedef Block NormalReturnType; /** Default constructor without initialization */ - inline explicit Hyperplane(int _dim = AmbientDimAtCompileTime) : m_coeffs(_dim+1) {} - + inline explicit Hyperplane() {} + + /** Constructs a dynamic-size hyperplane with \a _dim the dimension + * of the ambient space */ + inline explicit Hyperplane(int _dim) : m_coeffs(_dim+1) {} + /** Construct a plane from its normal \a n and a point \a e onto the plane. * \warning the vector normal is assumed to be normalized. */ @@ -72,8 +76,9 @@ class Hyperplane normal() = n; offset() = -e.dot(n); } - - /** Constructs a plane from its normal \a n and distance to the origin \a d. + + /** Constructs a plane from its normal \a n and distance to the origin \a d + * such that the algebraic equation of the plane is \f$ n \cdot x + d = 0 \f$. * \warning the vector normal is assumed to be normalized. */ inline Hyperplane(const VectorType& n, Scalar d) @@ -106,31 +111,38 @@ class Hyperplane return result; } - Hyperplane(const ParametrizedLine& parametrized) + /** Constructs a hyperplane passing through the parametrized line \a parametrized. + * If the dimension of the ambient space is greater than 2, then there isn't uniqueness, + * so an arbitrary choice is made. + */ + // FIXME to be consitent with the rest this could be implemented as a static Through function ?? + explicit Hyperplane(const ParametrizedLine& parametrized) { normal() = parametrized.direction().unitOrthogonal(); offset() = -normal().dot(parametrized.origin()); } - + ~Hyperplane() {} /** \returns the dimension in which the plane holds */ inline int dim() const { return AmbientDimAtCompileTime==Dynamic ? m_coeffs.size()-1 : AmbientDimAtCompileTime; } - + /** normalizes \c *this */ void normalize(void) { m_coeffs /= normal().norm(); } - + /** \returns the signed distance between the plane \c *this and a point \a p. + * \sa absDistance() */ inline Scalar signedDistance(const VectorType& p) const { return p.dot(normal()) + offset(); } /** \returns the absolute distance between the plane \c *this and a point \a p. + * \sa signedDistance() */ inline Scalar absDistance(const VectorType& p) const { return ei_abs(signedDistance(p)); } - + /** \returns the projection of a point \a p onto the plane \c *this. */ inline VectorType projection(const VectorType& p) const { return p - signedDistance(p) * normal(); } @@ -153,7 +165,7 @@ class Hyperplane /** \returns a non-constant reference to the distance to the origin, which is also the constant part * of the implicit equation */ inline Scalar& offset() { return m_coeffs(dim()); } - + /** \returns a constant reference to the coefficients c_i of the plane equation: * \f$ c_0*x_0 + ... + c_{d-1}*x_{d-1} + c_d = 0 \f$ */ @@ -166,7 +178,7 @@ class Hyperplane /** \returns the intersection of *this with \a other. * - * \warning The ambient space must be a plane, i.e. have dimension 2, so that *this and \a other are lines. + * \warning The ambient space must be a plane, i.e. have dimension 2, so that \c *this and \a other are lines. * * \note If \a other is approximately parallel to *this, this method will return any point on *this. */ @@ -190,7 +202,13 @@ class Hyperplane invdet*(other.coeffs().coeff(0)*coeffs().coeff(2)-coeffs().coeff(0)*other.coeffs().coeff(2))); } } - + + /** \returns the transformation of \c *this by the transformation matrix \a mat. + * + * \param mat the Dim x Dim transformation matrix + * \param traits specifies whether the matrix \a mat represents an Isometry + * or a more generic Affine transformation. The default is Affine. + */ template inline Hyperplane& transform(const MatrixBase& mat, TransformTraits traits = Affine) { @@ -205,6 +223,13 @@ class Hyperplane return *this; } + /** \returns the transformation of \c *this by the transformation \a t + * + * \param t the transformation of dimension Dim + * \param traits specifies whether the transformation \a t represents an Isometry + * or a more generic Affine transformation. The default is Affine. + * Other kind of transformations are not supported. + */ inline Hyperplane& transform(const Transform& t, TransformTraits traits = Affine) { diff --git a/Eigen/src/Geometry/ParametrizedLine.h b/Eigen/src/Geometry/ParametrizedLine.h index 41dabc38b..9fcb5b36c 100644 --- a/Eigen/src/Geometry/ParametrizedLine.h +++ b/Eigen/src/Geometry/ParametrizedLine.h @@ -32,9 +32,12 @@ * * \brief A parametrized line * + * A parametrized line is defined by an origin point \f$ \mathbf{o} \f$ and a unit + * direction vector \f$ \mathbf{d} \f$ such that the line corresponds to + * the set \f$ l(t) = \mathbf{o} + t \mathbf{d} \f$, \f$ l \in \mathbf{R} \f$. + * * \param _Scalar the scalar type, i.e., the type of the coefficients * \param _AmbientDim the dimension of the ambient space, can be a compile time value or Dynamic. - * Notice that the dimension of the hyperplane is _AmbientDim-1. */ template class ParametrizedLine @@ -50,14 +53,24 @@ class ParametrizedLine typedef Matrix VectorType; /** Default constructor without initialization */ - inline explicit ParametrizedLine(int _dim = AmbientDimAtCompileTime) - : m_origin(_dim), m_direction(_dim) - {} - + inline explicit ParametrizedLine() {} + + /** Constructs a dynamic-size line with \a _dim the dimension + * of the ambient space */ + inline explicit ParametrizedLine(int _dim) : m_origin(_dim), m_direction(_dim) {} + + /** Initializes a parametrized line of direction \a direction and origin \a origin. + * \warning the vector direction is assumed to be normalized. + */ ParametrizedLine(const VectorType& origin, const VectorType& direction) : m_origin(origin), m_direction(direction) {} + explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane); + /** Constructs a parametrized line going from \a p0 to \a p1. */ + static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1) + { return ParametrizedLine(p0, (p1-p0).normalized()); } + ~ParametrizedLine() {} /** \returns the dimension in which the line holds */ @@ -82,8 +95,7 @@ class ParametrizedLine */ RealScalar distance(const VectorType& p) const { return ei_sqrt(squaredDistance(p)); } - /** \returns the projection of a point \a p onto the line \c *this. - */ + /** \returns the projection of a point \a p onto the line \c *this. */ VectorType projection(const VectorType& p) const { return origin() + (p-origin()).dot(direction()) * direction(); } @@ -94,7 +106,7 @@ class ParametrizedLine VectorType m_origin, m_direction; }; -/** Construct a parametrized line from a 2D hyperplane +/** Constructs a parametrized line from a 2D hyperplane * * \warning the ambient space must have dimension 2 such that the hyperplane actually describes a line */ @@ -106,7 +118,7 @@ inline ParametrizedLine<_Scalar, _AmbientDim>::ParametrizedLine(const Hyperplane origin() = -hyperplane.normal()*hyperplane.offset(); } -/** \returns the parameter value of the intersection between *this and the given hyperplane +/** \returns the parameter value of the intersection between \c *this and the given hyperplane */ template inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane) diff --git a/bench/sparse_lu.cpp b/bench/sparse_lu.cpp index d6020b552..bb73d481d 100644 --- a/bench/sparse_lu.cpp +++ b/bench/sparse_lu.cpp @@ -112,6 +112,11 @@ int main(int argc, char *argv[]) } #endif + #ifdef EIGEN_UMFPACK_SUPPORT + x.setZero(); + doEigen("Eigen/UmfPack (auto)", sm1, b, x, 0); + #endif + #ifdef EIGEN_SUPERLU_SUPPORT x.setZero(); doEigen("Eigen/SuperLU (nat)", sm1, b, x, Eigen::NaturalOrdering); @@ -120,11 +125,6 @@ int main(int argc, char *argv[]) doEigen("Eigen/SuperLU (COLAMD)", sm1, b, x, Eigen::ColApproxMinimumDegree); #endif - #ifdef EIGEN_UMFPACK_SUPPORT - x.setZero(); - doEigen("Eigen/UmfPack (auto)", sm1, b, x, 0); - #endif - } return 0; -- cgit v1.2.3