12#ifndef EIGEN_HYPERPLANE_H
13#define EIGEN_HYPERPLANE_H
16#include "./InternalHeaderCheck.h"
37template <
typename Scalar_,
int AmbientDim_,
int Options_>
40 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar_,
41 AmbientDim_ == Dynamic ? Dynamic : AmbientDim_ + 1)
42 enum { AmbientDimAtCompileTime = AmbientDim_, Options = Options_ };
43 using Scalar = Scalar_;
44 using RealScalar =
typename NumTraits<Scalar>::Real;
48 Matrix<Scalar,
Index(AmbientDimAtCompileTime) == Dynamic ? Dynamic :
Index(AmbientDimAtCompileTime) + 1, 1,
56 template <
int OtherOptions>
58 : m_coeffs(other.
coeffs()) {}
67 EIGEN_DEVICE_FUNC
inline Hyperplane(
const VectorType& n,
const VectorType& e) : m_coeffs(n.size() + 1) {
76 EIGEN_DEVICE_FUNC
inline Hyperplane(
const VectorType& n,
const Scalar& d) : m_coeffs(n.size() + 1) {
84 EIGEN_DEVICE_FUNC
static inline Hyperplane Through(
const VectorType& p0,
const VectorType& p1) {
86 result.
normal() = (p1 - p0).unitOrthogonal();
94 EIGEN_DEVICE_FUNC
static inline Hyperplane Through(
const VectorType& p0,
const VectorType& p1,
const VectorType& p2) {
95 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 3)
97 VectorType v0(p2 - p0), v1(p1 - p0);
98 result.
normal() = v0.cross(v1);
99 RealScalar norm = result.
normal().norm();
100 if (norm <= v0.norm() * v1.norm() * NumTraits<RealScalar>::epsilon()) {
102 m << v0.transpose(), v1.transpose();
117 : m_coeffs(parametrized.
dim() + 1) {
118 normal() = parametrized.direction().unitOrthogonal();
124 return AmbientDimAtCompileTime == Dynamic ? m_coeffs.size() - 1 :
Index(AmbientDimAtCompileTime);
147 EIGEN_DEVICE_FUNC
inline ConstNormalReturnType
normal()
const {
148 return ConstNormalReturnType(m_coeffs, 0, 0,
dim(), 1);
154 EIGEN_DEVICE_FUNC
inline NormalReturnType
normal() {
return NormalReturnType(m_coeffs, 0, 0,
dim(), 1); }
159 EIGEN_DEVICE_FUNC
inline const Scalar&
offset()
const {
return m_coeffs.coeff(
dim()); }
163 EIGEN_DEVICE_FUNC
inline Scalar&
offset() {
return m_coeffs(
dim()); }
168 EIGEN_DEVICE_FUNC
inline const Coefficients&
coeffs()
const {
return m_coeffs; }
173 EIGEN_DEVICE_FUNC
inline Coefficients&
coeffs() {
return m_coeffs; }
182 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
186 if (internal::isMuchSmallerThan(det, Scalar(1))) {
188 if (numext::abs(
coeffs().coeff(1)) > numext::abs(
coeffs().coeff(0)))
193 Scalar invdet = Scalar(1) / det;
206 template <
typename XprType>
210 m_coeffs /=
normal().norm();
214 eigen_assert(0 &&
"invalid traits value in Hyperplane::transform()");
226 template <
int TrOptions>
239 template <
typename NewScalarType>
240 EIGEN_DEVICE_FUNC
inline
241 typename internal::cast_return_type<
Hyperplane,
245 typename internal::cast_return_type<
Hyperplane,
250 template <
typename OtherScalarType,
int OtherOptions>
264 template <
int OtherOptions>
267 const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision())
const {
268 return m_coeffs.isApprox(other.
coeffs(), prec);
293 template <
int OtherOptions>
296 const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision())
const {
297 const RealScalar this_norm =
normal().norm();
298 const RealScalar other_norm = other.
normal().norm();
299 eigen_assert(this_norm > RealScalar(0) && other_norm > RealScalar(0));
305 const RealScalar inner_norm = numext::abs(inner);
306 const Scalar phase = inner_norm > RealScalar(0) ? inner / Scalar(inner_norm) : Scalar(1);
307 if (!((other.
normal() / Scalar(other_norm) - phase * (
normal() / Scalar(this_norm))).norm() <= prec))
return false;
308 return internal::isApprox(other.
offset() / Scalar(other_norm), numext::conj(phase) * (
offset() / Scalar(this_norm)),
313 Coefficients m_coeffs;
Expression of a fixed-size or dynamic-size block.
Definition Block.h:111
A hyperplane.
Definition Hyperplane.h:38
static Hyperplane Through(const VectorType &p0, const VectorType &p1)
Definition Hyperplane.h:84
Hyperplane & transform(const MatrixBase< XprType > &mat, TransformTraits traits=Affine)
Definition Hyperplane.h:207
VectorType intersection(const Hyperplane &other) const
Definition Hyperplane.h:181
ConstNormalReturnType normal() const
Definition Hyperplane.h:147
Scalar signedDistance(const VectorType &p) const
Definition Hyperplane.h:133
Hyperplane(const VectorType &n, const VectorType &e)
Definition Hyperplane.h:67
NormalReturnType normal()
Definition Hyperplane.h:154
Eigen::Index Index
Definition Hyperplane.h:45
Hyperplane()
Definition Hyperplane.h:54
const Coefficients & coeffs() const
Definition Hyperplane.h:168
Coefficients & coeffs()
Definition Hyperplane.h:173
internal::cast_return_type< Hyperplane, Hyperplane< NewScalarType, AmbientDimAtCompileTime, Options > >::type cast() const
Definition Hyperplane.h:243
Index dim() const
Definition Hyperplane.h:123
Scalar absDistance(const VectorType &p) const
Definition Hyperplane.h:138
static Hyperplane Through(const VectorType &p0, const VectorType &p1, const VectorType &p2)
Definition Hyperplane.h:94
const Scalar & offset() const
Definition Hyperplane.h:159
Hyperplane(const VectorType &n, const Scalar &d)
Definition Hyperplane.h:76
bool isApprox(const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Hyperplane.h:265
Hyperplane(const Hyperplane< OtherScalarType, AmbientDimAtCompileTime, OtherOptions > &other)
Definition Hyperplane.h:251
bool isCoincident(const Hyperplane< Scalar, AmbientDimAtCompileTime, OtherOptions > &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition Hyperplane.h:294
void normalize(void)
Definition Hyperplane.h:128
Scalar & offset()
Definition Hyperplane.h:163
Hyperplane(Index _dim)
Definition Hyperplane.h:62
Hyperplane(const ParametrizedLine< Scalar, AmbientDimAtCompileTime > ¶metrized)
Definition Hyperplane.h:116
VectorType projection(const VectorType &p) const
Definition Hyperplane.h:142
Hyperplane & transform(const Transform< Scalar, AmbientDimAtCompileTime, Affine, TrOptions > &t, TransformTraits traits=Affine)
Definition Hyperplane.h:227
Two-sided Jacobi SVD decomposition of a rectangular matrix.
Definition JacobiSVD.h:616
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
Inverse< Derived > inverse() const
Definition InverseImpl.h:277
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
A parametrized line.
Definition ParametrizedLine.h:36
constexpr const Scalar & coeff(Index rowId, Index colId) const
Definition PlainObjectBase.h:187
const MatrixVType & matrixV() const
Definition SVDBase.h:192
TransformTraits
Definition Constants.h:470
@ ComputeFullV
Definition Constants.h:398
@ Affine
Definition Constants.h:475
@ Isometry
Definition Constants.h:472