Eigen 7 Geometry 幾何轉換

2021-10-01 10:51:17 字數 4296 閱讀 9658

官方位址傳送

space transformations

變換矩陣

eigen::isometry3d t;

t.matrix()才是變換矩陣,做運算時需加.matrix()字尾;

t.pretranslate()以及t.prerotate()可以給平移部分和旋轉矩陣賦值,但是若迴圈中使用,末尾不重置變換矩陣的話,這個設定量會累加,而不是覆蓋。

四元數賦值:eigen::quaterniond q;

q.x() = 3 「類似地 q.y() = q.z() = q.w()」

1、 旋轉矩陣(r),旋轉向量(v)和四元數(q)在eigen中轉換關係的總結:

2、旋轉矩陣(r),旋轉向量(v)和四元數(q)分別通過自身初始化自己的方式:

r通過自身初始化的方法:

v通過自身初始化的方法:

cout << 「rotation_vector1」 << endl << v1.matrix() << endl;

q通過自身初始化的方法:

q=[cos(a/2),n_xsin(a/2),n_ysin(a/2),n_z*sin(a/2)]

quaterniond q1(cos((m_pi / 4) / 2), 0 * sin((m_pi / 4) / 2), 0 * sin((m_pi / 4) / 2), 1 * sin((m_pi / 4) / 2));//以(0,0,1)為旋轉軸,旋轉45度

cout << 「quaternion1」 << endl << q1.coeffs() << endl;

演示**:

#include

#include

#define m_pi 3.1415926

using

namespace std;

using

namespace eigen;

void

run_eigen_geometry()

演示**2:eigen_geometry_2.cpp

#include

#include

#define m_pi 3.1415926

using

namespace std;

#include

// eigen 幾何模組

#include

/****************************

* 本程式演示了 eigen 幾何模組的使用方法

****************************/

void

run_eigen_geometry_2()

而程式為了簡化表示 直接使用 q*v代替

cout <<

"(1,0,0) after quaterniond rotation = "

<< v_rotated.

transpose()

<< endl;

/*程式設計題目

小蘿蔔1號位姿q1=[0.35,0.2,0.3,0.1],t1=[0.3,0.1,0.1]'   世界座標系到相機變換

小蘿蔔2號位姿q2=[-0.5,0.4,-0.1,0.2],t2=[-0.1,0.5,0.3]'

小蘿蔔1號看到位於自身座標系下p=[0.5,0,0.2]'

求該向量在小蘿蔔2號下的座標

*/ eigen::quaterniond q1

(0.35

,0.2

,0.3

,0.1);

//wxyz q1.coeffs() xyzw q1.vec() xyz

//q1 << 0.35,0.2,0.3,0.1;

eigen::matrix<

double,3

,1> t1;

//float型別

t1 <<

0.3,

0.1,

0.1;

eigen::quaterniond q2(-

0.5,

0.4,

-0.1

,0.2);

//q2 << -0.5,0.4,-0.1,0.2;

eigen::matrix<

double,3

,1> t2;

//float型別

t2 <<

-0.1

,0.5

,0.3

; eigen::matrix<

double,3

,1> p1;

//float型別

p1 <<

0.5,0,

0.2;

cout <<

"q1= \n"

<< q1.

coeffs()

<< endl;

cout <<

"t1= \n"

<< t1 << endl;

cout <<

"q2= \n"

<< q2.

coeffs()

<< endl;

cout <<

"t2= \n"

<< t2 << endl;

/* q1.setidentity();

cout<

normalized()

;//規範化  歸一化 除以模長

cout <<

"q1 after normalized\n"

<< q1.

coeffs()

<< endl;

q2 = q2.

normalized()

; cout <<

"q2 after normalized \n"

<< q2.

coeffs()

<< endl;

eigen::matrix3d q1rotation_matrix = eigen::matrix3d::

identity()

;//單位陣

q1rotation_matrix = q1.

torotationmatrix()

; eigen::isometry3d tc1w = eigen::isometry3d::

identity()

;// 雖然稱為3d,實質上是4*4的矩陣  齊次座標

tc1w.

rotate

(q1rotation_matrix)

;// 按照q1rotation_matrix進行旋轉

tc1w.

pretranslate

(t1)

;// 把平移向量設成t1

//eigen::isometry3d twc1=tc1w.inverse();//由world 到c1的逆變換  成 c1到world

eigen::matrix<

double,3

,1> pw = tc1w.

inverse()

*p1;

//將c1座標系下的點p1變換到world座標系下

eigen::matrix3d q2rotation_matrix = eigen::matrix3d::

identity()

;//單位陣

q2rotation_matrix = q2.

torotationmatrix()

; eigen::isometry3d tc2w = eigen::isometry3d::

identity()

;// 雖然稱為3d,實質上是4*4的矩陣  齊次座標

tc2w.

rotate

(q2rotation_matrix)

;// 按照q2rotation_matrix進行旋轉

tc2w.

pretranslate

(t2)

;// 把平移向量設成t2

eigen::matrix<

double,3

,1> p2 = tc2w*pw;

//將world座標系下的點pw變換到c2座標系下

cout <<

"the loc of p1 in c1 = \n"

<< p1 << endl;

cout <<

"the loc of p1 in world = \n"

<< pw << endl;

cout <<

"the loc of p1 in c2 = \n"

<< p2 << endl;

}

遞迴遞推練習 G7

老 師會按考號分配固定的座位,但唯一不變的是每兩個人之間肯定至少會留下兩個空座位,原因相信大家都懂得。那麼問題來了,我們現在只關注教室裡的一排座位,假設每排有 n個座位,小銀想知道這一排至少坐乙個人的前提下,一共有多少種坐法。此題分析一下,假如有n個座位,分析第n個座位,有兩種情況,一是坐人,那麼n...

Oracle11G 7個服務說明

中的方法成功安裝oracle 11g後,共有7個服務,這七個服務的含義分別為 1.oracle orcl vss writer service oracle卷對映拷貝寫入服務,vss volume shadow copy service 能夠讓儲存基礎裝置 比如磁碟,陣列等 建立高保真的時間點映像,...

Win7安裝oracle 10g 方法

然後解壓,在目錄中找到refhost.xml 有兩個,我的乙個是在stage prereq db目錄下,乙個是在stage prereq db prereqs db目錄下 進行新增修,新增如下 而後還要修改乙個oraparam.ini檔案,在install目錄下 先在 certified versi...