I'm trying to construct a plane out of three points in 3D. I want to use projective geometry to achieve this.
As far as I know, one can "simply" solve the following to find a plane:
A * x = 0 ,where
A is a 3x4 Matrix - each row being one of the points (x,y,z,1)
x is the plane I want to find
I know that I need to have a constrain. Therefore I want to set x(3) = 1
.
Can someone please point me to the right method to use?
So far I have the following code:
Eigen::Vector4f p1(0,0,1,1);
Eigen::Vector4f p2(1,0,0,1);
Eigen::Vector4f p3(0,1,0,1);
Eigen::Matrix<float,3,4> A;
A << p1.transpose(), p2.transpose(), p3.transpose();
// Throws compile error
// Eigen::Vector4f Plane = A.jacobiSvd(ComputeThinU | ComputeThinV).solve(Vector4f::Zero());
//throws runtime error (row-number do not match)
// Eigen::Vector4f Plane = A.fullPivHouseholderQr().solce(Eigen::Vector4f::Zero());
A 3x4 matrix multiplied by a 4 row vector will give you a 3 row vector. Thus you have to solve for a Vector3f::Zero()
. Also, for fixed size matrices you need to compute the full U and V. The final line looks like this:
Vector4f Plane = A.jacobiSvd(ComputeFullU | ComputeFullV).solve(Vector3f::Zero());
Eidt Since this equation system is not fully defined, it might give you the trivial solution of (0,0,0,0). You can solve that by constraining the length of the resulting vector by expanding the matrix to a 4x4, solving for (0,0,0,1) and scaling the result by x(3):
Eigen::Vector4f p1(0,0,1,1);
Eigen::Vector4f p2(1,0,0,1);
Eigen::Vector4f p3(0,1,0,1);
Eigen::Vector4f p4(1,1,1,1);
Eigen::Matrix<float,4,4> A;
A << p1.transpose(), p2.transpose(), p3.transpose(), p4.transpose();
// Throws compile error
Eigen::Vector4f Plane = A.jacobiSvd(Eigen::ComputeFullU | Eigen::ComputeFullV).solve(Vector4f::Unit(3));
Plane /= Plane(3);
This will give you the desired solution of (-1, -1, -1, 1).