简介
作业用来校验自己做的是否正确。请不用copy,因为这是cheat youself。
题目
给定一个点 P=(2,1), 将该点绕原点先逆时针旋转 45◦,再平移 (1,2), 计算出变换后点的坐标(要求用齐次坐标进行计算)。
code
1#include<cmath> 2#include<eigen3/Eigen/Core> 3#include<eigen3/Eigen/Dense> 4#include<iostream> 5#define _USE_MATH_DEFINES 6int main(){ 7 Eigen::Vector3d test(2.0f,1.0f,1.0f); 8 Eigen::Matrix3d rota; 9 Eigen::Matrix3d tran; 10 double theta = 45.0/180.0*M_PI; 11 rota << cos(theta), -1.0*sin(theta), 0, 12 sin(theta), cos(theta), 0, 13 0, 0, 1; 14 tran << 1, 0, 1, 15 0, 1, 2, 16 0, 0, 1; 17 test = tran * rota * test; 18 std::cout << test << std::endl; 19 std::cout << "After rotation and transform the point sits at " 20 << test[0] << "," << test[1] << std::endl; 21 return 0; 22}
参考资料
book 《fundamental of Computer Graphics》 page 130