Eigen  5.0.1-dev+master
 
Loading...
Searching...
No Matches
ParametrizedLine.h
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// SPDX-License-Identifier: MPL-2.0
11
12#ifndef EIGEN_PARAMETRIZEDLINE_H
13#define EIGEN_PARAMETRIZEDLINE_H
14
15// IWYU pragma: private
16#include "./InternalHeaderCheck.h"
17
18namespace Eigen {
19
35template <typename Scalar_, int AmbientDim_, int Options_>
37 public:
38 EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF_VECTORIZABLE_FIXED_SIZE(Scalar_, AmbientDim_)
39 enum { AmbientDimAtCompileTime = AmbientDim_, Options = Options_ };
40 using Scalar = Scalar_;
41 using RealScalar = typename NumTraits<Scalar>::Real;
42 using Index = Eigen::Index;
44
46 EIGEN_DEVICE_FUNC inline ParametrizedLine() {}
47
48 template <int OtherOptions>
50 : m_origin(other.origin()), m_direction(other.direction()) {}
51
54 EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(Index _dim) : m_origin(_dim), m_direction(_dim) {}
55
60 EIGEN_DEVICE_FUNC ParametrizedLine(const VectorType& origin, const VectorType& direction)
61 : m_origin(origin), m_direction(direction) {}
62
63 template <int OtherOptions>
64 EIGEN_DEVICE_FUNC explicit ParametrizedLine(const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane);
65
67 EIGEN_DEVICE_FUNC static inline ParametrizedLine Through(const VectorType& p0, const VectorType& p1) {
68 return ParametrizedLine(p0, (p1 - p0).normalized());
69 }
70
72 EIGEN_DEVICE_FUNC inline Index dim() const { return m_direction.size(); }
73
74 EIGEN_DEVICE_FUNC const VectorType& origin() const { return m_origin; }
75 EIGEN_DEVICE_FUNC VectorType& origin() { return m_origin; }
76
77 EIGEN_DEVICE_FUNC const VectorType& direction() const { return m_direction; }
78 EIGEN_DEVICE_FUNC VectorType& direction() { return m_direction; }
79
83 EIGEN_DEVICE_FUNC RealScalar squaredDistance(const VectorType& p) const {
84 VectorType diff = p - origin();
85 return (diff - direction().dot(diff) * direction()).squaredNorm();
86 }
87
90 EIGEN_DEVICE_FUNC RealScalar distance(const VectorType& p) const { return numext::sqrt(squaredDistance(p)); }
91
93 EIGEN_DEVICE_FUNC VectorType projection(const VectorType& p) const {
94 return origin() + direction().dot(p - origin()) * direction();
95 }
96
97 EIGEN_DEVICE_FUNC VectorType pointAt(const Scalar& t) const;
98
99 template <int OtherOptions>
100 EIGEN_DEVICE_FUNC Scalar
101 intersectionParameter(const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const;
102
103 template <int OtherOptions>
104 EIGEN_DEVICE_FUNC Scalar intersection(const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const;
105
106 template <int OtherOptions>
107 EIGEN_DEVICE_FUNC VectorType
109
116 template <typename XprType>
117 EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const MatrixBase<XprType>& mat,
118 TransformTraits traits = Affine) {
119 if (traits == Affine)
120 direction() = (mat * direction()).normalized();
121 else if (traits == Isometry)
122 direction() = mat * direction();
123 else {
124 eigen_assert(0 && "invalid traits value in ParametrizedLine::transform()");
125 }
126 origin() = mat * origin();
127 return *this;
128 }
129
137 template <int TrOptions>
138 EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(
140 transform(t.linear(), traits);
141 origin() += t.translation();
142 return *this;
143 }
144
150 template <typename NewScalarType>
151 EIGEN_DEVICE_FUNC inline
152 typename internal::cast_return_type<ParametrizedLine,
154 cast() const {
155 return typename internal::cast_return_type<
157 }
158
160 template <typename OtherScalarType, int OtherOptions>
161 EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(
163 m_origin = other.origin().template cast<Scalar>();
164 m_direction = other.direction().template cast<Scalar>();
165 }
166
174 EIGEN_DEVICE_FUNC bool isApprox(const ParametrizedLine& other, const typename NumTraits<Scalar>::Real& prec =
175 NumTraits<Scalar>::dummy_precision()) const {
176 return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec);
177 }
178
179 protected:
180 VectorType m_origin, m_direction;
181};
182
187template <typename Scalar_, int AmbientDim_, int Options_>
188template <int OtherOptions>
191 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
192 direction() = hyperplane.normal().unitOrthogonal();
193 origin() = -hyperplane.normal() * hyperplane.offset();
194}
195
198template <typename Scalar_, int AmbientDim_, int Options_>
199EIGEN_DEVICE_FUNC inline typename ParametrizedLine<Scalar_, AmbientDim_, Options_>::VectorType
201 return origin() + direction() * t;
202}
203
206template <typename Scalar_, int AmbientDim_, int Options_>
207template <int OtherOptions>
208EIGEN_DEVICE_FUNC inline Scalar_ ParametrizedLine<Scalar_, AmbientDim_, Options_>::intersectionParameter(
209 const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const {
210 return -(hyperplane.offset() + hyperplane.normal().dot(origin())) / hyperplane.normal().dot(direction());
211}
212
216template <typename Scalar_, int AmbientDim_, int Options_>
217template <int OtherOptions>
218EIGEN_DEVICE_FUNC inline Scalar_ ParametrizedLine<Scalar_, AmbientDim_, Options_>::intersection(
219 const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const {
220 return intersectionParameter(hyperplane);
221}
222
225template <typename Scalar_, int AmbientDim_, int Options_>
226template <int OtherOptions>
227EIGEN_DEVICE_FUNC inline typename ParametrizedLine<Scalar_, AmbientDim_, Options_>::VectorType
229 const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const {
230 return pointAt(intersectionParameter(hyperplane));
231}
232
233} // end namespace Eigen
234
235#endif // EIGEN_PARAMETRIZEDLINE_H
A hyperplane.
Definition Hyperplane.h:38
ConstNormalReturnType normal() const
Definition Hyperplane.h:147
const Scalar & offset() const
Definition Hyperplane.h:159
Base class for all dense matrices, vectors, and expressions.
Definition MatrixBase.h:53
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:188
A parametrized line.
Definition ParametrizedLine.h:36
Eigen::Index Index
Definition ParametrizedLine.h:42
ParametrizedLine & transform(const Transform< Scalar, AmbientDimAtCompileTime, Affine, TrOptions > &t, TransformTraits traits=Affine)
Definition ParametrizedLine.h:138
ParametrizedLine & transform(const MatrixBase< XprType > &mat, TransformTraits traits=Affine)
Definition ParametrizedLine.h:117
RealScalar squaredDistance(const VectorType &p) const
Definition ParametrizedLine.h:83
RealScalar distance(const VectorType &p) const
Definition ParametrizedLine.h:90
VectorType intersectionPoint(const Hyperplane< Scalar_, AmbientDim_, OtherOptions > &hyperplane) const
Definition ParametrizedLine.h:228
internal::cast_return_type< ParametrizedLine, ParametrizedLine< NewScalarType, AmbientDimAtCompileTime, Options > >::type cast() const
Definition ParametrizedLine.h:154
ParametrizedLine(const VectorType &origin, const VectorType &direction)
Definition ParametrizedLine.h:60
ParametrizedLine(Index _dim)
Definition ParametrizedLine.h:54
bool isApprox(const ParametrizedLine &other, const typename NumTraits< Scalar >::Real &prec=NumTraits< Scalar >::dummy_precision()) const
Definition ParametrizedLine.h:174
VectorType pointAt(const Scalar &t) const
Definition ParametrizedLine.h:200
ParametrizedLine()
Definition ParametrizedLine.h:46
static ParametrizedLine Through(const VectorType &p0, const VectorType &p1)
Definition ParametrizedLine.h:67
Index dim() const
Definition ParametrizedLine.h:72
ParametrizedLine(const ParametrizedLine< OtherScalarType, AmbientDimAtCompileTime, OtherOptions > &other)
Definition ParametrizedLine.h:161
VectorType projection(const VectorType &p) const
Definition ParametrizedLine.h:93
Represents an homogeneous transformation in a N dimensional space.
Definition Transform.h:222
ConstLinearPart linear() const
Definition Transform.h:418
ConstTranslationPart translation() const
Definition Transform.h:428
TransformTraits
Definition Constants.h:470
@ Affine
Definition Constants.h:475
@ Isometry
Definition Constants.h:472