some cleaning and doc in ParametrizedLine and HyperPlane

Just a thought: what about ParamLine instead of the verbose ParametrizedLine ?
This commit is contained in:
Gael Guennebaud 2008-10-25 00:08:52 +00:00
parent 8ea8b481de
commit 0c5a09d93f
3 changed files with 63 additions and 26 deletions

View File

@ -61,7 +61,11 @@ class Hyperplane
typedef Block<Coefficients,AmbientDimAtCompileTime,1> NormalReturnType; typedef Block<Coefficients,AmbientDimAtCompileTime,1> NormalReturnType;
/** Default constructor without initialization */ /** 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. /** 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. * \warning the vector normal is assumed to be normalized.
@ -73,7 +77,8 @@ class Hyperplane
offset() = -e.dot(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. * \warning the vector normal is assumed to be normalized.
*/ */
inline Hyperplane(const VectorType& n, Scalar d) inline Hyperplane(const VectorType& n, Scalar d)
@ -106,7 +111,12 @@ class Hyperplane
return result; return result;
} }
Hyperplane(const ParametrizedLine<Scalar, AmbientDimAtCompileTime>& 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<Scalar, AmbientDimAtCompileTime>& parametrized)
{ {
normal() = parametrized.direction().unitOrthogonal(); normal() = parametrized.direction().unitOrthogonal();
offset() = -normal().dot(parametrized.origin()); offset() = -normal().dot(parametrized.origin());
@ -124,10 +134,12 @@ class Hyperplane
} }
/** \returns the signed distance between the plane \c *this and a point \a p. /** \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(); } 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. /** \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)); } inline Scalar absDistance(const VectorType& p) const { return ei_abs(signedDistance(p)); }
@ -166,7 +178,7 @@ class Hyperplane
/** \returns the intersection of *this with \a other. /** \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. * \note If \a other is approximately parallel to *this, this method will return any point on *this.
*/ */
@ -191,6 +203,12 @@ class Hyperplane
} }
} }
/** \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<typename XprType> template<typename XprType>
inline Hyperplane& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine) inline Hyperplane& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine)
{ {
@ -205,6 +223,13 @@ class Hyperplane
return *this; 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<Scalar,AmbientDimAtCompileTime>& t, inline Hyperplane& transform(const Transform<Scalar,AmbientDimAtCompileTime>& t,
TransformTraits traits = Affine) TransformTraits traits = Affine)
{ {

View File

@ -32,9 +32,12 @@
* *
* \brief A parametrized line * \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 _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. * \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 <typename _Scalar, int _AmbientDim> template <typename _Scalar, int _AmbientDim>
class ParametrizedLine class ParametrizedLine
@ -50,14 +53,24 @@ class ParametrizedLine
typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType; typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
/** Default constructor without initialization */ /** Default constructor without initialization */
inline explicit ParametrizedLine(int _dim = AmbientDimAtCompileTime) inline explicit ParametrizedLine() {}
: m_origin(_dim), m_direction(_dim)
{}
/** 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) ParametrizedLine(const VectorType& origin, const VectorType& direction)
: m_origin(origin), m_direction(direction) {} : m_origin(origin), m_direction(direction) {}
explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim>& hyperplane); 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() {} ~ParametrizedLine() {}
/** \returns the dimension in which the line holds */ /** \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)); } 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 VectorType projection(const VectorType& p) const
{ return origin() + (p-origin()).dot(direction()) * direction(); } { return origin() + (p-origin()).dot(direction()) * direction(); }
@ -94,7 +106,7 @@ class ParametrizedLine
VectorType m_origin, m_direction; 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 * \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(); 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 <typename _Scalar, int _AmbientDim> template <typename _Scalar, int _AmbientDim>
inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane) inline _Scalar ParametrizedLine<_Scalar, _AmbientDim>::intersection(const Hyperplane<_Scalar, _AmbientDim>& hyperplane)

View File

@ -112,6 +112,11 @@ int main(int argc, char *argv[])
} }
#endif #endif
#ifdef EIGEN_UMFPACK_SUPPORT
x.setZero();
doEigen<Eigen::UmfPack>("Eigen/UmfPack (auto)", sm1, b, x, 0);
#endif
#ifdef EIGEN_SUPERLU_SUPPORT #ifdef EIGEN_SUPERLU_SUPPORT
x.setZero(); x.setZero();
doEigen<Eigen::SuperLU>("Eigen/SuperLU (nat)", sm1, b, x, Eigen::NaturalOrdering); doEigen<Eigen::SuperLU>("Eigen/SuperLU (nat)", sm1, b, x, Eigen::NaturalOrdering);
@ -120,11 +125,6 @@ int main(int argc, char *argv[])
doEigen<Eigen::SuperLU>("Eigen/SuperLU (COLAMD)", sm1, b, x, Eigen::ColApproxMinimumDegree); doEigen<Eigen::SuperLU>("Eigen/SuperLU (COLAMD)", sm1, b, x, Eigen::ColApproxMinimumDegree);
#endif #endif
#ifdef EIGEN_UMFPACK_SUPPORT
x.setZero();
doEigen<Eigen::UmfPack>("Eigen/UmfPack (auto)", sm1, b, x, 0);
#endif
} }
return 0; return 0;