今天我开始接触eigen,发现以下方法可以获取交点:
#include <Eigen/Dense>
using namespace Eigen;
using namespace std;
int main() {
// Calc intersection of line ac with bd:
Vector2f a(8,2);
Vector2f b(9,5);
Vector2f c(6,6);
Vector2f d(5,9);
Matrix2f xx;
xx << c-a, b-d;
cout << "Here is the matrix xx:\n" << xx << endl;
Vector2f x = xx.colPivHouseholderQr().solve(b-a);
Vector2f intersect1( a + x(0)* ( c-a ) );
Vector2f intersect2( b + x(1)* ( d-b ) );
cout << "intersect1\n" << intersect1 << std::endl;
cout << "intersect2\n" << intersect2 << std::endl;
}
问:Eigen库中是否有一个函数可以直接给出交点的结果?我认为我在这里做了太多手工编码。