Xem mẫu

Khoa CNTT - DDHBK Hà nội hunglt@it-hut.edu.vn 8682595 Bài 4 Các phép biến đổi Đồ hoạ Transformations Phép biến đổi - Transformations ⌘Trong kỹ thuật đồ hoạ 3 bước: Mô hình, Tô trát và Hiên thị (modeling, rendering, displaying) ⌘Với Modeling ( Mô hình hóa) : modeling coordinate Modeling transformation Le Tan Hung world coordinate Viewing transformation viewing coordinate (eye coordinate) Email: hunglt@it-hut.edu.vn ⌘Transformation: là phép ánh xạ tọa độ điểm hay vector thành tọa độ hay vector khác 1 2 Phép biến đổi Transformations ⌘Biến đổi mô hình hoá - Modeling transformations – build complex models by positioning simple components ⌘Biến đổi tạo góc nhìn - Viewing transformations – placing virtual camera in the world – transformation from world coordinates to camera coordinates ⌘Biến Phép chiếu – Projection Transform Transformations - Modeling world 3 4 Phép biến đổi Affine Affine Transformations? Modeling Transformations ⌘Phép biến đổi Affine là phép biến đổi tọa độ điểm đặc trưng của đối tượng thành tập tương ứng các điểm mới để tạo ra các hiệu ứng cho toàn đối tượng. – Ví dụ: phép biến đổi tọa độ với chỉ 2 điểm đầu cuối của đoạn thẳng tạo thành 2 điểm mới mà khi nối chúng với nhau tạo thành đoạn thẳng mới. ⌘Các điểm nằm trên đoạn thẳng sẽ có kết quả là điểm nằm trên đoạn thẳng mới với cùng phép biến đổi thông qua phép nội suy. Transform Transform coordinate system objects/points 5 6 1 Khoa CNTT - DDHBK Hà nội hunglt@it-hut.edu.vn 8682595 Biểu diễn Ma trận ⌘Việc biến đối các đối tượng làm thay đổi các điểm P thành các điểm Q theo thuật toán ⌘Việc biến đổi P sử dụng tọa độ của P (P ,P ) ánh xạ thành các tọa độ mới Q (Qx,Qy) ⌘Việc biến đổi có thể biểu diễn thông qua hàm T, hàm ánh xạ của điểm: – T(Px,Py) = (Qx,Qy) – or: – T(P) = Q Matrix Representation ⌘Phép biến đổi đồ họa - affine transformation T ánh xạ tập P sang tập Q: – Qx = aP + bP + tx – Qy = cP + dP + ty – where a, b, c, d, tx and ty là các hệ số ⌘Biểu diễn ma trận: ⎛ Q x ⎟ = ⎜ a b ⎟⎜ Px ⎟ + ⎜ tx ⎟ ⌘i.e. y y y Q =MP + Tr 7 8 Các phép biến đổi hình học hai chiều Phép biến đổi y ⌘Phương pháp biểu diễn đối tượng P = [ x y ] ⌘Phép biến đổi vị trí điểm T = ⎢c d⎦ ⌘Thực thi phép biến đổi đúng trên 1 điểm ảnh sẽ đúng trên toàn bộ đối tượng [X ]*[ ]= [x y]* ⎡a b ⎤ = (ax + cy ) (bx + dy )]= [x` y` ] ⎣ ⎦ y p pM x z ⌘Phép bất biến ⎡1 0⎤ ⎣0 1⎦ z x ⌘Phép biến đổi tỉ lệ - Scaling ⌘A scaling changes the size of an object with two scale factors, Sx and Sy [X]* T]= [x y]*⎢0 1⎥ = [ax) y]=[x` y`] ⌘Phép biến dạng [X]* T]=[x y]*⎡1 b⎥ = bx+dy]=[x` y`] ⌘A shearing shears an object in a particular direction, (in 2D, it’s either in the x or in the y direction 9 10 Phép quay- Rotation x = ρ cos α, y = ρ sin α ; x’ = ρ cos (θ +α ), y’ = ρ sin (θ +α ) ; x’ = ρ ( cosθ cosα - sinθ sinα ) = x cosθ - y sinθ y’ = ρ ( sinθ cosα + cosθ sinα ) = x sinθ + y cosθ [x` y`]= [xcosθ - ysinθ xsinθ + ycosθ] [T] = ⎣ cos θ sinθ⎤ 11 y ( x’, y’ ) ρ ( x, y ) θ ρ α x Thuộc tính cơ bản của phép biến đổi Affine Transformations ⌘Preservation of lines: – They preserve lines, so the image of a straight line is another straight line. – This vastly simplifies drawing transformed line segments. – We need only compute the image of the two endpoints of the original line and then draw a straight line between them – Preservation of collinearity guarantees that polygons will transform into polygons – Affine transformations map lines to lines; 12 2 Khoa CNTT - DDHBK Hà nội hunglt@it-hut.edu.vn 8682595 Thuộc tính ⌘Preservation of parallelism – Preservation of parallelism guarantees that parallelograms will transform into parallelograms ⌘Preservation of proportional distances – Preservation of proportional distances means that mid-points of lines remain mid-points ⌘Affine transformations change volume by | Det(M) |; Kết hợp các phép biến đổi Composition of Affine Transforms ⌘Any affine transformation can be decomposed into elementary transformations. ⌘Mọi phép biến đổi phức tạp đều có thể tạo thành từ các phép biến đổi cơ sở như: – Dịch chuyển - Translation – Tỉ lệ - Scaling – Quay- Rotation – Biến dạng - Shearing 13 14 Affine transformations preserve affine combinations ⌘It is rare that we want to perform just one elementary transformation. Thuộc tính T ⌘Usually an application requires that we build a complex transformation out of several elementary ones – e.g. translate an object, rotate it, and scale it, all in one move ⌘These individual transformations combine into one overall transformation ⌘This is called the composition of transformations. ⌘The composition of two or more affine transformations is also an affine transformation 15 ⌘Tác động lên tập các điểm đặc trưng của đối tượng tạo thành phép biến đổi cho đối tượng ⌘We have defined each transformation by their effects on single points ⌘In practice these will be applied to multiple points to transfer entire scenes or objects made up of many defining points 16 Điểm gốc - Pivotal points Cho phép quay và tỉ lệ Rotation and Scaling ⌘ The simple versions of rotation and scaling have been based around the origin. ⌘ This means that when we rotate or scale, the object will also move, with respect to the origin ⌘ Translate all points through (-c1,-c2) ⌘ Rotate all points about the origin by ⌘ Translate all points back through (c1,c2) (c1,c2) (0,0) Pivotal points ⌘Often we wish to rotate or scale with respect to some pivotal point, not the origin ⌘Most significantly, we often wish to rotate or scale an object about its centre, or midpoint ⌘In this way, the object’s location does not change ⌘To do this, we relate the rotation or scaling about the pivotal point V, to an elementary rotation or scaling about the origin – We first translate all points so that V coincides with the origin – We then rotate or about the origin – then all points are translated back, so that V is restored to its original location 18 3 Khoa CNTT - DDHBK Hà nội hunglt@it-hut.edu.vn 8682595 Hệ toạ độ đồng nhất ⌘Vấn đề gặp phải: ⌘An affine transformation is composed of a linear transformation followed by a translation ⌘Unfortunately, the translation portion is not a matrix multiplication but must instead be added as an extra term, or vector ⌘What we need is a “trick”, so that translations can be represented in matrix multiplication form ⌘This then means that they can be easily composed with other transformations, by simply 19 multiplying the matrices together Ưu điểm của Hệ tọa độ đồng nhất Homogeneous Transform Tọa độ đồng nhất Homogeneous Transform – x` = ax + by + n – y` = cx + dy + m ⌘Phương pháp biểu diễn mở rộng thông qua tọa độ đồng nhất của các vector vị trí ⌘Với ứng dụng của phép chiếu hình học mà ở đó tọa độ điểm được mô tả dưới ma trận [ x* y* h] – với x = x*/h, y = y*/h, z = z*/h và h là một số 20 thực tuỳ ý Phép biến đổi với tọa độ đồng nhất ⌘Ðưa ra cái nhìn hợp nhất của các phép biến đổi dưới phép nhân ma trận, hỗ trợ cho việc xử lý bằng cả phần cứng và phần mềm ⌘Kết hợp các các phép biến đổi tạo thành ma trận tích đơn giản duy nhất. Tránh nhầm lẫn về thứ tự của các phép nhân khi sử dụng. – Order matters: AB is generally not the same as BA ⌘Cho phép kết hợp với cả các phép biến đổi đặc biệt không tuyến tính khác(non-affine) như: – Phép chiếu phối cảnh - Perspective projections! – Uốn - Bends, Vuốt tapers v.v.v ⌘Ma trận biến đổi đồng nhất a b 0 [T]= ⎢c d 0⎥ ⌘Phép tịnh tiến ⎣m n 1⎦ 1 0 0 [x` y` 1]=[x y 1]⎢0 1 0⎥ =[x+m y+ n 1] ⎣m n 1⎦ (tx, ty, tz) ... - tailieumienphi.vn
nguon tai.lieu . vn