ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SLAM Eigen库的入门学习教程(CS2240 Interactive Computer Graphics)

2021-04-27 18:32:24  阅读:295  来源: 互联网

标签:CS2240 Eigen 矩阵 C++ Computer 我知 matrices cout


Eigen库介绍

Eigen is an open-source linear algebra library implemented in C++. It’s fast and well-suited for a
wide range of tasks, from heavy numerical computation, to simple vector arithmetic. The goal of
this tutorial is to introduce the features of Eigen required for implementing graphics applications,
to readers possessing basic knowledge of C++, linear algebra, and computer graphics.

Eigen库是适用C++的开源线性代数库,进行复杂的数值计算简化向量计算。教程的目的在于实现Eigen库的简单应用,需要我们的读者有C++基础,线性代数以及计算机图形学。

教程目标

After reading this tutorial, the reader should be able to

  1. Install Eigen on computers running Linux, Mac OS, and Windows.
  2. Create and initialize matrices and vectors of any size with Eigen in C++.
  3. Use Eigen for basic algebraic operations on matrices and vectors. The reader should be
    able to perform addition, multiplication, scalar multiplication, and matrix inversion and
    transposition.
  4. Use Eigen’s built-in functions to create 4x4 transformation matrices.

在学习完教程后,读者可以完成

  • 在不同环境下Eigen库的安装
  • 在C++中创建或初始化任意大小的矩阵和矢量
  • 使用Eigen库进行最基本的线性代数操作,加减乘除,标量乘,矩阵的逆和转置
  • 使用Eigen库的内置函数创建转置矩阵

安装Eigen库

$ cd ~
$ git clone https :// github .com/ eigenteam /eigen -git - mirror

验证是否安装成功

std::cout << " Eigen version : " << EIGEN_MAJOR_VERSION << "."<< EIGEN_MINOR_VERSION << std::endl ;

会在我们的终端中显示出来版本。

Eigen version : 4.99

遇到没有找到文件的情况要Fatal error :Eigen/core没有那个文件或目录
在这里插入图片描述

Eigen库的使用

    std::cout << " Eigen version : " << EIGEN_MAJOR_VERSION << "."<< EIGEN_MINOR_VERSION << std::endl ;
    Eigen::Matrix3f A;  // 建立一个3*3的矩阵,float
    Eigen::Matrix4d B;  // 建立一个4×4的矩阵,double

Keep in mind, though, that not all combinations of size and type are valid | Matrix2i works, but Matrix5s throws an error.That is not to say you can’t create 5x5 matrices of type short, or that you can only create square matrices.

我们要注意的事情是不是所有的大小的矩阵都可以使用这种方法。

error: ‘Matrix5s’ is not a member of ‘Eigen’
     Eigen::Matrix5s C;

我们可以使用另外一种方法构建:

// 5x5 matrix of type short
Matrix <short , 5, 5> M1;
// 20 x75 matrix of type float
Matrix <float , 20, 75> M2;

Eigen还允许我们构建未知大小的矩阵,比如 MatrixXf, MatrixXd

However, as the majority of graphics operations only require us to work with 3x3 and 4x4 single
or double precision matrices, we will restrict our attention in this tutorial to the datatypes
Matrix3f, Matrix4f, Matrix3d, and Matrix4d

我们经常使用的一般为3 × \times × 3的旋转矩阵以及4 × \times × 4的转换矩阵,所以我们的数据类型为Matrix3f, Matrix4f, Matrix3d, Matrix4d

矩阵的初始化

高级初始化方法

// Initialize A  (cumbersome,adj. 笨重的;累赘的;难处理的)
A << 1.0f, 0.0f, 0.0f,
     0.0f, 1.0f, 0.0f,
     0.0f, 0.0f, 1.0 f;
// Initialize B by accessing individual elements
for i = 1:4 {
	for j = 1:4 {
		B(j, i) = 0.0;
	}
}

如果我们的矩阵不是很大,可以使用第一种方法。

还有一种Vector4d :: Random () 随机生成数字。

转置和求逆和python里面的是一样的

// Transposition
cout << M1. transpose () << endl ;
// Inversion ( # include <Eigen /Dense > )
// Generates NaNs if the matrix is not invertible
cout << M1. inverse () << endl ;

Eigen库里面还有各种其他运算操作

cout << v1.dot (v2) << endl << endl ;
cout << v1. normalized () << endl << endl ;
cout << v1. cross (v2) << endl ;
// Convert a vector to and from homogenous coordinates
Vector3f s = Vector3f :: Random ();
Vector4f q = s. homogeneous ();
cout << (s == q. hnormalized ()) << endl;

更多信息解锁这里

肥鼠路易今天有在好好在办公室里喝水 在办公室里面学习,https://blog.csdn.net/weixin_44991673,欢迎点赞收藏关注三连666哦!
2021/04/27

在这里插入图片描述
今日背景音乐《世间美好与你环环相扣》

偏偏秉烛夜游
午夜星辰 似奔走之友
爱你每个结痂伤口
酿成的陈年烈酒
入喉尚算可口
怎么泪水 还偶尔失守
邀你细看心中缺口
裂缝中留存 温柔
此时已莺飞草长 爱的人正在路上
我知他风雨兼程 途经日暮不赏
穿越人海 只为与你相拥
此刻已皓月当空 爱的人手捧星光
我知他乘风破浪 去了黑暗一趟
感同身受 给你救赎热望
知道你不能 还要你感受
让星光加了一点彩虹
让樱花偷偷 吻你额头
让世间美好 与你环环相扣
此时已莺飞草长 爱的人正在路上
我知他风雨兼程 途经日暮不赏
穿越人海 只为与你相拥
此刻已皓月当空 爱的人手捧星光
我知他乘风破浪 去了黑暗一趟
感同身受 给你救赎热望
此时已莺飞草长 爱的人正在路上
我知他风雨兼程 途经日暮不赏
穿越人海 只为与你相拥
此刻已皓月当空 爱的人手捧星光
我知他乘风破浪 去了黑暗一趟
感同身受 给你救赎热望
知道你不能 还要你感受
让星光加了一点彩虹
当樱花开的纷纷扬扬
当世间美好 与你环环相扣

标签:CS2240,Eigen,矩阵,C++,Computer,我知,matrices,cout
来源: https://blog.csdn.net/weixin_44991673/article/details/116203653

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有