ParametrizedLine.h
Go to the documentation of this file.
1 // This file is part of Eigen, a lightweight C++ template library
2 // for linear algebra.
3 //
4 // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
5 // Copyright (C) 2008 Benoit Jacob <jacob.benoit.1@gmail.com>
6 //
7 // This Source Code Form is subject to the terms of the Mozilla
8 // Public License v. 2.0. If a copy of the MPL was not distributed
9 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11 #ifndef EIGEN_PARAMETRIZEDLINE_H
12 #define EIGEN_PARAMETRIZEDLINE_H
13 
14 namespace Eigen {
15 
29 template <typename _Scalar, int _AmbientDim, int _Options>
30 class ParametrizedLine
31 {
32 public:
34  enum {
35  AmbientDimAtCompileTime = _AmbientDim,
36  Options = _Options
37  };
38  typedef _Scalar Scalar;
40  typedef Eigen::Index Index;
42 
44  EIGEN_DEVICE_FUNC inline ParametrizedLine() {}
45 
46  template<int OtherOptions>
48  : m_origin(other.origin()), m_direction(other.direction())
49  {}
50 
53  EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {}
54 
58  EIGEN_DEVICE_FUNC ParametrizedLine(const VectorType& origin, const VectorType& direction)
59  : m_origin(origin), m_direction(direction) {}
60 
61  template <int OtherOptions>
62  EIGEN_DEVICE_FUNC explicit ParametrizedLine(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane);
63 
65  EIGEN_DEVICE_FUNC static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1)
66  { return ParametrizedLine(p0, (p1-p0).normalized()); }
67 
68  EIGEN_DEVICE_FUNC ~ParametrizedLine() {}
69 
71  EIGEN_DEVICE_FUNC inline Index dim() const { return m_direction.size(); }
72 
73  EIGEN_DEVICE_FUNC const VectorType& origin() const { return m_origin; }
74  EIGEN_DEVICE_FUNC VectorType& origin() { return m_origin; }
75 
76  EIGEN_DEVICE_FUNC const VectorType& direction() const { return m_direction; }
77  EIGEN_DEVICE_FUNC VectorType& direction() { return m_direction; }
78 
82  EIGEN_DEVICE_FUNC RealScalar squaredDistance(const VectorType& p) const
83  {
84  VectorType diff = p - origin();
85  return (diff - direction().dot(diff) * direction()).squaredNorm();
86  }
90  EIGEN_DEVICE_FUNC RealScalar distance(const VectorType& p) const { EIGEN_USING_STD_MATH(sqrt) return sqrt(squaredDistance(p)); }
91 
93  EIGEN_DEVICE_FUNC VectorType projection(const VectorType& p) const
94  { return origin() + direction().dot(p-origin()) * direction(); }
95 
96  EIGEN_DEVICE_FUNC VectorType pointAt(const Scalar& t) const;
97 
98  template <int OtherOptions>
99  EIGEN_DEVICE_FUNC Scalar intersectionParameter(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
100 
101  template <int OtherOptions>
102  EIGEN_DEVICE_FUNC Scalar intersection(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
103 
104  template <int OtherOptions>
105  EIGEN_DEVICE_FUNC VectorType intersectionPoint(const Hyperplane<_Scalar, _AmbientDim, OtherOptions>& hyperplane) const;
106 
112  template<typename NewScalarType>
113  EIGEN_DEVICE_FUNC inline typename internal::cast_return_type<ParametrizedLine,
115  {
118  }
119 
121  template<typename OtherScalarType,int OtherOptions>
123  {
124  m_origin = other.origin().template cast<Scalar>();
125  m_direction = other.direction().template cast<Scalar>();
126  }
127 
132  EIGEN_DEVICE_FUNC bool isApprox(const ParametrizedLine& other, const typename NumTraits<Scalar>::Real& prec = NumTraits<Scalar>::dummy_precision()) const
133  { return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec); }
134 
135 protected:
136 
137  VectorType m_origin, m_direction;
138 };
139 
144 template <typename _Scalar, int _AmbientDim, int _Options>
145 template <int OtherOptions>
147 {
149  direction() = hyperplane.normal().unitOrthogonal();
150  origin() = -hyperplane.normal()*hyperplane.offset();
151 }
152 
155 template <typename _Scalar, int _AmbientDim, int _Options>
156 EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType
158 {
159  return origin() + (direction()*t);
160 }
161 
164 template <typename _Scalar, int _AmbientDim, int _Options>
165 template <int OtherOptions>
167 {
168  return -(hyperplane.offset()+hyperplane.normal().dot(origin()))
169  / hyperplane.normal().dot(direction());
170 }
171 
172 
176 template <typename _Scalar, int _AmbientDim, int _Options>
177 template <int OtherOptions>
179 {
180  return intersectionParameter(hyperplane);
181 }
182 
185 template <typename _Scalar, int _AmbientDim, int _Options>
186 template <int OtherOptions>
187 EIGEN_DEVICE_FUNC inline typename ParametrizedLine<_Scalar, _AmbientDim,_Options>::VectorType
189 {
190  return pointAt(intersectionParameter(hyperplane));
191 }
192 
193 } // end namespace Eigen
194 
195 #endif // EIGEN_PARAMETRIZEDLINE_H
EIGEN_DEVICE_FUNC const VectorType & direction() const
EIGEN_DEVICE_FUNC RealScalar distance(const VectorType &p) const
EIGEN_DEVICE_FUNC ~ParametrizedLine()
EIGEN_DEVICE_FUNC ParametrizedLine(const VectorType &origin, const VectorType &direction)
EIGEN_DEVICE_FUNC ParametrizedLine()
EIGEN_DEVICE_FUNC bool isApprox(const ParametrizedLine &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
EIGEN_DEVICE_FUNC RealScalar squaredDistance(const VectorType &p) const
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
Definition: LDLT.h:16
Holds information about the various numeric (i.e. scalar) types allowed by Eigen. ...
Definition: NumTraits.h:150
EIGEN_DEVICE_FUNC VectorType pointAt(const Scalar &t) const
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar, Size)
Definition: Memory.h:691
EIGEN_DEVICE_FUNC Scalar intersectionParameter(const Hyperplane< _Scalar, _AmbientDim, OtherOptions > &hyperplane) const
TFSIMD_FORCE_INLINE Vector3 normalized() const
EIGEN_DEVICE_FUNC Index dim() const
Matrix< Scalar, AmbientDimAtCompileTime, 1, Options > VectorType
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:33
EIGEN_DEVICE_FUNC ParametrizedLine(const ParametrizedLine< OtherScalarType, AmbientDimAtCompileTime, OtherOptions > &other)
EIGEN_DEVICE_FUNC internal::cast_return_type< ParametrizedLine, ParametrizedLine< NewScalarType, AmbientDimAtCompileTime, Options > >::type cast() const
EIGEN_DEVICE_FUNC VectorType intersectionPoint(const Hyperplane< _Scalar, _AmbientDim, OtherOptions > &hyperplane) const
TFSIMD_FORCE_INLINE tfScalar dot(const Quaternion &q1, const Quaternion &q2)
EIGEN_DEVICE_FUNC Scalar intersection(const Hyperplane< _Scalar, _AmbientDim, OtherOptions > &hyperplane) const
EIGEN_DEVICE_FUNC VectorType projection(const VectorType &p) const
EIGEN_DEVICE_FUNC ParametrizedLine(const ParametrizedLine< Scalar, AmbientDimAtCompileTime, OtherOptions > &other)
EIGEN_DEVICE_FUNC const VectorType & origin() const
EIGEN_DEVICE_FUNC ParametrizedLine(Index _dim)
EIGEN_DEVICE_FUNC ConstNormalReturnType normal() const
Definition: Hyperplane.h:157
EIGEN_DEVICE_FUNC VectorType & direction()
NumTraits< Scalar >::Real RealScalar
static EIGEN_DEVICE_FUNC ParametrizedLine Through(const VectorType &p0, const VectorType &p1)
A parametrized line.
EIGEN_DEVICE_FUNC VectorType & origin()
#define EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(TYPE, SIZE)
Definition: StaticAssert.h:152
EIGEN_DEVICE_FUNC const Scalar & offset() const
Definition: Hyperplane.h:167


hebiros
Author(s): Xavier Artache , Matthew Tesch
autogenerated on Thu Sep 3 2020 04:08:31