Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ > Class Template Reference

A hyperplane. More...

Public Types

enum  {
  AmbientDimAtCompileTime ,
  Options
}
 
typedef Matrix< Scalar, Index(AmbientDimAtCompileTime)==Dynamic ? Dynamic :Index(AmbientDimAtCompileTime)+1, 1, OptionsCoefficients
 
typedef const Block< const Coefficients, AmbientDimAtCompileTime, 1 > ConstNormalReturnType
 
typedef Eigen::Index Index
 
typedef Block< Coefficients, AmbientDimAtCompileTime, 1 > NormalReturnType
 
typedef NumTraits< Scalar >::Real RealScalar
 
typedef Scalar_ Scalar
 
typedef Matrix< Scalar, AmbientDimAtCompileTime, 1 > VectorType
 

Public Member Functions

Scalar absDistance (const VectorType &p) const
 
template<typename NewScalarType >
internal::cast_return_type< Hyperplane, Hyperplane< NewScalarType, AmbientDimAtCompileTime, Options > >::type cast () const
 
Coefficientscoeffs ()
 
const Coefficientscoeffs () const
 
Index dim () const
 
 Hyperplane ()
 
template<typename OtherScalarType , int OtherOptions>
 Hyperplane (const Hyperplane< OtherScalarType, AmbientDimAtCompileTime, OtherOptions > &other)
 
template<int OtherOptions>
 Hyperplane (const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &other)
 
 Hyperplane (const ParametrizedLine< Scalar, AmbientDimAtCompileTime > &parametrized)
 
 Hyperplane (const VectorType &n, const Scalar &d)
 
 Hyperplane (const VectorType &n, const VectorType &e)
 
 Hyperplane (Index _dim)
 
VectorType intersection (const Hyperplane &other) const
 
template<int OtherOptions>
bool isApprox (const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
 
NormalReturnType normal ()
 
ConstNormalReturnType normal () const
 
void normalize (void)
 
Scalaroffset ()
 
const Scalaroffset () const
 
VectorType projection (const VectorType &p) const
 
Scalar signedDistance (const VectorType &p) const
 
template<typename XprType >
Hyperplanetransform (const MatrixBase< XprType > &mat, TransformTraits traits=Affine)
 
template<int TrOptions>
Hyperplanetransform (const Transform< Scalar, AmbientDimAtCompileTime, Affine, TrOptions > &t, TransformTraits traits=Affine)
 
 ~Hyperplane ()
 

Static Public Member Functions

static Hyperplane Through (const VectorType &p0, const VectorType &p1)
 
static Hyperplane Through (const VectorType &p0, const VectorType &p1, const VectorType &p2)
 

Protected Attributes

Coefficients m_coeffs
 

Detailed Description

template<typename Scalar_, int AmbientDim_, int Options_>
class Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >

A hyperplane.

This is defined in the Geometry module.

A hyperplane is an affine subspace of dimension n-1 in a space of dimension n. For example, a hyperplane in a plane is a line; a hyperplane in 3-space is a plane.

Template Parameters
Scalar_the scalar type, i.e., the type of the coefficients
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.

This class represents an hyperplane as the zero set of the implicit equation \( n \cdot x + d = 0 \) where \( n \) is a unit normal vector of the plane (linear part) and \( d \) is the distance (offset) to the origin.

Definition at line 36 of file Hyperplane.h.

Member Typedef Documentation

◆ Coefficients

template<typename Scalar_ , int AmbientDim_, int Options_>
typedef Matrix<Scalar,Index(AmbientDimAtCompileTime)==Dynamic ? Dynamic : Index(AmbientDimAtCompileTime)+1,1,Options> Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Coefficients

Definition at line 50 of file Hyperplane.h.

◆ ConstNormalReturnType

template<typename Scalar_ , int AmbientDim_, int Options_>
typedef const Block<const Coefficients,AmbientDimAtCompileTime,1> Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::ConstNormalReturnType

Definition at line 52 of file Hyperplane.h.

◆ Index

template<typename Scalar_ , int AmbientDim_, int Options_>
typedef Eigen::Index Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Index
Deprecated:
since Eigen 3.3

Definition at line 46 of file Hyperplane.h.

◆ NormalReturnType

template<typename Scalar_ , int AmbientDim_, int Options_>
typedef Block<Coefficients,AmbientDimAtCompileTime,1> Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::NormalReturnType

Definition at line 51 of file Hyperplane.h.

◆ RealScalar

template<typename Scalar_ , int AmbientDim_, int Options_>
typedef NumTraits<Scalar>::Real Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::RealScalar

Definition at line 45 of file Hyperplane.h.

◆ Scalar

template<typename Scalar_ , int AmbientDim_, int Options_>
typedef Scalar_ Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Scalar

Definition at line 44 of file Hyperplane.h.

◆ VectorType

template<typename Scalar_ , int AmbientDim_, int Options_>
typedef Matrix<Scalar,AmbientDimAtCompileTime,1> Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::VectorType

Definition at line 47 of file Hyperplane.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename Scalar_ , int AmbientDim_, int Options_>
anonymous enum
Enumerator
AmbientDimAtCompileTime 
Options 

Definition at line 40 of file Hyperplane.h.

40  {
41  AmbientDimAtCompileTime = AmbientDim_,
42  Options = Options_
43  };

Constructor & Destructor Documentation

◆ Hyperplane() [1/7]

template<typename Scalar_ , int AmbientDim_, int Options_>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Hyperplane ( )
inline

Default constructor without initialization

Definition at line 55 of file Hyperplane.h.

55 {}

◆ Hyperplane() [2/7]

template<typename Scalar_ , int AmbientDim_, int Options_>
template<int OtherOptions>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Hyperplane ( const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &  other)
inline

Definition at line 58 of file Hyperplane.h.

59  : m_coeffs(other.coeffs())
60  {}
Coefficients m_coeffs
Definition: Hyperplane.h:279

◆ Hyperplane() [3/7]

template<typename Scalar_ , int AmbientDim_, int Options_>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Hyperplane ( Index  _dim)
inlineexplicit

Constructs a dynamic-size hyperplane with _dim the dimension of the ambient space

Definition at line 64 of file Hyperplane.h.

64 : m_coeffs(_dim+1) {}

◆ Hyperplane() [4/7]

template<typename Scalar_ , int AmbientDim_, int Options_>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Hyperplane ( const VectorType n,
const VectorType e 
)
inline

Construct a plane from its normal n and a point e onto the plane.

Warning
the vector normal is assumed to be normalized.

Definition at line 69 of file Hyperplane.h.

70  : m_coeffs(n.size()+1)
71  {
72  normal() = n;
73  offset() = -n.dot(e);
74  }
int n
Array< double, 1, 3 > e(1./3., 0.5, 2.)
ConstNormalReturnType normal() const
Definition: Hyperplane.h:159
const Scalar & offset() const
Definition: Hyperplane.h:169

◆ Hyperplane() [5/7]

template<typename Scalar_ , int AmbientDim_, int Options_>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Hyperplane ( const VectorType n,
const Scalar d 
)
inline

Constructs a plane from its normal n and distance to the origin d such that the algebraic equation of the plane is \( n \cdot x + d = 0 \).

Warning
the vector normal is assumed to be normalized.

Definition at line 80 of file Hyperplane.h.

81  : m_coeffs(n.size()+1)
82  {
83  normal() = n;
84  offset() = d;
85  }

◆ Hyperplane() [6/7]

template<typename Scalar_ , int AmbientDim_, int Options_>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Hyperplane ( const ParametrizedLine< Scalar, AmbientDimAtCompileTime > &  parametrized)
inlineexplicit

Constructs a hyperplane passing through the parametrized line parametrized. If the dimension of the ambient space is greater than 2, then there isn't uniqueness, so an arbitrary choice is made.

Definition at line 125 of file Hyperplane.h.

126  {
127  normal() = parametrized.direction().unitOrthogonal();
128  offset() = -parametrized.origin().dot(normal());
129  }

◆ ~Hyperplane()

template<typename Scalar_ , int AmbientDim_, int Options_>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::~Hyperplane ( )
inline

Definition at line 131 of file Hyperplane.h.

131 {}

◆ Hyperplane() [7/7]

template<typename Scalar_ , int AmbientDim_, int Options_>
template<typename OtherScalarType , int OtherOptions>
Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Hyperplane ( const Hyperplane< OtherScalarType, AmbientDimAtCompileTime, OtherOptions > &  other)
inlineexplicit

Copy constructor with scalar type conversion

Definition at line 266 of file Hyperplane.h.

267  { m_coeffs = other.coeffs().template cast<Scalar>(); }

Member Function Documentation

◆ absDistance()

template<typename Scalar_ , int AmbientDim_, int Options_>
Scalar Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::absDistance ( const VectorType p) const
inline
Returns
the absolute distance between the plane *this and a point p.
See also
signedDistance()

Definition at line 150 of file Hyperplane.h.

150 { return numext::abs(signedDistance(p)); }
float * p
Scalar signedDistance(const VectorType &p) const
Definition: Hyperplane.h:145
EIGEN_ALWAYS_INLINE std::enable_if_t< NumTraits< T >::IsSigned||NumTraits< T >::IsComplex, typename NumTraits< T >::Real > abs(const T &x)

◆ cast()

template<typename Scalar_ , int AmbientDim_, int Options_>
template<typename NewScalarType >
internal::cast_return_type<Hyperplane, Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::cast ( ) const
inline
Returns
*this with scalar type casted to NewScalarType

Note that if NewScalarType is equal to the current scalar type of *this then this function smartly returns a const reference to *this.

Definition at line 258 of file Hyperplane.h.

259  {
260  return typename internal::cast_return_type<Hyperplane,
261  Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this);
262  }

◆ coeffs() [1/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
Coefficients& Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::coeffs ( )
inline
Returns
a non-constant reference to the coefficients c_i of the plane equation: \( c_0*x_0 + ... + c_{d-1}*x_{d-1} + c_d = 0 \)

Definition at line 183 of file Hyperplane.h.

183 { return m_coeffs; }

◆ coeffs() [2/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
const Coefficients& Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::coeffs ( ) const
inline
Returns
a constant reference to the coefficients c_i of the plane equation: \( c_0*x_0 + ... + c_{d-1}*x_{d-1} + c_d = 0 \)

Definition at line 178 of file Hyperplane.h.

178 { return m_coeffs; }

◆ dim()

template<typename Scalar_ , int AmbientDim_, int Options_>
Index Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::dim ( ) const
inline
Returns
the dimension in which the plane holds

Definition at line 134 of file Hyperplane.h.

Eigen::Index Index
Definition: Hyperplane.h:46
const int Dynamic
Definition: Constants.h:24

◆ intersection()

template<typename Scalar_ , int AmbientDim_, int Options_>
VectorType Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::intersection ( const Hyperplane< Scalar_, AmbientDim_, Options_ > &  other) const
inline
Returns
the intersection of *this with other.
Warning
The ambient space must be a plane, i.e. have dimension 2, so that *this and other are lines.
Note
If other is approximately parallel to *this, this method will return any point on *this.

Definition at line 191 of file Hyperplane.h.

192  {
194  Scalar det = coeffs().coeff(0) * other.coeffs().coeff(1) - coeffs().coeff(1) * other.coeffs().coeff(0);
195  // since the line equations ax+by=c are normalized with a^2+b^2=1, the following tests
196  // whether the two lines are approximately parallel.
198  { // special case where the two lines are approximately parallel. Pick any point on the first line.
199  if(numext::abs(coeffs().coeff(1))>numext::abs(coeffs().coeff(0)))
200  return VectorType(coeffs().coeff(1), -coeffs().coeff(2)/coeffs().coeff(1)-coeffs().coeff(0));
201  else
202  return VectorType(-coeffs().coeff(2)/coeffs().coeff(0)-coeffs().coeff(1), coeffs().coeff(0));
203  }
204  else
205  { // general case
206  Scalar invdet = Scalar(1) / det;
207  return VectorType(invdet*(coeffs().coeff(1)*other.coeffs().coeff(2)-other.coeffs().coeff(1)*coeffs().coeff(2)),
208  invdet*(other.coeffs().coeff(0)*coeffs().coeff(2)-coeffs().coeff(0)*other.coeffs().coeff(2)));
209  }
210  }
if((m *x).isApprox(y))
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:51
const Coefficients & coeffs() const
Definition: Hyperplane.h:178
Matrix< Scalar, AmbientDimAtCompileTime, 1 > VectorType
Definition: Hyperplane.h:47
constexpr const Scalar & coeff(Index rowId, Index colId) const
bool isMuchSmallerThan(const Scalar &x, const OtherScalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())

◆ isApprox()

template<typename Scalar_ , int AmbientDim_, int Options_>
template<int OtherOptions>
bool Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::isApprox ( const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &  other,
const typename NumTraits< Scalar >::Real &  prec = NumTraits<Scalar>::dummy_precision() 
) const
inline
Returns
true if *this is approximately equal to other, within the precision determined by prec.
See also
MatrixBase::isApprox()

Definition at line 274 of file Hyperplane.h.

275  { return m_coeffs.isApprox(other.m_coeffs, prec); }

◆ normal() [1/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
NormalReturnType Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::normal ( )
inline
Returns
a non-constant reference to the unit normal vector of the plane, which corresponds to the linear part of the implicit equation.

Definition at line 164 of file Hyperplane.h.

164 { return NormalReturnType(m_coeffs,0,0,dim(),1); }
Block< Coefficients, AmbientDimAtCompileTime, 1 > NormalReturnType
Definition: Hyperplane.h:51
Index dim() const
Definition: Hyperplane.h:134

◆ normal() [2/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
ConstNormalReturnType Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::normal ( ) const
inline
Returns
a constant reference to the unit normal vector of the plane, which corresponds to the linear part of the implicit equation.

Definition at line 159 of file Hyperplane.h.

159 { return ConstNormalReturnType(m_coeffs,0,0,dim(),1); }
const Block< const Coefficients, AmbientDimAtCompileTime, 1 > ConstNormalReturnType
Definition: Hyperplane.h:52

◆ normalize()

template<typename Scalar_ , int AmbientDim_, int Options_>
void Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::normalize ( void  )
inline

normalizes *this

Definition at line 137 of file Hyperplane.h.

138  {
139  m_coeffs /= normal().norm();
140  }

◆ offset() [1/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
Scalar& Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::offset ( )
inline
Returns
a non-constant reference to the distance to the origin, which is also the constant part of the implicit equation

Definition at line 173 of file Hyperplane.h.

173 { return m_coeffs(dim()); }

◆ offset() [2/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
const Scalar& Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::offset ( ) const
inline
Returns
the distance to the origin, which is also the "constant term" of the implicit equation
Warning
the vector normal is assumed to be normalized.

Definition at line 169 of file Hyperplane.h.

169 { return m_coeffs.coeff(dim()); }

◆ projection()

template<typename Scalar_ , int AmbientDim_, int Options_>
VectorType Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::projection ( const VectorType p) const
inline
Returns
the projection of a point p onto the plane *this.

Definition at line 154 of file Hyperplane.h.

154 { return p - signedDistance(p) * normal(); }

◆ signedDistance()

template<typename Scalar_ , int AmbientDim_, int Options_>
Scalar Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::signedDistance ( const VectorType p) const
inline
Returns
the signed distance between the plane *this and a point p.
See also
absDistance()

Definition at line 145 of file Hyperplane.h.

145 { return normal().dot(p) + offset(); }

◆ Through() [1/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
static Hyperplane Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Through ( const VectorType p0,
const VectorType p1 
)
inlinestatic

Constructs a hyperplane passing through the two points. If the dimension of the ambient space is greater than 2, then there isn't uniqueness, so an arbitrary choice is made.

Definition at line 90 of file Hyperplane.h.

91  {
92  Hyperplane result(p0.size());
93  result.normal() = (p1 - p0).unitOrthogonal();
94  result.offset() = -p0.dot(result.normal());
95  return result;
96  }
Vector3f p0
Vector3f p1

◆ Through() [2/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
static Hyperplane Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::Through ( const VectorType p0,
const VectorType p1,
const VectorType p2 
)
inlinestatic

Constructs a hyperplane passing through the three points. The dimension of the ambient space is required to be exactly 3.

Definition at line 101 of file Hyperplane.h.

102  {
104  Hyperplane result(p0.size());
105  VectorType v0(p2 - p0), v1(p1 - p0);
106  result.normal() = v0.cross(v1);
107  RealScalar norm = result.normal().norm();
108  if(norm <= v0.norm() * v1.norm() * NumTraits<RealScalar>::epsilon())
109  {
110  Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
111  JacobiSVD<Matrix<Scalar,2,3>, ComputeFullV> svd(m);
112  result.normal() = svd.matrixV().col(2);
113  }
114  else
115  result.normal() /= norm;
116  result.offset() = -p0.dot(result.normal());
117  return result;
118  }
Matrix3f m
cout<< "Here is the matrix m:"<< endl<< m<< endl;JacobiSVD< MatrixXf, ComputeThinU|ComputeThinV > svd(m)
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
NumTraits< Scalar >::Real RealScalar
Definition: Hyperplane.h:45
@ ComputeFullV
Definition: Constants.h:399

◆ transform() [1/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
template<typename XprType >
Hyperplane& Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::transform ( const MatrixBase< XprType > &  mat,
TransformTraits  traits = Affine 
)
inline

Applies the transformation matrix mat to *this and returns a reference to *this.

Parameters
matthe Dim x Dim transformation matrix
traitsspecifies whether the matrix mat represents an Isometry or a more generic Affine transformation. The default is Affine.

Definition at line 219 of file Hyperplane.h.

220  {
221  if (traits==Affine)
222  {
223  normal() = mat.inverse().transpose() * normal();
224  m_coeffs /= normal().norm();
225  }
226  else if (traits==Isometry)
227  normal() = mat * normal();
228  else
229  {
230  eigen_assert(0 && "invalid traits value in Hyperplane::transform()");
231  }
232  return *this;
233  }
#define eigen_assert(x)
Definition: Macros.h:902
@ Affine
Definition: Constants.h:464
@ Isometry
Definition: Constants.h:461

◆ transform() [2/2]

template<typename Scalar_ , int AmbientDim_, int Options_>
template<int TrOptions>
Hyperplane& Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::transform ( const Transform< Scalar, AmbientDimAtCompileTime, Affine, TrOptions > &  t,
TransformTraits  traits = Affine 
)
inline

Applies the transformation t to *this and returns a reference to *this.

Parameters
tthe transformation of dimension Dim
traitsspecifies whether the transformation t represents an Isometry or a more generic Affine transformation. The default is Affine. Other kind of transformations are not supported.

Definition at line 243 of file Hyperplane.h.

245  {
246  transform(t.linear(), traits);
247  offset() -= normal().dot(t.translation());
248  return *this;
249  }
Hyperplane & transform(const MatrixBase< XprType > &mat, TransformTraits traits=Affine)
Definition: Hyperplane.h:219

Member Data Documentation

◆ m_coeffs

template<typename Scalar_ , int AmbientDim_, int Options_>
Coefficients Eigen::Hyperplane< Scalar_, AmbientDim_, Options_ >::m_coeffs
protected

Definition at line 279 of file Hyperplane.h.


The documentation for this class was generated from the following files: