Point Cloud Library (PCL)  1.14.1-dev
intersections.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2010, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder(s) nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *
34  * $Id$
35  *
36  */
37 
38 #pragma once
39 
40 #include <pcl/ModelCoefficients.h>
41 #include <pcl/common/common.h>
42 #include <pcl/common/distances.h>
43 
44 /**
45  * \file pcl/common/intersections.h
46  * Define line with line intersection functions
47  * \ingroup common
48  */
49 
50 /*@{*/
51 namespace pcl
52 {
53  /** \brief Get the intersection of a two 3D lines in space as a 3D point
54  * \param[in] line_a the coefficients of the first line (point, direction)
55  * \param[in] line_b the coefficients of the second line (point, direction)
56  * \param[out] point holder for the computed 3D point
57  * \param[in] sqr_eps maximum allowable squared distance to the true solution
58  * \ingroup common
59  */
60  PCL_EXPORTS inline bool
61  lineWithLineIntersection (const Eigen::VectorXf &line_a,
62  const Eigen::VectorXf &line_b,
63  Eigen::Vector4f &point,
64  double sqr_eps = 1e-4);
65 
66  /** \brief Get the intersection of a two 3D lines in space as a 3D point
67  * \param[in] line_a the coefficients of the first line (point, direction)
68  * \param[in] line_b the coefficients of the second line (point, direction)
69  * \param[out] point holder for the computed 3D point
70  * \param[in] sqr_eps maximum allowable squared distance to the true solution
71  * \ingroup common
72  */
73 
74  PCL_EXPORTS inline bool
76  const pcl::ModelCoefficients &line_b,
77  Eigen::Vector4f &point,
78  double sqr_eps = 1e-4);
79 
80  /** \brief Determine the line of intersection of two non-parallel planes using lagrange multipliers
81  * \note Described in: "Intersection of Two Planes, John Krumm, Microsoft Research, Redmond, WA, USA"
82  * \param[in] plane_a coefficients of plane A and plane B in the form ax + by + cz + d = 0
83  * \param[in] plane_b coefficients of line where line.tail<3>() = direction vector and
84  * line.head<3>() the point on the line closest to (0, 0, 0)
85  * \param[out] line the intersected line to be filled
86  * \param[in] angular_tolerance tolerance in radians
87  * \return true if succeeded/planes aren't parallel
88  */
89  template <typename Scalar> bool
90  planeWithPlaneIntersection (const Eigen::Matrix<Scalar, 4, 1> &plane_a,
91  const Eigen::Matrix<Scalar, 4, 1> &plane_b,
92  Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &line,
93  double angular_tolerance = 0.1);
94 
95  inline bool
96  planeWithPlaneIntersection (const Eigen::Vector4f &plane_a,
97  const Eigen::Vector4f &plane_b,
98  Eigen::VectorXf &line,
99  double angular_tolerance = 0.1)
100  {
101  return (planeWithPlaneIntersection<float> (plane_a, plane_b, line, angular_tolerance));
102  }
103 
104  inline bool
105  planeWithPlaneIntersection (const Eigen::Vector4d &plane_a,
106  const Eigen::Vector4d &plane_b,
107  Eigen::VectorXd &line,
108  double angular_tolerance = 0.1)
109  {
110  return (planeWithPlaneIntersection<double> (plane_a, plane_b, line, angular_tolerance));
111  }
112 
113  /** \brief Determine the point of intersection of three non-parallel planes by solving the equations.
114  * \note If using nearly parallel planes you can lower the determinant_tolerance value. This can
115  * lead to inconsistent results.
116  * If the three planes intersects in a line the point will be anywhere on the line.
117  * \param[in] plane_a are the coefficients of the first plane in the form ax + by + cz + d = 0
118  * \param[in] plane_b are the coefficients of the second plane
119  * \param[in] plane_c are the coefficients of the third plane
120  * \param[in] determinant_tolerance is a limit to determine whether planes are parallel or not
121  * \param[out] intersection_point the three coordinates x, y, z of the intersection point
122  * \return true if succeeded/planes aren't parallel
123  */
124  template <typename Scalar> bool
125  threePlanesIntersection (const Eigen::Matrix<Scalar, 4, 1> &plane_a,
126  const Eigen::Matrix<Scalar, 4, 1> &plane_b,
127  const Eigen::Matrix<Scalar, 4, 1> &plane_c,
128  Eigen::Matrix<Scalar, 3, 1> &intersection_point,
129  double determinant_tolerance = 1e-6);
130 
131 
132  inline bool
133  threePlanesIntersection (const Eigen::Vector4f &plane_a,
134  const Eigen::Vector4f &plane_b,
135  const Eigen::Vector4f &plane_c,
136  Eigen::Vector3f &intersection_point,
137  double determinant_tolerance = 1e-6)
138  {
139  return (threePlanesIntersection<float> (plane_a, plane_b, plane_c,
140  intersection_point, determinant_tolerance));
141  }
142 
143  inline bool
144  threePlanesIntersection (const Eigen::Vector4d &plane_a,
145  const Eigen::Vector4d &plane_b,
146  const Eigen::Vector4d &plane_c,
147  Eigen::Vector3d &intersection_point,
148  double determinant_tolerance = 1e-6)
149  {
150  return (threePlanesIntersection<double> (plane_a, plane_b, plane_c,
151  intersection_point, determinant_tolerance));
152  }
153 
154 }
155 /*@}*/
156 
157 #include <pcl/common/impl/intersections.hpp>
Define standard C methods and C++ classes that are common to all methods.
Define standard C methods to do distance calculations.
bool lineWithLineIntersection(const Eigen::VectorXf &line_a, const Eigen::VectorXf &line_b, Eigen::Vector4f &point, double sqr_eps)
Get the intersection of a two 3D lines in space as a 3D point.
bool planeWithPlaneIntersection(const Eigen::Matrix< Scalar, 4, 1 > &plane_a, const Eigen::Matrix< Scalar, 4, 1 > &plane_b, Eigen::Matrix< Scalar, Eigen::Dynamic, 1 > &line, double angular_tolerance)
Determine the line of intersection of two non-parallel planes using lagrange multipliers.
bool threePlanesIntersection(const Eigen::Matrix< Scalar, 4, 1 > &plane_a, const Eigen::Matrix< Scalar, 4, 1 > &plane_b, const Eigen::Matrix< Scalar, 4, 1 > &plane_c, Eigen::Matrix< Scalar, 3, 1 > &intersection_point, double determinant_tolerance)
Determine the point of intersection of three non-parallel planes by solving the equations.
#define PCL_EXPORTS
Definition: pcl_macros.h:325