Go to the documentation of this file.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 #include "main.h"
00027 #include <Eigen/Geometry>
00028 #include <Eigen/LU>
00029 #include <Eigen/QR>
00030
00031 template<typename HyperplaneType> void hyperplane(const HyperplaneType& _plane)
00032 {
00033
00034
00035
00036
00037 const int dim = _plane.dim();
00038 typedef typename HyperplaneType::Scalar Scalar;
00039 typedef typename NumTraits<Scalar>::Real RealScalar;
00040 typedef Matrix<Scalar, HyperplaneType::AmbientDimAtCompileTime, 1> VectorType;
00041 typedef Matrix<Scalar, HyperplaneType::AmbientDimAtCompileTime,
00042 HyperplaneType::AmbientDimAtCompileTime> MatrixType;
00043
00044 VectorType p0 = VectorType::Random(dim);
00045 VectorType p1 = VectorType::Random(dim);
00046
00047 VectorType n0 = VectorType::Random(dim).normalized();
00048 VectorType n1 = VectorType::Random(dim).normalized();
00049
00050 HyperplaneType pl0(n0, p0);
00051 HyperplaneType pl1(n1, p1);
00052 HyperplaneType pl2 = pl1;
00053
00054 Scalar s0 = ei_random<Scalar>();
00055 Scalar s1 = ei_random<Scalar>();
00056
00057 VERIFY_IS_APPROX( n1.eigen2_dot(n1), Scalar(1) );
00058
00059 VERIFY_IS_MUCH_SMALLER_THAN( pl0.absDistance(p0), Scalar(1) );
00060 VERIFY_IS_APPROX( pl1.signedDistance(p1 + n1 * s0), s0 );
00061 VERIFY_IS_MUCH_SMALLER_THAN( pl1.signedDistance(pl1.projection(p0)), Scalar(1) );
00062 VERIFY_IS_MUCH_SMALLER_THAN( pl1.absDistance(p1 + pl1.normal().unitOrthogonal() * s1), Scalar(1) );
00063
00064
00065 if (!NumTraits<Scalar>::IsComplex)
00066 {
00067 MatrixType rot = MatrixType::Random(dim,dim).qr().matrixQ();
00068 Scaling<Scalar,HyperplaneType::AmbientDimAtCompileTime> scaling(VectorType::Random());
00069 Translation<Scalar,HyperplaneType::AmbientDimAtCompileTime> translation(VectorType::Random());
00070
00071 pl2 = pl1;
00072 VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot).absDistance(rot * p1), Scalar(1) );
00073 pl2 = pl1;
00074 VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot,Isometry).absDistance(rot * p1), Scalar(1) );
00075 pl2 = pl1;
00076 VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot*scaling).absDistance((rot*scaling) * p1), Scalar(1) );
00077 pl2 = pl1;
00078 VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot*scaling*translation)
00079 .absDistance((rot*scaling*translation) * p1), Scalar(1) );
00080 pl2 = pl1;
00081 VERIFY_IS_MUCH_SMALLER_THAN( pl2.transform(rot*translation,Isometry)
00082 .absDistance((rot*translation) * p1), Scalar(1) );
00083 }
00084
00085
00086 const int Dim = HyperplaneType::AmbientDimAtCompileTime;
00087 typedef typename GetDifferentType<Scalar>::type OtherScalar;
00088 Hyperplane<OtherScalar,Dim> hp1f = pl1.template cast<OtherScalar>();
00089 VERIFY_IS_APPROX(hp1f.template cast<Scalar>(),pl1);
00090 Hyperplane<Scalar,Dim> hp1d = pl1.template cast<Scalar>();
00091 VERIFY_IS_APPROX(hp1d.template cast<Scalar>(),pl1);
00092 }
00093
00094 template<typename Scalar> void lines()
00095 {
00096 typedef Hyperplane<Scalar, 2> HLine;
00097 typedef ParametrizedLine<Scalar, 2> PLine;
00098 typedef Matrix<Scalar,2,1> Vector;
00099 typedef Matrix<Scalar,3,1> CoeffsType;
00100
00101 for(int i = 0; i < 10; i++)
00102 {
00103 Vector center = Vector::Random();
00104 Vector u = Vector::Random();
00105 Vector v = Vector::Random();
00106 Scalar a = ei_random<Scalar>();
00107 while (ei_abs(a-1) < 1e-4) a = ei_random<Scalar>();
00108 while (u.norm() < 1e-4) u = Vector::Random();
00109 while (v.norm() < 1e-4) v = Vector::Random();
00110
00111 HLine line_u = HLine::Through(center + u, center + a*u);
00112 HLine line_v = HLine::Through(center + v, center + a*v);
00113
00114
00115 VERIFY_IS_APPROX(line_u.normal().norm(), Scalar(1));
00116 VERIFY_IS_APPROX(line_v.normal().norm(), Scalar(1));
00117
00118 Vector result = line_u.intersection(line_v);
00119
00120
00121 VERIFY_IS_APPROX(result, center);
00122
00123
00124 PLine pl(line_u);
00125 CoeffsType converted_coeffs(HLine(pl).coeffs());
00126 converted_coeffs *= line_u.coeffs()(0)/converted_coeffs(0);
00127 VERIFY(line_u.coeffs().isApprox(converted_coeffs));
00128 }
00129 }
00130
00131 void test_eigen2_hyperplane()
00132 {
00133 for(int i = 0; i < g_repeat; i++) {
00134 CALL_SUBTEST_1( hyperplane(Hyperplane<float,2>()) );
00135 CALL_SUBTEST_2( hyperplane(Hyperplane<float,3>()) );
00136 CALL_SUBTEST_3( hyperplane(Hyperplane<double,4>()) );
00137 CALL_SUBTEST_4( hyperplane(Hyperplane<std::complex<double>,5>()) );
00138 CALL_SUBTEST_5( lines<float>() );
00139 CALL_SUBTEST_6( lines<double>() );
00140 }
00141 }