00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <pcl/common/intersections.h>
00039 #include <pcl/console/print.h>
00040
00041 bool
00042 pcl::lineWithLineIntersection (const Eigen::VectorXf &line_a,
00043 const Eigen::VectorXf &line_b,
00044 Eigen::Vector4f &point, double sqr_eps)
00045 {
00046 Eigen::Vector4f p1, p2;
00047 lineToLineSegment (line_a, line_b, p1, p2);
00048
00049
00050 double sqr_dist = (p1 - p2).squaredNorm ();
00051 if (sqr_dist < sqr_eps)
00052 {
00053 point = p1;
00054 return (true);
00055 }
00056 point.setZero ();
00057 return (false);
00058 }
00059
00060 bool
00061 pcl::lineWithLineIntersection (const pcl::ModelCoefficients &line_a,
00062 const pcl::ModelCoefficients &line_b,
00063 Eigen::Vector4f &point, double sqr_eps)
00064 {
00065 Eigen::VectorXf coeff1 = Eigen::VectorXf::Map (&line_a.values[0], line_a.values.size ());
00066 Eigen::VectorXf coeff2 = Eigen::VectorXf::Map (&line_b.values[0], line_b.values.size ());
00067 return (lineWithLineIntersection (coeff1, coeff2, point, sqr_eps));
00068 }
00069
00070 bool
00071 pcl::planeWithPlaneIntersection (const Eigen::Vector4f &plane_a,
00072 const Eigen::Vector4f &plane_b,
00073 Eigen::VectorXf &line,
00074 double angular_tolerance)
00075 {
00076
00077 double test_cosine = plane_a.head<3>().dot(plane_b.head<3>());
00078 double upper_limit = 1 + angular_tolerance;
00079 double lower_limit = 1 - angular_tolerance;
00080
00081 if ((test_cosine < upper_limit) && (test_cosine > lower_limit))
00082 {
00083 PCL_ERROR ("Plane A and Plane B are Parallel");
00084 return (false);
00085 }
00086
00087 if ((test_cosine > -upper_limit) && (test_cosine < -lower_limit))
00088 {
00089 PCL_ERROR ("Plane A and Plane B are Parallel");
00090 return (false);
00091 }
00092
00093 Eigen::Vector4f line_direction = plane_a.cross3(plane_b);
00094 line_direction.normalized();
00095
00096
00097 Eigen::MatrixXf langegrange_coefs(5,5);
00098 langegrange_coefs << 2,0,0,plane_a[0],plane_b[0], 0,2,0,plane_a[1],plane_b[1], 0,0,2, plane_a[2], plane_b[2], plane_a[0], plane_a[1] , plane_a[2], 0,0, plane_b[0], plane_b[1], plane_b[2], 0,0;
00099
00100 Eigen::VectorXf b;
00101 b.resize(5);
00102 b << 0, 0, 0, -plane_a[3], -plane_b[3];
00103
00104
00105 Eigen::VectorXf x;
00106 x.resize(5);
00107 x = langegrange_coefs.colPivHouseholderQr().solve(b);
00108
00109 line.resize(6);
00110 line.head<3>() = x.head<3>();
00111 line[3] = line_direction[0];
00112 line[4] = line_direction[1];
00113 line[5] = line_direction[2];
00114 return true;
00115 }