作业一种遇到两个问题,自己找资料和想了很久都没解决,希望大佬能够赐教
一、当输入的围绕旋转的轴时,如果第一个输入参数不为0,就会segmentation error。
二、如果绕y轴旋转,结果会出错,但绕z轴结果应该正确。
以下是代码:
Eigen::Matrix4f get_rotation(Vector3f axis, float angle)
{
axis.normalize();
float radian_angle = angle/180.0f*MY_PI;
Eigen::Matrix4f rotation = Eigen::Matrix4f::Identity();
//store tmp matrix, change it to 4x4
Eigen::Matrix3f temp = Eigen::Matrix3f::Identity();
Eigen::Matrix3f m;
m << 0,-axis[2], axis[1],
axis[2],0,-axis[0],
-axis[1],axis[0],0;
//Rodrigues' rotation formula
temp = cos(radian_angle)*Eigen::Matrix3f::Identity()
+(1-cos(radian_angle))*axis*axis.transpose()
+sin(radian_angle)*m;
rotation << temp(0,0),temp(0,1),temp(0,2),0,
temp(1,0),temp(1,1),temp(1,2),0,
temp(2,0),temp(2,1),temp(2,2),0,
0,0,0,1;
return rotation;
}
//main函数里
Eigen::Vector3f axis;
axis<<0,0,1.0f; // rotate around z axis by default
float angle = 0;
float angle_inter=20; // 20 by default
bool command_line = false;
std::string filename = "output.png";
if (argc >= 3) {
command_line = true;
angle_inter = std::stof(argv[2]); // -r by default
if(argc == 3){
}
//output file name
else if (argc == 4) {
filename = std::string(argv[3]);
}
//rotate axis
else if(argc == 6){
std::cout<<"argv 3"<<argv[3];
axis[0] = std::stof(argv[3]);
axis[1] = std::stof(argv[4]);
axis[2] = std::stof(argv[5]);
}
else{
return 0;
}
}
Attachments:
You must be
logged in to view attached files.