官网
http://eigen.tuxfamily.org/index.php?title=Main_Page
下载解压后路径:
D:\dev\C++Lib\eigen-3.4.0
建立 .vscode 目录
建立build 配置文件
这个地方在includePath 下面加上之前解压的Eigen库的路径目录
表示让VSCode 识别出,要去这个目录下查找头文件
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"D:\\dev\\C++Lib\\eigen-3.4.0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\BasicSoftware\\mingw64\\bin\\gcc.exe",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) 启动",
"type": "cppvsdbg",
"request": "launch",
"program": "${fileBasenameNoExtension}.exe",
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
}
]
}
注意这个才是重点:
注意路径用两个斜线 \\ 分开
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "g++ build",
"command": "g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"D:\\dev\\C++Lib\\eigen-3.4.0"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "build task"
}
],
"version": "2.0.0"
}
main.cpp
#include <iostream>
#include <Eigen/Dense>
#include<Eigen/Core>
using Eigen::MatrixXd;
int main(){
//定义我们的p点 写成齐次坐标形式
Eigen::Vector3f p(2.0f,1.0f,1.0f);
// 目标是先旋转后平移
// 所以我们在p的左边依次乘以旋转矩阵和平移矩阵
// 定义旋转矩阵
Eigen::Matrix3f rotation;
Eigen::Matrix3f transform;
// 定义平移矩阵
// 转换成弧度数
double theta = 45.0/180.0*M_PI;
// 旋转矩阵写成齐次坐标形式
rotation << cos(theta), -sin(theta), 0,
sin(theta), cos(theta), 0,
0, 0, 1;
// 平移矩阵 +(1,2)
transform << 1, 0, 1,
0, 1, 2,
0, 0, 1;
std::cout << p << std::endl;
p = transform * p;
std::cout << "transform" << std::endl;
std::cout << p << std::endl;
p = rotation * p;
std::cout << "rotate:" << std::endl;
// 最终结果
std::cout<< p <<std::endl;
}
输出:
2
1
1
transform
3
3
1
rotate:
0
4.24264
1