Warning, file /include/eigen3/Eigen/src/Geometry/ParametrizedLine.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_PARAMETRIZEDLINE_H
0012 #define EIGEN_PARAMETRIZEDLINE_H
0013
0014 namespace Eigen {
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 template <typename _Scalar, int _AmbientDim, int _Options>
0030 class ParametrizedLine
0031 {
0032 public:
0033 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(_Scalar,_AmbientDim)
0034 enum {
0035 AmbientDimAtCompileTime = _AmbientDim,
0036 Options = _Options
0037 };
0038 typedef _Scalar Scalar;
0039 typedef typename NumTraits<Scalar>::Real RealScalar;
0040 typedef Eigen::Index Index;
0041 typedef Matrix<Scalar,AmbientDimAtCompileTime,1,Options> VectorType;
0042
0043
0044 EIGEN_DEVICE_FUNC inline ParametrizedLine() {}
0045
0046 template<int OtherOptions>
0047 EIGEN_DEVICE_FUNC ParametrizedLine(const ParametrizedLine<Scalar,AmbientDimAtCompileTime,OtherOptions>& other)
0048 : m_origin(other.origin()), m_direction(other.direction())
0049 {}
0050
0051
0052
0053 EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {}
0054
0055
0056
0057
0058 EIGEN_DEVICE_FUNC ParametrizedLine(const VectorType& origin, const VectorType& direction)
0059 : m_origin(origin), m_direction(direction) {}
0060
0061 template <int OtherOptions>
0062 EIGEN_DEVICE_FUNC explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane);
0063
0064
0065 EIGEN_DEVICE_FUNC static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
0066 { return ParametrizedLine(p0, (p1-p0).normalized()); }
0067
0068 EIGEN_DEVICE_FUNC ~ParametrizedLine() {}
0069
0070
0071 EIGEN_DEVICE_FUNC inline Index dim() const { return m_direction.size(); }
0072
0073 EIGEN_DEVICE_FUNC const VectorType& origin() const { return m_origin; }
0074 EIGEN_DEVICE_FUNC VectorType& origin() { return m_origin; }
0075
0076 EIGEN_DEVICE_FUNC const VectorType& direction() const { return m_direction; }
0077 EIGEN_DEVICE_FUNC VectorType& direction() { return m_direction; }
0078
0079
0080
0081
0082 EIGEN_DEVICE_FUNC RealScalar squaredDistance(const VectorType& p) const
0083 {
0084 VectorType diff = p - origin();
0085 return (diff - direction().dot(diff) * direction()).squaredNorm();
0086 }
0087
0088
0089
0090 EIGEN_DEVICE_FUNC RealScalar distance(const VectorType& p) const { EIGEN_USING_STD(sqrt) return sqrt(squaredDistance(p)); }
0091
0092
0093 EIGEN_DEVICE_FUNC VectorType projection(const VectorType& p) const
0094 { return origin() + direction().dot(p-origin()) * direction(); }
0095
0096 EIGEN_DEVICE_FUNC VectorType pointAt(const Scalar& t) const;
0097
0098 template <int OtherOptions>
0099 EIGEN_DEVICE_FUNC Scalar intersectionParameter(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
0100
0101 template <int OtherOptions>
0102 EIGEN_DEVICE_FUNC Scalar intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
0103
0104 template <int OtherOptions>
0105 EIGEN_DEVICE_FUNC VectorType intersectionPoint(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
0106
0107
0108
0109
0110
0111
0112
0113 template<typename XprType>
0114 EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const MatrixBase<XprType>& mat, TransformTraits traits = Affine)
0115 {
0116 if (traits==Affine)
0117 direction() = (mat * direction()).normalized();
0118 else if (traits==Isometry)
0119 direction() = mat * direction();
0120 else
0121 {
0122 eigen_assert(0 && "invalid traits value in ParametrizedLine::transform()");
0123 }
0124 origin() = mat * origin();
0125 return *this;
0126 }
0127
0128
0129
0130
0131
0132
0133
0134
0135 template<int TrOptions>
0136 EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const Transform<Scalar,AmbientDimAtCompileTime,Affine,TrOptions>& t,
0137 TransformTraits traits = Affine)
0138 {
0139 transform(t.linear(), traits);
0140 origin() += t.translation();
0141 return *this;
0142 }
0143
0144
0145
0146
0147
0148
0149 template<typename NewScalarType>
0150 EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<ParametrizedLine,
0151 ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type cast() const
0152 {
0153 return typename internal::cast_return_type<ParametrizedLine,
0154 ParametrizedLine<NewScalarType,AmbientDimAtCompileTime,Options> >::type(*this);
0155 }
0156
0157
0158 template<typename OtherScalarType,int OtherOptions>
0159 EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(const ParametrizedLine<OtherScalarType,AmbientDimAtCompileTime,OtherOptions>& other)
0160 {
0161 m_origin = other.origin().template cast<Scalar>();
0162 m_direction = other.direction().template cast<Scalar>();
0163 }
0164
0165
0166
0167
0168
0169 EIGEN_DEVICE_FUNC bool isApprox(const ParametrizedLine& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
0170 { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
0171
0172 protected:
0173
0174 VectorType m_origin, m_direction;
0175 };
0176
0177
0178
0179
0180
0181 template <typename _Scalar, int _AmbientDim, int _Options>
0182 template <int OtherOptions>
0183 EIGEN_DEVICE_FUNC inline ParametrizedLine<_Scalar, _AmbientDim,_Options>::ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim,OtherOptions>& hyperplane)
0184 {
0185 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
0186 direction() = hyperplane.normal().unitOrthogonal();
0187 origin() = -hyperplane.normal()*hyperplane.offset();
0188 }
0189
0190
0191
0192 template <typename _Scalar, int _AmbientDim, int _Options>
0193 EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType
0194 ParametrizedLine<_Scalar, _AmbientDim,_Options>::pointAt(const _Scalar& t) const
0195 {
0196 return origin() + (direction()*t);
0197 }
0198
0199
0200
0201 template <typename _Scalar, int _AmbientDim, int _Options>
0202 template <int OtherOptions>
0203 EIGEN_DEVICE_FUNC inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersectionParameter(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const
0204 {
0205 return -(hyperplane.offset()+hyperplane.normal().dot(origin()))
0206 / hyperplane.normal().dot(direction());
0207 }
0208
0209
0210
0211
0212
0213 template <typename _Scalar, int _AmbientDim, int _Options>
0214 template <int OtherOptions>
0215 EIGEN_DEVICE_FUNC inline _Scalar ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const
0216 {
0217 return intersectionParameter(hyperplane);
0218 }
0219
0220
0221
0222 template <typename _Scalar, int _AmbientDim, int _Options>
0223 template <int OtherOptions>
0224 EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType
0225 ParametrizedLine<_Scalar, _AmbientDim,_Options>::intersectionPoint(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const
0226 {
0227 return pointAt(intersectionParameter(hyperplane));
0228 }
0229
0230 }
0231
0232 #endif