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
00040 bool
00041 pcl::lineWithLineIntersection (const Eigen::VectorXf &line_a,
00042 const Eigen::VectorXf &line_b,
00043 Eigen::Vector4f &point, double sqr_eps)
00044 {
00045 Eigen::Vector4f p1, p2;
00046 lineToLineSegment (line_a, line_b, p1, p2);
00047
00048
00049 double sqr_dist = (p1 - p2).squaredNorm ();
00050 if (sqr_dist < sqr_eps)
00051 {
00052 point = p1;
00053 return (true);
00054 }
00055 point.setZero ();
00056 return (false);
00057 }
00058
00059 bool
00060 pcl::lineWithLineIntersection (const pcl::ModelCoefficients &line_a,
00061 const pcl::ModelCoefficients &line_b,
00062 Eigen::Vector4f &point, double sqr_eps)
00063 {
00064 Eigen::VectorXf coeff1 = Eigen::VectorXf::Map (&line_a.values[0], line_a.values.size ());
00065 Eigen::VectorXf coeff2 = Eigen::VectorXf::Map (&line_b.values[0], line_b.values.size ());
00066 return (lineWithLineIntersection (coeff1, coeff2, point, sqr_eps));
00067 }
00068
00069 bool
00070 pcl::planeWithPlaneIntersection (const Eigen::Vector4f &plane_a,
00071 const Eigen::Vector4f &plane_b,
00072 Eigen::VectorXf &line,
00073 double angular_tolerance)
00074 {
00075
00076 double test_cosine = plane_a.head<3>().dot(plane_b.head<3>());
00077 double upper_limit = 1 + angular_tolerance;
00078 double lower_limit = 1 - angular_tolerance;
00079
00080 if ((test_cosine < upper_limit) && (test_cosine > lower_limit))
00081 {
00082 PCL_ERROR ("Plane A and Plane B are Parallel");
00083 return (false);
00084 }
00085
00086 if ((test_cosine > -upper_limit) && (test_cosine < -lower_limit))
00087 {
00088 PCL_ERROR ("Plane A and Plane B are Parallel");
00089 return (false);
00090 }
00091
00092 Eigen::Vector4f line_direction = plane_a.cross3(plane_b);
00093 line_direction.normalized();
00094
00095
00096 Eigen::MatrixXf langegrange_coefs(5,5);
00097 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;
00098
00099 Eigen::VectorXf b;
00100 b.resize(5);
00101 b << 0, 0, 0, -plane_a[3], -plane_b[3];
00102
00103
00104 Eigen::VectorXf x;
00105 x.resize(5);
00106 x = langegrange_coefs.colPivHouseholderQr().solve(b);
00107
00108 line.resize(6);
00109 line.head<3>() = x.head<3>();
00110 line[3] = line_direction[0];
00111 line[4] = line_direction[1];
00112 line[5] = line_direction[2];
00113 return true;
00114 }