11#ifndef EIGEN_HYPERPLANE_H
12#define EIGEN_HYPERPLANE_H
33template <
typename _Scalar,
int _AmbientDim,
int _Options>
37 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim==
Dynamic ?
Dynamic : _AmbientDim+1)
39 AmbientDimAtCompileTime = _AmbientDim,
42 typedef _Scalar Scalar;
43 typedef typename NumTraits<Scalar>::Real RealScalar;
45 typedef Matrix<Scalar,AmbientDimAtCompileTime,1>
VectorType;
49 typedef Block<Coefficients,AmbientDimAtCompileTime,1> NormalReturnType;
50 typedef const Block<const Coefficients,AmbientDimAtCompileTime,1> ConstNormalReturnType;
55 template<
int OtherOptions>
56 EIGEN_DEVICE_FUNC
Hyperplane(
const Hyperplane<Scalar,AmbientDimAtCompileTime,OtherOptions>& other)
68 : m_coeffs(n.size()+1)
79 : m_coeffs(n.size()+1)
91 result.normal() = (p1 - p0).unitOrthogonal();
92 result.offset() = -p0.dot(result.normal());
101 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(
VectorType, 3)
104 result.normal() = v0.cross(v1);
105 RealScalar norm = result.normal().norm();
108 Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
110 result.normal() = svd.matrixV().col(2);
113 result.normal() /= norm;
114 result.offset() = -p0.dot(result.normal());
123 EIGEN_DEVICE_FUNC
explicit Hyperplane(
const ParametrizedLine<Scalar, AmbientDimAtCompileTime>& parametrized)
125 normal() = parametrized.direction().unitOrthogonal();
132 EIGEN_DEVICE_FUNC
inline Index dim()
const {
return AmbientDimAtCompileTime==
Dynamic ? m_coeffs.size()-1 :
Index(AmbientDimAtCompileTime); }
137 m_coeffs /=
normal().norm();
157 EIGEN_DEVICE_FUNC
inline ConstNormalReturnType
normal()
const {
return ConstNormalReturnType(m_coeffs,0,0,
dim(),1); }
162 EIGEN_DEVICE_FUNC
inline NormalReturnType
normal() {
return NormalReturnType(m_coeffs,0,0,
dim(),1); }
167 EIGEN_DEVICE_FUNC
inline const Scalar&
offset()
const {
return m_coeffs.
coeff(
dim()); }
171 EIGEN_DEVICE_FUNC
inline Scalar&
offset() {
return m_coeffs(
dim()); }
191 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(
VectorType, 2)
195 if(internal::isMuchSmallerThan(det, Scalar(1)))
197 if(numext::abs(
coeffs().coeff(1))>numext::abs(
coeffs().coeff(0)))
204 Scalar invdet = Scalar(1) / det;
216 template<
typename XprType>
222 m_coeffs /=
normal().norm();
228 eigen_assert(0 &&
"invalid traits value in Hyperplane::transform()");
240 template<
int TrOptions>
241 EIGEN_DEVICE_FUNC
inline Hyperplane&
transform(
const Transform<Scalar,AmbientDimAtCompileTime,Affine,TrOptions>& t,
254 template<
typename NewScalarType>
255 EIGEN_DEVICE_FUNC
inline typename internal::cast_return_type<
Hyperplane,
256 Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type
cast()
const
258 return typename internal::cast_return_type<
Hyperplane,
259 Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*
this);
263 template<
typename OtherScalarType,
int OtherOptions>
264 EIGEN_DEVICE_FUNC
inline explicit Hyperplane(
const Hyperplane<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other)
265 { m_coeffs = other.coeffs().template cast<Scalar>(); }
271 template<
int OtherOptions>
273 {
return m_coeffs.isApprox(other.m_coeffs, prec); }
277 Coefficients m_coeffs;
A hyperplane.
Definition Hyperplane.h:35
Scalar & offset()
Definition Hyperplane.h:171
Hyperplane(const VectorType &n, const VectorType &e)
Definition Hyperplane.h:67
Index dim() const
Definition Hyperplane.h:132
static Hyperplane Through(const VectorType &p0, const VectorType &p1, const VectorType &p2)
Definition Hyperplane.h:99
Scalar absDistance(const VectorType &p) const
Definition Hyperplane.h:148
VectorType intersection(const Hyperplane &other) const
Definition Hyperplane.h:189
Hyperplane & transform(const Transform< Scalar, AmbientDimAtCompileTime, Affine, TrOptions > &t, TransformTraits traits=Affine)
Definition Hyperplane.h:241
NormalReturnType normal()
Definition Hyperplane.h:162
Eigen::Index Index
Definition Hyperplane.h:44
const Coefficients & coeffs() const
Definition Hyperplane.h:176
Hyperplane(Index _dim)
Definition Hyperplane.h:62
Hyperplane(const VectorType &n, const Scalar &d)
Definition Hyperplane.h:78
static Hyperplane Through(const VectorType &p0, const VectorType &p1)
Definition Hyperplane.h:88
VectorType projection(const VectorType &p) const
Definition Hyperplane.h:152
Hyperplane()
Definition Hyperplane.h:53
Hyperplane & transform(const MatrixBase< XprType > &mat, TransformTraits traits=Affine)
Definition Hyperplane.h:217
Scalar signedDistance(const VectorType &p) const
Definition Hyperplane.h:143
ConstNormalReturnType normal() const
Definition Hyperplane.h:157
Coefficients & coeffs()
Definition Hyperplane.h:181
Hyperplane(const ParametrizedLine< Scalar, AmbientDimAtCompileTime > ¶metrized)
Definition Hyperplane.h:123
internal::cast_return_type< Hyperplane, Hyperplane< NewScalarType, AmbientDimAtCompileTime, Options > >::type cast() const
Definition Hyperplane.h:256
bool isApprox(const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Hyperplane.h:272
Hyperplane(const Hyperplane< OtherScalarType, AmbientDimAtCompileTime, OtherOptions > &other)
Definition Hyperplane.h:264
void normalize(void)
Definition Hyperplane.h:135
const Scalar & offset() const
Definition Hyperplane.h:167
const Scalar & coeff(Index rowId, Index colId) const
Definition PlainObjectBase.h:152
TransformTraits
Definition Constants.h:455
@ ComputeFullV
Definition Constants.h:397
@ Affine
Definition Constants.h:460
@ Isometry
Definition Constants.h:457
Namespace containing all symbols from the Eigen library.
Definition Core:141
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition Meta.h:74
const int Dynamic
Definition Constants.h:22
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition NumTraits.h:233