寫了個能驗證線性變換的程序,主要是用來驗證https://www.bilibili.com/video/av5987715/windows
這個教學視頻的線性代數內容,學習和實踐相結合,知行合一嘛~架構
原始就是一個正方形,隨便按一個按鍵就可以進行旋轉操做,旋轉後的畫面不重繪,因此就出現了這樣連續的圖形。ide
繪圖採用的windows經典圖形架構,不羅嗦了。函數
主要寫了這樣的幾個類,實現圖形描述,畫圖,旋轉等操做。學習
先介紹MyPoint這個類。本來想用CPoint的,結果VS2017中不包含那個頭文件,因此沒辦法了,只能本身寫一個。this
就是用來描述點的,數據作了點封裝,具體以下:spa
1 class MyPoint 2 { 3 private: 4 int x; 5 int y; 6 public: 7 MyPoint() :x(0),y(0){}; 8 MyPoint(int xval, int yval) :x(xval), y(yval) {}; 9 inline void SetX(int xval) { x = xval; }; 10 inline void SetY(int yval) { y = yval; }; 11 int GetX() { return x; }; 12 int GetY() { return y; }; 13 void SetXY(int xval, int yval) 14 { 15 SetX(xval); 16 SetY(yval); 17 } 18 MyPoint & operator += (MyPoint & Offset) 19 { 20 x += Offset.x; 21 y += Offset.y; 22 return *this; 23 }; 24 MyPoint & operator = (MyPoint & Offset) 25 { 26 x = Offset.x; 27 y = Offset.y; 28 return *this; 29 }; 30 ~MyPoint() {}; 31 };
BasicShape這個類數據主要包含了多個點,,而後按照順尋,將這些點依次鏈接起來,造成一個圖形閉環。3d
這個類還不完善,目前實現自我旋轉的函數是在畫圖的時候畫出來的,沒有在類的內部進行封裝。所以這部分還要改善。code
1 class BasicShape 2 { 3 private: 4 std::vector<MyPoint> ShapeData; 5 public: 6 BasicShape(); 7 /*位置調整*/ 8 void SetPosition(MyPosition & NewPosition); 9 int DrawShape(HDC hdc); 10 int RotateShape(float angle); 11 ~BasicShape(); 12 };
Rotate類是實現數據旋轉的,其實就是個描述矩陣。視頻
Switchto函數的主要功能是根據輸入的角度生成對應的矩陣,而後在調用RotatePoint函數對單獨的點進行線性變換。
1 class Rotater 2 { 3 private: 4 float x_i, x_j; 5 float y_i, y_j; 6 public: 7 Rotater():x_i (1), y_i(0), x_j(0), y_j(1){}; 8 void Switchto(float angle); 9 void RotatePoint( MyPoint & Point ); 10 };