Matrices(矩陣)

週一到週五,天天一篇,北京時間早上7點準時更新~程序員

The matrix is not just a Hollywood movie trilogy, but an exceptionally powerful mathematical tool that greatly simplifies the process of solving one or more equations with variables that have complex relationships with one another(矩陣不像東漢書院那樣,是個花花腸子,每天想着多圈點粉絲,完了還想兜售課程,還想推廣他們自家的引擎,簡直是不懷好意, 矩陣它可以讓空間位置關係方面的表達獲得簡化,這麼看來,矩陣的確是個好人的說呢。可是比起像柯文哲這樣的喜歡把fan念成huan的,東漢書院仍是至少逼格高一點的呢). One common example of this, near and dear to the hearts of graphics programmers, is coordinate transformations(矩陣這個同窗比較常見的姿式就是座標的轉換). For example, if you have a point in space represented by x, y, and zcoordinates, and you need to know where that point is if you rotate it some number of degrees around some arbitrary point and orientation, you use a matrix(好比,你使用矩陣沿着空間中的某個軸去旋轉一個點,你須要知道這個點被轉到哪裏去了). Why? Because the new x coordinate depends not only on the old x coordinate and the other rotation parameters, but also on what the y and z coordinates were(爲何?由於新的x座標不只僅受到原來的x座標的影響,還會受到原來的y、z座標的影響). This kind of dependency between the variables and solution is just the sort of problem at which matrices excel(這種類型的變量間的依賴關係恰好是矩陣所能解決的問題). For fans of the Matrix movies who have a mathematical inclination, the term 「matrix」 is indeed an appropriate title(對於那些有數學功底的***帝國的粉絲來講,毫無疑問matrix確實是一個很是合適的電影名稱)數組

Mathematically, a matrix is nothing more than a set of numbers arranged in uniform rows and columns—in programming terms, a two-dimensional array(數學意義上,矩陣就是不少行列的數據組成一坨東西,在程序員眼裏,就是一個二維數組). A matrix doesn’t have to be square, but all of the rows must have the same number of elements and all of the columns must have the same number of elements(一個矩陣沒必要要非得是方陣,只不過要求每一行或者每一列的元素個數都相同就行). The following are a selection of matrices. They don’t represent anything in particular but serve only to demonstrate matrix structure(下面就是一系列的矩陣,他們不表明任何東西,僅僅是展現了矩陣的結構). Note that it is also valid for a matrix to have a single column or row(矩陣也可能只包含一行或者一列元素). A single row or column of numbers would more simply be called a vector, as discussed previously(若是一個矩陣只有一行或者一列,那麼它能夠被當作是一個向量). In fact, as you will soon see, we can think of some matrices as a table of column vectors(實際上,你將很快看到,咱們能夠把矩陣想象成爲一個列向量組成的表)
Matrices(矩陣)
Matrix」 and 「vector」 are two important terms that you see often in 3D graphics programming literature(在3D圖形學裏,矩陣和向量是很是重要的東西). When dealing with these quantities, you also see the term 「scalar.」(當處理這些數據的時候,你常常還會看到標量,一個標量就是一個表達長度的數字或者說什麼其餘的東西的數據) A scalar is just an ordinary single number used to represent a magnitude or a specific quantity (you know—a regular old, plain, simple number... like before you cared or had all this jargon added to your vocabulary). Matrices can be multiplied and added together, but they can also be multiplied by vectors and scalar values(矩陣間能夠進行乘法加法運算,它還能夠跟向量和標量進行乘法運算). Multiplying a point (represented by a vector) by a matrix (representing a transformation) yields a new transformed point (another vector)(用點和矩陣相乘能夠獲得一個轉換後的點). Matrix transformations are actually not too difficult to understand but can be intimidating at first(矩陣變換不是很是難理解可是剛接觸的玩家會感到很怕怕,若是是這樣的話,建議去抓住×××姐的手). Because an understanding of matrix transformations is fundamental to many 3D tasks, you should still make an attempt to become familiar with them(因爲理解矩陣任然是你作不少3D工做的基礎,因此你仍是要克服恐懼,適應這塊的數學內容). Fortunately, only a little understanding is enough to get you going and doing some pretty incredible things with OpenGL(幸運的是,只須要小學數學,你就能夠玩轉OpenGL了). Over time, and with a little more practice and study, you will master this mathematical tool yourself.(隨着時間的推移和簡單的練習,你就會徹底掌握數學工具)app

In the meantime, as previously for vectors, you will find a number of useful matrix functions and features available in the vmath library(就如同前面的內容同樣,vmath庫裏也包含了不少能夠用於矩陣計算的函數). The source code to this library is also available in the file vmath.h in the book’s source code folder(源代碼就在vmath.h裏). This 3D math library greatly simplifies many tasks in this chapter and the ones to come(這個3D數學庫真的是太棒了,它簡化了不少工做以及後面要作得事情,然而感受這個跟學生學習沒什麼關係,只是讓做者看起來他後面教學內容會簡單了). One useful feature of this library is that it lacks incredibly clever and highly optimized code!(一個很是重要的特色就是,這個庫的代碼很傻,徹底沒怎麼優化過) This makes the library highly portable and easy to understand(這會使得這個庫很容易被人理解,以咱們的實際經驗獲得的結果是,沒人會去看那些晦澀的代碼,尤爲是背後有數學理論的時候,即使本身寫完都再也不願意看第二遍). You’ll also find it has a very GLSL-like syntax(你會發現它跟GLSL裏的語法很像).ide

In your 3D programming tasks with OpenGL, you will use three sizes of matrices extensively: 2 × 2, 3 × 3, and 4 × 4(在咱們的OpenGL裏,你將會使用三種不一樣大小的矩陣,二、三、4維的方陣). The vmath library has matrix data types that match those, defined by GLSL, such as(vmath提供對應的矩陣實現代碼,以下所示:)函數

vmath::mat2 m1;
vmath::mat3 m2;
vmath::mat4 m3;

As in GLSL, the matrix classes in vmath define common operators such as addition, subtraction, unary negation, multiplication, and division, along with constructors and relational operators(就如同GLSL裏同樣,vmath庫定義了基本的矩陣的運算操做的函數接口). Again, the matrix classes in vmath are built using templates and include type definitions for single- and double-precision floating-point, and signed- and unsigned-integer matrix types(一樣,該函數是由C++模板實現,你可使用任意的數據類型,好比浮點、雙精度或者是×××均可以的。實際上做爲一個大學生或者初級3D圖形學選手,你不會去看他的vmath實現, 這些老外寫的東西須要你具有牛X的C++基礎,才勉強能看懂他們的C++代碼,這種是極其不推薦的,學習語言是爲了作項目,不是爲了使用語言的高級語法,C++學習應該適可而止,重點仍是回過頭來看圖形學。至於3D圖形學 方面,咱們的建議是若是想深刻了解,仍是腳踏實地一步一步好好把你的大學工科基礎那些書都翻一遍,做者此處純粹是一筆帶過,知識含量有限)工具

本日的翻譯就到這裏,明天見,拜拜~~學習

第一時間獲取最新橋段,請關注東漢書院以及圖形之心公衆號優化

東漢書院,等你來玩哦ui

相關文章
相關標籤/搜索