42 #include <pcl/console/print.h>
50 const Eigen::VectorXf &line_b,
51 Eigen::Vector4f &point,
double sqr_eps)
53 Eigen::Vector4f p1, p2;
57 double sqr_dist = (p1 - p2).squaredNorm ();
58 if (sqr_dist < sqr_eps)
71 Eigen::Vector4f &point,
double sqr_eps)
73 Eigen::VectorXf coeff1 = Eigen::VectorXf::Map (line_a.
values.data(), line_a.
values.size ());
74 Eigen::VectorXf coeff2 = Eigen::VectorXf::Map (line_b.
values.data(), line_b.
values.size ());
78 template <
typename Scalar>
bool
80 const Eigen::Matrix<Scalar, 4, 1> &plane_b,
81 Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &line,
82 double angular_tolerance)
84 using Vector3 = Eigen::Matrix<Scalar, 3, 1>;
85 using Vector4 = Eigen::Matrix<Scalar, 4, 1>;
86 using Vector5 = Eigen::Matrix<Scalar, 5, 1>;
87 using Matrix5 = Eigen::Matrix<Scalar, 5, 5>;
90 Vector3 plane_a_norm (plane_a.template head<3> ());
91 Vector3 plane_b_norm (plane_b.template head<3> ());
92 plane_a_norm.normalize ();
93 plane_b_norm.normalize ();
96 double test_cos = plane_a_norm.dot (plane_b_norm);
97 double tolerance_cos = 1 - sin (std::abs (angular_tolerance));
99 if (std::abs (test_cos) > tolerance_cos)
101 PCL_DEBUG (
"Plane A and Plane B are parallel.\n");
105 Vector4 line_direction = plane_a.cross3 (plane_b);
106 line_direction.normalized();
109 Matrix5 langrange_coefs;
110 langrange_coefs << 2,0,0, plane_a[0], plane_b[0],
111 0,2,0, plane_a[1], plane_b[1],
112 0,0,2, plane_a[2], plane_b[2],
113 plane_a[0], plane_a[1], plane_a[2], 0, 0,
114 plane_b[0], plane_b[1], plane_b[2], 0, 0;
117 b << 0, 0, 0, -plane_a[3], -plane_b[3];
121 line.template head<3>() = langrange_coefs.colPivHouseholderQr().solve(b).template head<3> ();
122 line.template tail<3>() = line_direction.template head<3>();
126 template <
typename Scalar>
bool
128 const Eigen::Matrix<Scalar, 4, 1> &plane_b,
129 const Eigen::Matrix<Scalar, 4, 1> &plane_c,
130 Eigen::Matrix<Scalar, 3, 1> &intersection_point,
131 double determinant_tolerance)
133 using Vector3 = Eigen::Matrix<Scalar, 3, 1>;
134 using Matrix3 = Eigen::Matrix<Scalar, 3, 3>;
138 Matrix3 normals_in_lines;
140 for (
int i = 0; i < 3; i++)
142 normals_in_lines (i, 0) = plane_a[i];
143 normals_in_lines (i, 1) = plane_b[i];
144 normals_in_lines (i, 2) = plane_c[i];
147 Scalar determinant = normals_in_lines.determinant ();
148 if (std::abs (determinant) < determinant_tolerance)
151 PCL_DEBUG (
"At least two planes are parallel.\n");
158 for (
int i = 0; i < 3; i++)
160 left_member (0, i) = plane_a[i];
161 left_member (1, i) = plane_b[i];
162 left_member (2, i) = plane_c[i];
166 Vector3 right_member;
167 right_member << -plane_a[3], -plane_b[3], -plane_c[3];
170 intersection_point = left_member.fullPivLu ().solve (right_member);
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.
PCL_EXPORTS void lineToLineSegment(const Eigen::VectorXf &line_a, const Eigen::VectorXf &line_b, Eigen::Vector4f &pt1_seg, Eigen::Vector4f &pt2_seg)
Get the shortest 3D segment between two 3D lines.
Define line with line intersection functions.
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.
Defines all the PCL and non-PCL macros used.
std::vector< float > values