Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row wise cross product Eigen

Tags:

c++

eigen

I am trying to do cross product between every row of one Eigen::MatrixXd dir with corresponding row of Eigen::MatrixXd v0v2 and save the result in another Eigen::MatrixXd pvec.

Initialization of pvec : Eigen::MatrixXd pvec(v0v2.rows(), 3);

I have tried this dirty method:

for(size_t i = 0; i < v0v2.rows(); i++){ pvec.row(i) = dir.row(i).cross(v0v2.row(i)); }

I get this error : THIS_METHOD_IS_ONLY_FOR_VECTORS_OF_A_SPECIFIC_SIZE

I thought this would be because of column-major/row-major issue so I added .transpose() but that doesn't help either. I could always do a dirtier personal cross product element wise something like this:

Vec3 crossProduct(const Vec3<T> &v) const { return Vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); } but I would like to do an Eigen method. Any help would be great!

like image 634
Rick M. Avatar asked Jan 30 '26 07:01

Rick M.


1 Answers

The arguments of .cross must be known at compile-time to be of size 3. Try declaring your matrices as Eigen::Matrix<double, Eigen::Dynamic, 3> dir(N, 3);, etc.

like image 190
chtz Avatar answered Feb 01 '26 22:02

chtz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!