GAMES101 作業0 圖形學


簡介

作業用來校驗自己做的是否正確。請不用copy,因為這是cheat youself。

題目

給定一個點 P=(2,1), 將該點繞原點先逆時針旋轉 45◦,再平移 (1,2), 計算出變換后點的坐標(要求用齊次坐標進行計算)。

code

#include<cmath>
#include<eigen3/Eigen/Core>
#include<eigen3/Eigen/Dense>
#include<iostream>
#define _USE_MATH_DEFINES
int main(){
    Eigen::Vector3d test(2.0f,1.0f,1.0f);
    Eigen::Matrix3d rota;
    Eigen::Matrix3d tran;
    double theta = 45.0/180.0*M_PI;
    rota << cos(theta), -1.0*sin(theta), 0,
            sin(theta), cos(theta), 0, 
            0, 0, 1;
    tran << 1, 0, 1, 
            0, 1, 2, 
            0, 0, 1;
    test = tran * rota * test;
    std::cout << test << std::endl;
    std::cout <<  "After rotation and transform the point sits at " 
        << test[0] << "," << test[1] << std::endl;
    return 0;
}

參考資料

book 《fundamental of Computer Graphics》 page 130


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM