zoukankan      html  css  js  c++  java
  • A Personal Understanding to Matrix Transformation in Graphics

    A Personal Understanding to Matrix Transformation in Graphics
    -------------------------------------------------------------

    Matrix Transformation is a vital important concept for people who are at their beginning of learning Graphics. And this concept usually get hard to learn, especially from a mathematical perspective. This article, however, is not going to elaborate such a theory by an arithmetic way. Instead I'll just focus on a single topic and talk about what I got from that.

    What I'm going to talk is "how to understand that more than one matrix integrate into one result matrix which will then be applied to a vertex to make it transformed."

    =================

    Let's start from the simplest case, there's only one matrix applied to a vertex, which is written like this:

    Va = [M1] * Vb

    It's obvious that "Vb" is transformed to "Va" through the matrix "[M1]". But on the other side, we can think this formula from another meaning, which is in fact the essential idea in this article. Before explaining the idea, let's give a little background knowledge first : the default coordinate in which we're drawing objects is actually a kind of matrix and let's call it "[M0]" for example. With this hidden matrix exposed out, we can replace the formula as this :

    Va = [M0] * [M1] * Vb

    Now the idea comes. We can see the representation as that the default coordinate(matrix) "[M0]" is transformed by the other matrix "[M1]" and turned into a new coordinate, and then, "Vb" is just drawn at the location as it is, but in this new coordinate. the value of "Va" represents the location of "Vb" where we look it from the default coordinate("[M0]").

    So briefly speaking, There are two understandings to the same formula, just from two directions opposed to each other.

             ---------------> (a)
    Va = [M0] * [M1] * Vb
             <--------------- (b)


    (a) stands at the "coordinate"'s view to see the transformation. A coordinate turns into others one by one from left to right side, and in the final result coordinate, the vertex is drawn to the location where it's value reflects.

    And (b) see the transformation standing from the "vertex"'s view. A vertex is applied by a matrix and turns into another vertex with the different location. And the new vertex continues the transformation until the last matrix is applied to it. And eventually we draw this result vertex under the default coordinate ("[M0]").

    Both thoughts get the same result. "Va", the left side of the equation, represents the original "Vb" is transformed to a new location where now "Va" lies in the default coordinate "[M0]". This is a good example showing "consider the same one thing from more than one aspects".

    =================

    It's time I give a practical case using this philosophy now, still a simple case, though. Suppose there is an arbitrary object composed of vertices(ex. a triangle with 3 vertices) in the default coordinate "[M0]". What if we want to firstly move it to somewhere, and secondly make it self-rotated, which means rotate around its own axes?

    Let's break this question down. Actually our question include two transformations, MOVE and ROTATE, each can be represented by a matrix. we'll give them a name respectively, "[T]" for MOVE("Translation") and "[R]" for ROTATE("Rotation"). We know that these two matrices will be integrate to one final matrix and be applied to the object vertices, but what's the sequence of mixing? The different order, results in the different effect. So now we touched the core the question.

    The answer is simple. If we adopt the idea (a), The order is alike with the way we describes the requirement. First we move the coordinate to somewhere and then rotate the coordinate to some angles. And at last we draw the object on that transformed coordinate. While if we adopt the idea (b), what we should do is to rotate the object first and move this rotated object to somewhere we're aiming on the unchanged and default matrix. Both formulas are same:

               ---------------> (a)
    OBJa = [T] * [R] * OBJb
               <--------------- (b)

    ================= 

    A little advanced example enhancing the above case is to take the "Camera View Transformation" into the consideration. We know "Camera View Transformation" is also a kind of matrix and so it can be thought as such. I don't want to go to the details too much here except only a note that the movement relationship between a camera and objects is relative. If the camera moves forward 10 steps, this also means the whole objects in the scene move backward 10 steps with the camera keeps unmoved.

    Since what we're transforming is objects rather than the camera, we should take the inversed matrix of cameras' as the transforming matrix, we call it "Inv([C])", for example. The formula finally looks like this :

               ------------------------> (a)
    OBJa = Inv([C]) * [T] * [R] * OBJb
               <------------------------ (b)

  • 相关阅读:
    面向对象:范式与思想
    每个人都应该懂点函数式编程
    Lambda 表达式-即匿名函数----Lambda演算-即匿名函数的等价推演过程-- => define as
    Side effect (computer science)
    系统理论
    参量与变量、指针、函数、对象
    面向对象和结构化程序设计的区别X
    面向对象编程与面向过程编程的区别(翻译版)
    2015 Objective-C 新特性
    Comparison of programming paradigms
  • 原文地址:https://www.cnblogs.com/lookof/p/3308220.html
Copyright © 2011-2022 走看看