Eigen的配置和使用(GAMES101-0作业)

VS STIDO配置Eigen库

配置教程

Eigen库的使用

Eigen库基础使用手册

GAMES101-0作业

 C++代码如下:

#include 
#include 
#include 
#include 

using namespace std;

int main()
{
	// 向量的定义
	Eigen::Vector3f v(1, 0, 0);
	Eigen::Vector3f w(0, 1, 0);
	// 向量的加减运行
	cout << "v + w:" << endl << v + w << endl;
	cout << "v - w:" << endl << v - w << endl;
	cout << "v * 2:" << endl << v * 2 << endl;
	// 向量的点乘和叉乘
	cout << "v·w:" << endl << v.dot(w) << endl;
	cout << "v×w:" << endl << v.cross(w) << endl;
	// 向量的大小
	cout << "v.size:" << endl << v.size() << endl;
	// 向量元素的访问
	cout << "v(0):" << v(0) << " v[0]:" << v[0] << endl;
	cout << "v{0->1}:" << endl << v.head(2) << endl;
	cout << "v{end-3->end}:" << endl << v.tail(3) << endl;
	cout << "v{i->i+j-1}:" << endl << v.segment(0,2) << endl;

	// 矩阵的定义
	Eigen::Matrix3f A, B;
	// 矩阵数据的赋值(按行赋值)
	A << 1, 2, 3, 4, 5, 6, 7, 8, 9;
	B << 2, 3, 1, 4, 6, 5, 9, 7, 8;
	cout << "A:" << endl << A << endl;
	cout << "B:" << endl << B << endl;
	// 矩阵的转置和求和
	cout << "A(T)" << endl << A.transpose() << endl;
	cout << "A+B:" << endl << A + B << endl;
	
	// 矩阵求逆
	Eigen::Matrix2f C;
	C << 1, 1, -1, 1;
	cout << "C:" << endl << C << endl;
	cout << "C(-1)" << endl << C.inverse() << endl;
	cout << "CC(-1)" << endl << C * C.inverse() << endl;
	return 0;
}



你可能感兴趣的:(GAMES101,计算机图形学,GAMES101,CG,Eigen)