0

Note: I'm probably doing something that isn't supposed to be & my eigen knowledge is pretty limited but couldn't find what I look for.

I'm currently using eigen to get the direction vector of a pointcloud line.

//Compute eigenvalues and eigenvectors:
        Eigen::SelfAdjointEigenSolver<Eigen::MatrixXf> eig(scatter);


        Eigen::MatrixXf eigvecs = eig.eigenvectors();

        //largest eigenvalue is yeild at its last column
        b->x = eigvecs(0, 2);
        b->y = eigvecs(1, 2);
        b->z = eigvecs(2, 2);

with "b" being a pointer on a structure defined as:

typedef struct
{
   double x;
   double y;
   double z;
}3d_point;

using this "scatter" input:

80.0156 5.29252  2.06179
5.29252 0.489233 0.214055
2.06179 0.214055 3.17522

eigein output b (which is the direction vector of the line) :

 b = (0.997452, 0.06653, 0.0268062)

I get that a direction vector with a norm equal to 1 is enough. But as I know the "global" start point of this line, I was hopping to use "b" to get the global end point, thus the length of that line.

Is there any way to get the not normed b-vector ?

================

Following the answer I'm currently at that point:

Eigen::Vector3d meanV ;
meanV << a->x, a->y, a->z; //a is a 3d_point struct
points.rowwise() -= meanV.transpose(); // with Eigen::MatrixXd points = Eigen::MatrixXd::Zero(700, 3);

and this obviously fails as dimension do not matches:

Eigen::VectorXd projected = eigvecs.col(2).transpose() * points;

What did I misunderstood in your answer?

A.albin
  • 274
  • 2
  • 15

1 Answers1

0

I guess scatter has been computed after centering the points wrt the mean m? Then you have a parametric line l(t)=m+t*b with t roughly ranging from -a to a with a=sqrt(eig.eigenvalues()(2)). You can easily reparametrize it so that t range in [0,1] if you like. If you want strict bounds, then you need to project the points onto this line:

VectorXf projected = eigvecs.col(2).transpose() * (points.colwise()-m);

and extract the min/max to then reparametrize your line accordingly.

ggael
  • 28,425
  • 2
  • 65
  • 71
  • I've a semantic problem due to the fact that English isn't my strength, could you provide more details about the logic path to an eigen and maths neophyte? (You are right about the origin of scatter); – A.albin Aug 19 '18 at 16:30
  • 1) I've no idea of what "points" is supposed to be. 2) if points is my matrixNx3 of 3dpoints then dimension do not matches for the *operator. 3) if points is a Nx3 matrix dimension do not matches for minus operator – A.albin Aug 20 '18 at 07:41
  • In my example, `points` is `3xN`, if you stored them row-wise, just take the transpose. – ggael Aug 21 '18 at 21:20