Games101-202作业00

#include <iostream>
#include <Eigen>
#define PI 3.1415926
using Eigen::Matrix3d;
using Eigen::Vector3d;
using namespace std;

int main()
{
	Vector3d p(1, 2, 1);//构造函数给基础的P向量赋值为(1,2,1)
	//第三维的数是齐次坐标
	//默认是列向量
	Matrix3d rotate;
	rotate << cos(PI / 4.0f), -sin(PI / 4.0f),0,
		       sin(PI / 4.0f), cos(PI / 4.0f),0,
	              0, 0, 1;
	//三位旋转矩阵
	Matrix3d trans;
	trans << 1, 0, 1,
		     0, 1, 2,
		     0, 0, 1;
	//平移矩阵
	Vector3d ans = trans * rotate * p;
	cout << "Ans = " << endl;
	cout << ans << endl;


		    
}

比较简单,主要是熟悉Eigen的用法。比如如何声明矩阵和向量,如何初始化矩阵和向量。

输出结果 

Ans =
0.292893
 4.12132
       1

猜你喜欢

转载自blog.csdn.net/qq_24917263/article/details/129080181