This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Hyperplane Through method not working in some cases

Tags: None
(comma "," separated)
jgordon
Registered Member
Posts
2
Karma
0
Hi,

I am try to use the Hyperplane and ParametrizedLine classes to calculate the point at which a line intersects a plane.

I am using the "Through" static methods to construct both the plane and line.

The "Through" method seems to fail (i.e. the plane coefficients have strange values) in some cases depending on the three points I pass to it. The following code and output demonstrates this.

Note that I am using version 3.0.5 of Eigen (due to wanting to use it with a particular version of the PCL library).

I am new to the Eigen library so hope I am not using the library incorrectly?

Code: Select all
   Eigen::Vector3f p1_ok( 1, 1, 3 );
   Eigen::Vector3f p2_ok( 2, 1, 3 );
   Eigen::Vector3f p3_ok( 1, 0, 3 );
   Eigen::Hyperplane<float,3> plane_ok = Eigen::Hyperplane<float,3>::Through( p1_ok, p2_ok, p3_ok );
   std::cout << "plane_ok coefficients  : " << plane_ok.coeffs()[0] << ", " << plane_ok.coeffs()[1] << ", " << plane_ok.coeffs()[2] << ", " << plane_ok.coeffs()[3] << std::endl;

   Eigen::Vector3f p1_bad( 1, 1, 3 );
   Eigen::Vector3f p2_bad( 2, 1, 3 );
   Eigen::Vector3f p3_bad( 0, 1, 3 );
   Eigen::Hyperplane<float,3> plane_bad = Eigen::Hyperplane<float,3>::Through( p1_bad, p2_bad, p3_bad );
   std::cout << "plane_bad coefficients : " << plane_bad.coeffs()[0] << ", " << plane_bad.coeffs()[1] << ", " << plane_bad.coeffs()[2] << ", " << plane_bad.coeffs()[3] << std::endl;

   Eigen::Vector3f p4( 0, 0, 0 );
   Eigen::Vector3f p5( 0, 0, 1 );
   Eigen::ParametrizedLine<float,3> pline = Eigen::ParametrizedLine<float,3>::Through( p4, p5 );

   // Using Eigen version 3.0.5 (used by PCL version 1.6.0) so can't use ParmetriziedLine.pointAt() method.
   Eigen::Vector3f p_int;
   float t = pline.intersection( plane_ok );
   p_int = p4 + (pline.direction()*t);
   std::cout << "Point of intersection with plane_ok  : (" << p_int.x() << ", " << p_int.y() << ", " << p_int.z() << " )" << std::endl;

   t = pline.intersection( plane_bad );
   p_int = p4 + (pline.direction()*t);
   std::cout << "Point of intersection with plane_bad : (" << p_int.x() << ", " << p_int.y() << ", " << p_int.z() << " )" << std::endl;


Output :
plane_ok coefficients : -0, 0, 1, -3
plane_bad coefficients : -1.#IND, -1.#IND, -1.#IND, 1.#QNAN
Point of intersection with plane_ok : (0, 0, 3 )
Point of intersection with plane_bad : (-1.#IND, -1.#IND, -1.#IND )


Thanks in advance,
Joel Gordon.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Indeed, the current code does not seem to handle the degenerate case where the three points are aligned. Among the infinite number of solutions, the method might pick one instead of returning NaN.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Fixed in devel and 3.2 branches:
https://bitbucket.org/eigen/eigen/commits/d9af749994e1/
https://bitbucket.org/eigen/eigen/commits/7aa6b68a6f2a/

Feel free to upgrade to the latest 3.2, I guess that the 3.0.5 advice of PCL is a minimum only.
jgordon
Registered Member
Posts
2
Karma
0
Thanks very much for the prompt reply and quick fix.

It now works fine.

Regards,
Joel Gordon.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]