Eigen  5.0.1
 
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 {
91 EIGEN_USING_STD(sqrt) return sqrt(squaredDistance(p));
92 }
93
95 EIGEN_DEVICE_FUNC VectorType projection(const VectorType& p) const {
96 return origin() + direction().dot(p - origin()) * direction();
97 }
98
99 EIGEN_DEVICE_FUNC VectorType pointAt(const Scalar& t) const;
100
101 template <int OtherOptions>
102 EIGEN_DEVICE_FUNC Scalar
103 intersectionParameter(const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const;
104
105 template <int OtherOptions>
106 EIGEN_DEVICE_FUNC Scalar intersection(const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const;
107
108 template <int OtherOptions>
109 EIGEN_DEVICE_FUNC VectorType
111
118 template <typename XprType>
119 EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(const MatrixBase<XprType>& mat,
120 TransformTraits traits = Affine) {
121 if (traits == Affine)
122 direction() = (mat * direction()).normalized();
123 else if (traits == Isometry)
124 direction() = mat * direction();
125 else {
126 eigen_assert(0 && "invalid traits value in ParametrizedLine::transform()");
127 }
128 origin() = mat * origin();
129 return *this;
130 }
131
139 template <int TrOptions>
140 EIGEN_DEVICE_FUNC inline ParametrizedLine& transform(
142 transform(t.linear(), traits);
143 origin() += t.translation();
144 return *this;
145 }
146
152 template <typename NewScalarType>
153 EIGEN_DEVICE_FUNC inline
154 typename internal::cast_return_type<ParametrizedLine,
156 cast() const {
157 return typename internal::cast_return_type<
159 }
160
162 template <typename OtherScalarType, int OtherOptions>
163 EIGEN_DEVICE_FUNC inline explicit ParametrizedLine(
165 m_origin = other.origin().template cast<Scalar>();
166 m_direction = other.direction().template cast<Scalar>();
167 }
168
176 EIGEN_DEVICE_FUNC bool isApprox(const ParametrizedLine& other, const typename NumTraits<Scalar>::Real& prec =
177 NumTraits<Scalar>::dummy_precision()) const {
178 return m_origin.isApprox(other.m_origin, prec) && m_direction.isApprox(other.m_direction, prec);
179 }
180
181 protected:
182 VectorType m_origin, m_direction;
183};
184
189template <typename Scalar_, int AmbientDim_, int Options_>
190template <int OtherOptions>
193 EIGEN_STATIC_ASSERT_VECTOR_SPECIFIC_SIZE(VectorType, 2)
194 direction() = hyperplane.normal().unitOrthogonal();
195 origin() = -hyperplane.normal() * hyperplane.offset();
196}
197
200template <typename Scalar_, int AmbientDim_, int Options_>
201EIGEN_DEVICE_FUNC inline typename ParametrizedLine<Scalar_, AmbientDim_, Options_>::VectorType
203 return origin() + direction() * t;
204}
205
208template <typename Scalar_, int AmbientDim_, int Options_>
209template <int OtherOptions>
210EIGEN_DEVICE_FUNC inline Scalar_ ParametrizedLine<Scalar_, AmbientDim_, Options_>::intersectionParameter(
211 const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const {
212 return -(hyperplane.offset() + hyperplane.normal().dot(origin())) / hyperplane.normal().dot(direction());
213}
214
218template <typename Scalar_, int AmbientDim_, int Options_>
219template <int OtherOptions>
220EIGEN_DEVICE_FUNC inline Scalar_ ParametrizedLine<Scalar_, AmbientDim_, Options_>::intersection(
221 const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const {
222 return intersectionParameter(hyperplane);
223}
224
227template <typename Scalar_, int AmbientDim_, int Options_>
228template <int OtherOptions>
229EIGEN_DEVICE_FUNC inline typename ParametrizedLine<Scalar_, AmbientDim_, Options_>::VectorType
231 const Hyperplane<Scalar_, AmbientDim_, OtherOptions>& hyperplane) const {
232 return pointAt(intersectionParameter(hyperplane));
233}
234
235} // end namespace Eigen
236
237#endif // EIGEN_PARAMETRIZEDLINE_H
A hyperplane.
Definition Hyperplane.h:38
ConstNormalReturnType normal() const
Definition Hyperplane.h:146
const Scalar & offset() const
Definition Hyperplane.h:158
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:140
ParametrizedLine & transform(const MatrixBase< XprType > &mat, TransformTraits traits=Affine)
Definition ParametrizedLine.h:119
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:230
internal::cast_return_type< ParametrizedLine, ParametrizedLine< NewScalarType, AmbientDimAtCompileTime, Options > >::type cast() const
Definition ParametrizedLine.h:156
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:176
VectorType pointAt(const Scalar &t) const
Definition ParametrizedLine.h:202
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:163
VectorType projection(const VectorType &p) const
Definition ParametrizedLine.h:95
Represents an homogeneous transformation in a N dimensional space.
Definition Transform.h:222
ConstLinearPart linear() const
Definition Transform.h:415
ConstTranslationPart translation() const
Definition Transform.h:425
TransformTraits
Definition Constants.h:470
@ Affine
Definition Constants.h:475
@ Isometry
Definition Constants.h:472