日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用eigen库进行空间变换

發布時間:2023/12/29 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用eigen库进行空间变换 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用eigen庫進行空間變換

在三維空間中,常常需要變換當前機器人的位姿計算定義的絕對坐標系和當前機器人所處相對坐標系之間的關系。而主要的變換則是平移和旋轉,有時候可能需要尺度變換,那么就可以描述為:

Transform<float,3,Affine> T = Translation3f(p) * AngleAxisf(a,axis) * Scaling(s);

Affine3d T是一個4*4齊次矩陣變換。

旋轉

Eigen::Quaternionf quater;

可以采用沿著某一個軸進行計算,

Eigen::AngleAxisd(M_PI/2.0,Eigen::Vector3d::UnitZ());

也可以直接給定參數

quater.x() = 0; quater.y() = 0; quater.z() = sin(M_PI/2.0 / 2.0); quater.w() = cos(M_PI/2.0 / 2.0);

平移

Eigen::Translation3f translation(x,y,z);

尺度縮放

Scaling(sx, sy) Scaling(sx, sy, sz) Scaling(s) Scaling(vecN)

仿射變換

//仿射變換矩陣 Eigen::Affine3f affine3f = translation*quater.toRotationMatrix();//求逆矩陣 affine3f = affine3f.inverse();

對三維點進行變換

//變換前的點 Eigen::Vector3f v3f_a(x_m, y_m, 0.0);//變換后的點 Eigen::Vector3f v3f_b = affine3f*v3f_a;

eigen空間變換詳細文檔,以便查找其他函數的使用方法。

有時候需要知道affine3f的四維矩陣Matrix4f,采用如下裝換

Eigen::Matrix4f a; Eigen::Affine3f b; b.matrix() = a;

Eigen庫使用教程

  • Multiplication:
Eigen::Matrix3d A = Eigen::Matrix3d::Identity();Eigen::Vector3d a(0.5, 3, -0.4);Eigen::Vector3d Aa = A * a;std::cout << "The multiplication of A * a is " << std::endl << Aa << std::endl;Eigen::MatrixXd B = Eigen::MatrixXd::Identity(6, 5);Eigen::VectorXd b(5);b << 1, 4, 6, -2, 0.4;Eigen::VectorXd Bb = B * b;std::cout << "The multiplication of B * b is " << std::endl << Bb << std::endl;
  • Transpose and inverse:
Eigen::MatrixXd A(3, 2);A << 1, 2,2, 3,3, 4;Eigen::MatrixXd B = A.transpose();// the transpose of A is a 2x3 matrixEigen::MatrixXd C = (B * A).inverse();// computer the inverse of BA, which is a 2x2 matrix
  • Dot product and cross product:
Eigen::Vector3d v(1, 2, 3);Eigen::Vector3d w(0, 1, 2);double vDotw = v.dot(w); // dot product of two vectorsEigen::Vector3d vCrossw = v.cross(w); // cross product of two vectors
  • Accessing matrix:
Eigen::MatrixXd A = Eigen::MatrixXd::Random(7, 9);std::cout << "The element at fourth row and 7the column is " << A(3, 6) << std::endl;Eigen::MatrixXd B = A.block(1, 2, 3, 3);std::cout << "Take sub-matrix whose upper left corner is A(1, 2)" << std::endl << B << std::endl;Eigen::VectorXd a = A.col(1); // take the second column of AEigen::VectorXd b = B.row(0); // take the first row of BEigen::VectorXd c = a.head(3);// take the first three elements of aEigen::VectorXd d = b.tail(2);// take the last two elements of b
  • Quaternion:
Eigen::Quaterniond q(2, 0, 1, -3); std::cout << "This quaternion consists of a scalar " << q.w() << " and a vector " << std::endl << q.vec() << std::endl;q.normalize();std::cout << "To represent rotation, we need to normalize it such that its length is " << q.norm() << std::endl;Eigen::Vector3d v(1, 2, -1);Eigen::Quaterniond p;p.w() = 0;p.vec() = v;Eigen::Quaterniond rotatedP = q * p * q.inverse(); Eigen::Vector3d rotatedV = rotatedP.vec();std::cout << "We can now use it to rotate a vector " << std::endl << v << " to " << std::endl << rotatedV << std::endl;Eigen::Matrix3d R = q.toRotationMatrix(); // convert a quaternion to a 3x3 rotation matrixstd::cout << "Compare with the result using an rotation matrix " << std::endl << R * v << std::endl;Eigen::Quaterniond a = Eigen::Quterniond::Identity();Eigen::Quaterniond b = Eigen::Quterniond::Identity();Eigen::Quaterniond c; // Adding two quaternion as two 4x1 vectors is not supported by the EIgen API. That is, c = a + b is not allowed. We have to do this in a hard wayc.w() = a.w() + b.w();c.x() = a.x() + b.x();c.y() = a.y() + b.y();c.z() = a.z() + b.z();

cs4496 Computer Animation 使用eigen 教程。

總結

以上是生活随笔為你收集整理的使用eigen库进行空间变换的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。