eigen_line.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, ATR, Atsushi Watanabe
3  * Copyright (c) 2014-2018, the neonavigation authors
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * * Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef TRAJECTORY_TRACKER_EIGEN_LINE_H
32 #define TRAJECTORY_TRACKER_EIGEN_LINE_H
33 
34 #include <cmath>
35 
36 #include <Eigen/Core>
37 
38 namespace trajectory_tracker
39 {
40 inline float curv3p(
41  const Eigen::Vector2d& a,
42  const Eigen::Vector2d& b,
43  const Eigen::Vector2d& c)
44 {
45  float ret;
46  ret = 2 * (a[0] * b[1] + b[0] * c[1] + c[0] * a[1] -
47  a[0] * c[1] - b[0] * a[1] - c[0] * b[1]);
48  ret /= std::sqrt((b - a).squaredNorm() * (b - c).squaredNorm() * (c - a).squaredNorm());
49 
50  return ret;
51 }
52 
53 inline float cross2(const Eigen::Vector2d& a, const Eigen::Vector2d& b)
54 {
55  return a[0] * b[1] - a[1] * b[0];
56 }
57 
58 inline float lineDistance(
59  const Eigen::Vector2d& a,
60  const Eigen::Vector2d& b,
61  const Eigen::Vector2d& c)
62 {
63  return cross2((b - a), (c - a)) / (b - a).norm();
64 }
65 
66 inline float lineStripDistance(
67  const Eigen::Vector2d& a,
68  const Eigen::Vector2d& b,
69  const Eigen::Vector2d& c)
70 {
71  if ((b - a).dot(c - a) <= 0)
72  return (c - a).norm();
73  if ((a - b).dot(c - b) <= 0)
74  return (c - b).norm() + 0.005;
75  return std::abs(lineDistance(a, b, c));
76 }
77 
78 inline Eigen::Vector2d projection2d(
79  const Eigen::Vector2d& a,
80  const Eigen::Vector2d& b,
81  const Eigen::Vector2d& c)
82 {
83  const float r = (b - a).dot(c - a) / (b - a).squaredNorm();
84  return b * r + a * (1.0 - r);
85 }
86 } // namespace trajectory_tracker
87 
88 #endif // TRAJECTORY_TRACKER_EIGEN_LINE_H
doubleAcc dot(const VectorAcc &lhs, const VectorAcc &rhs)
float cross2(const Eigen::Vector2d &a, const Eigen::Vector2d &b)
Definition: eigen_line.h:53
float lineDistance(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
Definition: eigen_line.h:58
float curv3p(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
Definition: eigen_line.h:40
Eigen::Vector2d projection2d(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
Definition: eigen_line.h:78
float lineStripDistance(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
Definition: eigen_line.h:66


trajectory_tracker
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:09