Registered Member
|
Hi,
there are two possibilities to store vectors that I'd like your opinion/advice on: (1) store them in std containers, e.g.
(2) store them in a matrix, e.g.
Are there reasons to favor one over the other by means of speed, possible operations, ...? Best, Ben |
Moderator
|
Using a matrix as the advantage to allow you to work on the full set of 3D vectors at once, for instance to apply a rotation matrix:
Matrix3d rot; rotated_pts = rot * pts; or to compute the centroid: Vector3d c = pts.rowwise().mean(); etc. In this case, it is better to store them column-wise, so using a Matrix<double,3,Dynamic>. The std::vector approach implies loops but is more efficient at dynamically resizing the number of vectors. Note that you can also see a vector<Vector3d> as a Matrix<double,3,Dynamic> using Map:
In this case pts aliases vec_pts. |
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]