作业0
配置环境:
基本配置在pa0中都有,下面介绍使用vscode连接VB虚拟机快捷开发
vscode连接VB虚拟机
1.用户名
可以看到Username为cs18
并非为css180
2.密钥
在window主机生成密钥
ssh-keygen #一路回车
3.VB虚拟机配置ssh
- sshd_config配置
cd /etc/ssh/
vim sshd_config
复制以下粘贴到文末:
其实主要修改为:
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys
PasswordAuthentication yes
PermitEmptyPasswords yes
- 放置公钥 到下面文件 没有就新建
~/.ssh/authorized_keys
- 重启ssh服务
sudo service ssh restart
4.虚拟机网卡
按下图设置后保存
查看地址
ifconfig
复制红线地址
在window cmd下测试连接
ssh cs18@地址
可进入虚拟机则进入下一步
5.vscode连接
输入
ssh cs18@地址
如果连接不上则进行 vscode ssh配置
Host 地址HostName 地址User cs18Port 22IdentityFile "C:\Users\你的用户名\.ssh\id_rsa"
至此配置完成 可以愉快的在windows上写代码了,与实际没有差异,任何跳转\提示功能健全
答案:
Main.cpp
#include<cmath>
#include<eigen3/Eigen/Core>
#include<eigen3/Eigen/Dense>
#include<iostream>
#include "Point2D.h"
using namespace std;void example();
void rotate_point(Point2D &point,float theta); int main(){Point2D point;point.x = 2.0f;point.y = 1.0f;rotate_point(point,45);cout<<point.x<<endl;cout<<point.y<<endl;
}void rotate_point(Point2D &point,float theta) {theta = theta/180.0*acos(-1);Eigen::Matrix2f rotate_matrix;rotate_matrix << cos(theta) ,-sin(theta),sin(theta) , cos(theta);Eigen::Matrix<float,2,1> point_matrix;point_matrix << point.x,point.y;Eigen::Matrix<float,2,1> result = rotate_matrix * point_matrix;point.x = result[0];point.y = result[1];
}void example() {// Basic Example of cppstd::cout << "Example of cpp \n";float a = 1.0, b = 2.0;std::cout << a << std::endl;std::cout << a/b << std::endl;std::cout << std::sqrt(b) << std::endl;std::cout << std::acos(-1) << std::endl;std::cout << std::sin(30.0/180.0*acos(-1)) << std::endl;// Example of vectorstd::cout << "Example of vector \n";// vector definitionEigen::Vector3f v(1.0f,2.0f,3.0f);Eigen::Vector3f w(1.0f,0.0f,0.0f);// vector outputstd::cout << "Example of output \n";std::cout << v << std::endl;// vector addstd::cout << "Example of add \n";std::cout << v + w << std::endl;// vector scalar multiplystd::cout << "Example of scalar multiply \n";std::cout << v * 3.0f << std::endl;std::cout << 2.0f * v << std::endl;// Example of matrixstd::cout << "Example of matrix \n";// matrix definitionEigen::Matrix3f i,j;i << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;j << 2.0, 3.0, 1.0, 4.0, 6.0, 5.0, 9.0, 7.0, 8.0;// matrix outputstd::cout << "Example of output \n";std::cout << i << std::endl;// matrix add i + j// matrix scalar multiply i * 2.0// matrix multiply i * j// matrix multiply vector i * vreturn ;
}
Point2D.h
class Point2D
{
private:/* data */
public:float x;float y;
};
Point2D.cpp
#include "Point2D.h"
run.sh 快捷编译
cmake ./ &&
cd ./build
make
if [ $? -ne 0 ]; thenecho "\033[1m\033[40;31m编译失败,本次结果为上一次成功的运行结果\033[0m";./Transformationexit;
elseecho "\033[1m\033[40;32m编译成功\033[0m"./Transformation
fi
作业0
配置环境:
基本配置在pa0中都有,下面介绍使用vscode连接VB虚拟机快捷开发
vscode连接VB虚拟机
1.用户名
可以看到Username为cs18
并非为css180
2.密钥
在window主机生成密钥
ssh-keygen #一路回车
3.VB虚拟机配置ssh
- sshd_config配置
cd /etc/ssh/
vim sshd_config
复制以下粘贴到文末:
其实主要修改为:
PermitRootLogin yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys
PasswordAuthentication yes
PermitEmptyPasswords yes
- 放置公钥 到下面文件 没有就新建
~/.ssh/authorized_keys
- 重启ssh服务
sudo service ssh restart
4.虚拟机网卡
按下图设置后保存
查看地址
ifconfig
复制红线地址
在window cmd下测试连接
ssh cs18@地址
可进入虚拟机则进入下一步
5.vscode连接
输入
ssh cs18@地址
如果连接不上则进行 vscode ssh配置
Host 地址HostName 地址User cs18Port 22IdentityFile "C:\Users\你的用户名\.ssh\id_rsa"
至此配置完成 可以愉快的在windows上写代码了,与实际没有差异,任何跳转\提示功能健全
答案:
Main.cpp
#include<cmath>
#include<eigen3/Eigen/Core>
#include<eigen3/Eigen/Dense>
#include<iostream>
#include "Point2D.h"
using namespace std;void example();
void rotate_point(Point2D &point,float theta); int main(){Point2D point;point.x = 2.0f;point.y = 1.0f;rotate_point(point,45);cout<<point.x<<endl;cout<<point.y<<endl;
}void rotate_point(Point2D &point,float theta) {theta = theta/180.0*acos(-1);Eigen::Matrix2f rotate_matrix;rotate_matrix << cos(theta) ,-sin(theta),sin(theta) , cos(theta);Eigen::Matrix<float,2,1> point_matrix;point_matrix << point.x,point.y;Eigen::Matrix<float,2,1> result = rotate_matrix * point_matrix;point.x = result[0];point.y = result[1];
}void example() {// Basic Example of cppstd::cout << "Example of cpp \n";float a = 1.0, b = 2.0;std::cout << a << std::endl;std::cout << a/b << std::endl;std::cout << std::sqrt(b) << std::endl;std::cout << std::acos(-1) << std::endl;std::cout << std::sin(30.0/180.0*acos(-1)) << std::endl;// Example of vectorstd::cout << "Example of vector \n";// vector definitionEigen::Vector3f v(1.0f,2.0f,3.0f);Eigen::Vector3f w(1.0f,0.0f,0.0f);// vector outputstd::cout << "Example of output \n";std::cout << v << std::endl;// vector addstd::cout << "Example of add \n";std::cout << v + w << std::endl;// vector scalar multiplystd::cout << "Example of scalar multiply \n";std::cout << v * 3.0f << std::endl;std::cout << 2.0f * v << std::endl;// Example of matrixstd::cout << "Example of matrix \n";// matrix definitionEigen::Matrix3f i,j;i << 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0;j << 2.0, 3.0, 1.0, 4.0, 6.0, 5.0, 9.0, 7.0, 8.0;// matrix outputstd::cout << "Example of output \n";std::cout << i << std::endl;// matrix add i + j// matrix scalar multiply i * 2.0// matrix multiply i * j// matrix multiply vector i * vreturn ;
}
Point2D.h
class Point2D
{
private:/* data */
public:float x;float y;
};
Point2D.cpp
#include "Point2D.h"
run.sh 快捷编译
cmake ./ &&
cd ./build
make
if [ $? -ne 0 ]; thenecho "\033[1m\033[40;31m编译失败,本次结果为上一次成功的运行结果\033[0m";./Transformationexit;
elseecho "\033[1m\033[40;32m编译成功\033[0m"./Transformation
fi