Warning, file /include/eigen3/Eigen/src/Geometry/Hyperplane.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef EIGEN_HYPERPLANE_H
0012 #define EIGEN_HYPERPLANE_H
0013
0014 namespace Eigen {
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 template <typename _Scalar, int _AmbientDim, int _Options>
0034 class Hyperplane
0035 {
0036 public:
0037 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim==Dynamic ? Dynamic : _AmbientDim+1)
0038 enum {
0039 AmbientDimAtCompileTime = _AmbientDim,
0040 Options = _Options
0041 };
0042 typedef _Scalar Scalar;
0043 typedef typename NumTraits<Scalar>::Real RealScalar;
0044 typedef Eigen::Index Index;
0045 typedef Matrix<Scalar,AmbientDimAtCompileTime,1> VectorType;
0046 typedef Matrix<Scalar,Index(AmbientDimAtCompileTime)==Dynamic
0047 ? Dynamic
0048 : Index(AmbientDimAtCompileTime)+1,1,Options> Coefficients;
0049 typedef Block<Coefficients,AmbientDimAtCompileTime,1> NormalReturnType;
0050 typedef const Block<const Coefficients,AmbientDimAtCompileTime,1> ConstNormalReturnType;
0051
0052
0053 EIGEN_DEVICE_FUNC inline Hyperplane() {}
0054
0055 template<int OtherOptions>
0056 EIGEN_DEVICE_FUNC Hyperplane(const Hyperplane<Scalar,AmbientDimAtCompileTime,OtherOptions>& other)
0057 : m_coeffs(other.coeffs())
0058 {}
0059
0060
0061
0062 EIGEN_DEVICE_FUNC inline explicit Hyperplane(Index _dim) : m_coeffs(_dim+1) {}
0063
0064
0065
0066
0067 EIGEN_DEVICE_FUNC inline Hyperplane(const VectorType& n, const VectorType& e)
0068 : m_coeffs(n.size()+1)
0069 {
0070 normal() = n;
0071 offset() = -n.dot(e);
0072 }
0073
0074
0075
0076
0077
0078 EIGEN_DEVICE_FUNC inline Hyperplane(const VectorType& n, const Scalar& d)
0079 : m_coeffs(n.size()+1)
0080 {
0081 normal() = n;
0082 offset() = d;
0083 }
0084
0085
0086
0087
0088 EIGEN_DEVICE_FUNC static inline Hyperplane Through(const VectorType& p0, const VectorType& p1)
0089 {
0090 Hyperplane result(p0.size());
0091 result.normal() = (p1 - p0).unitOrthogonal();
0092 result.offset() = -p0.dot(result.normal());
0093 return result;
0094 }
0095
0096
0097
0098
0099 EIGEN_DEVICE_FUNC static inline Hyperplane Through(const VectorType& p0, const VectorType& p1, const VectorType& p2)
0100 {
0101 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 3)
0102 Hyperplane result(p0.size());
0103 VectorType v0(p2 - p0), v1(p1 - p0);
0104 result.normal() = v0.cross(v1);
0105 RealScalar norm = result.normal().norm();
0106 if(norm <= v0.norm() * v1.norm() * NumTraits<RealScalar>::epsilon())
0107 {
0108 Matrix<Scalar,2,3> m; m << v0.transpose(), v1.transpose();
0109 JacobiSVD<Matrix<Scalar,2,3> > svd(m, ComputeFullV);
0110 result.normal() = svd.matrixV().col(2);
0111 }
0112 else
0113 result.normal() /= norm;
0114 result.offset() = -p0.dot(result.normal());
0115 return result;
0116 }
0117
0118
0119
0120
0121
0122
0123 EIGEN_DEVICE_FUNC explicit Hyperplane(const ParametrizedLine<Scalar, AmbientDimAtCompileTime>& parametrized)
0124 {
0125 normal() = parametrized.direction().unitOrthogonal();
0126 offset() = -parametrized.origin().dot(normal());
0127 }
0128
0129 EIGEN_DEVICE_FUNC ~Hyperplane() {}
0130
0131
0132 EIGEN_DEVICE_FUNC inline Index dim() const { return AmbientDimAtCompileTime==Dynamic ? m_coeffs.size()-1 : Index(AmbientDimAtCompileTime); }
0133
0134
0135 EIGEN_DEVICE_FUNC void normalize(void)
0136 {
0137 m_coeffs /= normal().norm();
0138 }
0139
0140
0141
0142
0143 EIGEN_DEVICE_FUNC inline Scalar signedDistance(const VectorType& p) const { return normal().dot(p) + offset(); }
0144
0145
0146
0147
0148 EIGEN_DEVICE_FUNC inline Scalar absDistance(const VectorType& p) const { return numext::abs(signedDistance(p)); }
0149
0150
0151
0152 EIGEN_DEVICE_FUNC inline VectorType projection(const VectorType& p) const { return p - signedDistance(p) * normal(); }
0153
0154
0155
0156
0157 EIGEN_DEVICE_FUNC inline ConstNormalReturnType normal() const { return ConstNormalReturnType(m_coeffs,0,0,dim(),1); }
0158
0159
0160
0161
0162 EIGEN_DEVICE_FUNC inline NormalReturnType normal() { return NormalReturnType(m_coeffs,0,0,dim(),1); }
0163
0164
0165
0166
0167 EIGEN_DEVICE_FUNC inline const Scalar& offset() const { return m_coeffs.coeff(dim()); }
0168
0169
0170
0171 EIGEN_DEVICE_FUNC inline Scalar& offset() { return m_coeffs(dim()); }
0172
0173
0174
0175
0176 EIGEN_DEVICE_FUNC inline const Coefficients& coeffs() const { return m_coeffs; }
0177
0178
0179
0180
0181 EIGEN_DEVICE_FUNC inline Coefficients& coeffs() { return m_coeffs; }
0182
0183
0184
0185
0186
0187
0188
0189 EIGEN_DEVICE_FUNC VectorType intersection(const Hyperplane& other) const
0190 {
0191 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
0192 Scalar det = coeffs().coeff(0) * other.coeffs().coeff(1) - coeffs().coeff(1) * other.coeffs().coeff(0);
0193
0194
0195 if(internal::isMuchSmallerThan(det, Scalar(1)))
0196 {
0197 if(numext::abs(coeffs().coeff(1))>numext::abs(coeffs().coeff(0)))
0198 return VectorType(coeffs().coeff(1), -coeffs().coeff(2)/coeffs().coeff(1)-coeffs().coeff(0));
0199 else
0200 return VectorType(-coeffs().coeff(2)/coeffs().coeff(0)-coeffs().coeff(1), coeffs().coeff(0));
0201 }
0202 else
0203 {
0204 Scalar invdet = Scalar(1) / det;
0205 return VectorType(invdet*(coeffs().coeff(1)*other.coeffs().coeff(2)-other.coeffs().coeff(1)*coeffs().coeff(2)),
0206 invdet*(other.coeffs().coeff(0)*coeffs().coeff(2)-coeffs().coeff(0)*other.coeffs().coeff(2)));
0207 }
0208 }
0209
0210
0211
0212
0213
0214
0215
0216 template<typename XprType>
0217 EIGEN_DEVICE_FUNC inline Hyperplane& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine)
0218 {
0219 if (traits==Affine)
0220 {
0221 normal() = mat.inverse().transpose() * normal();
0222 m_coeffs /= normal().norm();
0223 }
0224 else if (traits==Isometry)
0225 normal() = mat * normal();
0226 else
0227 {
0228 eigen_assert(0 && "invalid traits value in Hyperplane::transform()");
0229 }
0230 return *this;
0231 }
0232
0233
0234
0235
0236
0237
0238
0239
0240 template<int TrOptions>
0241 EIGEN_DEVICE_FUNC inline Hyperplane& transform(const Transform<Scalar,AmbientDimAtCompileTime,Affine,TrOptions>& t,
0242 TransformTraits traits = Affine)
0243 {
0244 transform(t.linear(), traits);
0245 offset() -= normal().dot(t.translation());
0246 return *this;
0247 }
0248
0249
0250
0251
0252
0253
0254 template<typename NewScalarType>
0255 EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<Hyperplane,
0256 Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type cast() const
0257 {
0258 return typename internal::cast_return_type<Hyperplane,
0259 Hyperplane<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this);
0260 }
0261
0262
0263 template<typename OtherScalarType,int OtherOptions>
0264 EIGEN_DEVICE_FUNC inline explicit Hyperplane(const Hyperplane<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other)
0265 { m_coeffs = other.coeffs().template cast<Scalar>(); }
0266
0267
0268
0269
0270
0271 template<int OtherOptions>
0272 EIGEN_DEVICE_FUNC bool isApprox(const Hyperplane<Scalar,AmbientDimAtCompileTime,OtherOptions>& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
0273 { return m_coeffs.isApprox(other.m_coeffs, prec); }
0274
0275 protected:
0276
0277 Coefficients m_coeffs;
0278 };
0279
0280 }
0281
0282 #endif