Home › Forums › GAMES在线课程(现代计算机图形学入门)讨论区 › 作业1提高题的问题
- This topic has 1 reply, 2 voices, and was last updated 5 years ago by
Diamanta.
Viewing 1 reply thread
-
AuthorPosts
-
-
gzhao01
Participant作业一种遇到两个问题,自己找资料和想了很久都没解决,希望大佬能够赐教
一、当输入的围绕旋转的轴时,如果第一个输入参数不为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. -
Diamanta
Participant你这个旋转函数看起来没什么问题呀 实现的部分你没写出来 要三个轴的旋转矩阵乘起来 并且顺序要正确 否则会产生万向锁
-
-
AuthorPosts
Viewing 1 reply thread
- You must be logged in to reply to this topic.