Transformasi 2D (endang_pg)

Slides:



Advertisements
Similar presentations
Computer Graphics: 2D Transformations
Advertisements

Computer Graphics 2D & 3D Transformation.
COMPUTER GRAPHICS 2D TRANSFORMATIONS.
Gursharan Singh Tatla TRANSFORMATIONS Gursharan Singh Tatla Gursharan Singh Tatla.
CLASS 4 CS770/870. Translation Scale Multiplying Matrices. The R C rule What happens when we do two translates? What happens when we do two scales?
GRAFIKA KOMPUTER ~ M. Ali Fauzi.
Arithmetic and Logic Unit. Arithmetic And Logic Unit Representasi Bilangan ALU 1. Integer Semua bilangan direpresentasikan dengan hanya menggunakan bilangan.
1 1 © 2003 Thomson  /South-Western Slide Chapter 15 Multicriteria Decision Problems n Goal Programming n Goal Programming: Formulation and Graphical.
Geometric Transformations
CMPE 466 COMPUTER GRAPHICS
1 CSCE 441 Computer Graphics: 2D Transformations Jinxiang Chai.
Course Website: Computer Graphics 3: 2D Transformations.
2IV60 Computer Graphics 2D transformations
2D Transformations x y x y x y. 2D Transformation Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation.
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
2D Transformations. World Coordinates Translate Rotate Scale Viewport Transforms Hierarchical Model Transforms Putting it all together.
3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. 3D Transformation glVertex3f(x, y,z);
5.2 Three-Dimensional Geometric and Modeling Transformations 2D3D Consideration for the z coordinate.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Graphics Graphics Korea University kucg.korea.ac.kr Transformations 고려대학교 컴퓨터 그래픽스 연구실.
2D Transformations.
Lecture Notes: Computer Graphics.
Geometry: 2-D Transformations Course web page: Chapter #3.
Computer Graphics 2D Transformations. 2 of 74 Contents In today’s lecture we’ll cover the following: –Why transformations –Transformations Translation.
1 Computer Graphics Week9 -3D Geometric Transformation.
Computer Graphics I, Fall 2010 OpenGL Transformations.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
3D Transformations. Translation x’ = x + tx y’ = y + ty z’ = z + tz P = P’ = T = P’ = T. P tx ty tz xyz1xyz1 x’ y’ z’ 1 x y.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
3D Transformation A 3D point (x,y,z) – x,y, and z coordinates
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
PENDAHULUAN Dalam matematika, deret Taylor adalah representasi fungsi matematika sebagai jumlahan tak hingga dari suku-suku yang nilainya dihitung dari.
1 By Dr. HANY ELSALAMONY.  We have seen how to create models in the 3D world. We discussed transforms in lecture 3, and we have used some transformations.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0.
1 Teaching Innovation - Entrepreneurial - Global The Centre for Technology enabled Teaching & Learning, N Y S S, India DTEL DTEL (Department for Technology.
Oleh : Gina Elvira ( ). Komunikasi antarbudaya adalah komunikasi yang terjadi di antara orang-orang yang memiliki kebudayaan yang berbeda (bisa.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphic 2 D Transformation.
CSCE 441 Computer Graphics: 2D Transformations
MODEL REGRESI VARIABEL DUMMY A.Sifat Alamiah Variabel-Variabel Dummy Variabel yang diasumsikan nilai 0 dan 1 suatu perangkat untuk menggolongkan data ke.
CPT450 – Computer Graphics
Computer Graphics 2D Transformations
Modeling Transformations
Lecture 10 Geometric Transformations In 3D(Three- Dimensional)
Computer Graphics 3: 2D Transformations
Geometric Transformations Hearn & Baker Chapter 5
2D Geometric Transformations
Computer Graphics CC416 Week 15 3D Graphics.
Computer Graphics Transformations.
Computer Graphics 3: 2D Transformations
Chapter 5 2-D Transformations.
Computer Graphics Transformations.
Lecture 7 Geometric Transformations (Continued)
Strategi Algoritma Universitas Ahmad Dahlan
2D Transformations y y x x y x.
© 2008, Fayyaz A. Afsar, DCIS, PIEAS.
Introduction to Computer Graphics with WebGL
Geometric Transformations
A.ERROR Kesalahan adalah perbedaan antara variabel yang diukur dan setpoint. Kesalahan dapat berupa positif atau negatif. Tujuan dari setiap skema kontrol.
Geometric Transformations
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
IV.VEKTOR. A.MENJUMLAHKAN VEKTOR a. Menjumlahkan vektor dengan cara jajaran genjang Gambar di bawah vektor F1 dan vektor F2 pada satu titik tangkap yang.
Transformations in OpenGL
Geometric Objects and Transformations (II)
ICT HANDYBOOK SPM LA2 COMPUTER SYSTEMS 2.3 Software.
Geometric Transformations
TWO DIMENSIONAL TRANSFORMATION
Presentation transcript:

Transformasi 2D (endang_pg) Reff: “Fundamentals of interactive computer Graphics” james d. folley and andreas Van Dam” Komputer Grafik Departemen Ilmu Komputer FMIPA-IPB 2011

Agenda kali ini! Kenapa transformasi? Jenis Transformasi Translasi Scaling Rotasi Sistem Koordinat Homogen dan representasi matrix transformasi Transformasi Komposit

Kenapa Transformasi? Transformasi ditujukan untuk menggambarkan operasi perubahan posisi, ukuran, ataupun view sebuah objek grafik

Translasi x’ = x + dx y‘= y + dy Transformasi bagi fenomena pergeseran suatu objek dari satu posisi ke posisi lain x’ = x + dx y‘= y + dy Translasi relatif terhadap sumbu koordinat y x 1 2 3 4 5 6 7 8 9 10

Contoh Translasi y x 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 1) (3, 1)

Scaling x’ = Sx × x y ‘= Sy × y Transformasi terkait perubahan ukuran objek grafis, dengan mengalikan setiap titik terhadap suatu skalar Perhatikan: tidak hanya berubah tetapi juga bergerak! x’ = Sx × x y ‘= Sy × y Relatif terhadap origin y x 1 2 3 4 5 6 7 8 9 10

Contoh Scaling y x 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 1) (3, 1) 7

Rotasi x ‘= x × cosθ – yold × sinθ y ‘= x × sinθ + yold × cosθ Rotasi dasar memutar objek terhadap titik origin dengan suatu sudut putaran tertentu (θ) x ‘= x × cosθ – yold × sinθ y ‘= x × sinθ + yold × cosθ formulasi di papan tulis y 6 5 4 3 2 1 x

Contoh Rotasi y x 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 1) (3, 1) 9

Sistem Koordinat Homogen Andaikan P adalah pasangan titik (xi,yi) Translasi P’=P+T Scaling P’=P.S Rotasi P’=P.R Perhatikan mana yang Operasinya sangat Berbeda? Jelaskan terlebih dahulu setiap matriks ketika menjelasakan modus transformasi

Sistem Koordinat Homogen(ii) Seringkali transformasi merupakan proses berturutan dari dua atau lebih kombinasi jenis transformasi berbeda Bagaimana agar operasi ketiga transformasi dapat dengan mudah dikombinasikan? PASTINYA OPERASINYA HARUS HOMOGEN

Homogeneous coordinates w (x, y, w) w = 1 (x/w, y/w, 1) x y y Kita bisa memandang bahwa sisi 2 D adalah dimensi terbatas dari ruang 3D. Objek 3D adalah sehimpunan sisi paralel tidak terbatas dari ruang 3D x w = 0

Homogeneous Coordinates Sebuah titik (x, y) dapat dituliskan pada homogeneous coordinates sebagai (xh, yh, h) Dengan homogeneous parameter h sebuah nilai tidak Nol sehingga: Selanjutnya setiap titik (x, y) dapat ditulis sebagai (hx, hy, h) Dengan mudah untuk h = 1 maka (x, y) menjadi (x, y, 1)

Why Homogeneous Coordinates? Matematikawan biasanya menggunakan koordinat homogen untuk dapat memberikan faktor skala yang dikemudian waktu dapat dihapus dari persamaan Kita akan lihat bahwa semua transformasi dapat direpresentasikan sebagai matriks 3 * 3 Koordinat homogen dapat kita gunakan untuk mewujudkannya, sehingga operasi transformasi menjadi lebih efisien

Remember Matrix Multiplication Recall how matrix multiplication takes place:

Homogeneous Translation Translasi titik oleh (dx, dy) dapat ditulis dalam bentuk matriks sebagai Mewakili titik sebagai vektor kolom homogen kita melakukan aksi ini sebagai perhitungan:

Homogenous Coordinates To make operations easier, 2-D points are written as homogenous coordinate column vectors Translation: Scaling:

Homogenous Coordinates (cont…) Rotation:

Inverse Transformations Secara mudah matriks transformasinya dapat dituliskan sebagai

Combining Transformations Untuk memudahkan beberapa kombinasi transformasi dapat direpresentasikan sebagai sebuah matrik transformasi Contoh sebuah objek bentuk yang berputar pada poros titik beratnya (Z): Transformasikan Z ke origin Rotasikan dengan poros origin Transformasikan kembali origin pada Z

Combining Transformations (cont…) 1 2 3 4

Combining Transformations (cont…) The three transformation matrices are combined as follows REMEMBER: Matrix multiplication is not commutative so order matters

Transformasi 2D in Open GL (endang_pg) Komputer Grafik Departemen Ilmu Komputer FMIPA-IPB 2011 23

In OpenGL, all the model transformations are accumulated in the current transformation matrix (CTM). All vertices of an object will be transformed via this matrix before the object is drawn. A system stack is provided for storing the backup copies of the CTM during execution. We usually save the CTM in the stack before the drawing of a transformed object. And restore the original CTM afterwards. CTM Vertices Stack

. . To save a copy of the CTM in the stack Vertices CTM Stack (before) To save a copy of the CTM in the stack glPushMatrix(); CTM Vertices Stack . (after)

. . . . . . To overwrite the CTM with the top matrix in the stack Vertices Stack . . . (before) To overwrite the CTM with the top matrix in the stack glPopMatrix(); Vertices Vertices CTM (after) . . . Stack

To specify a translation glTranslatef( double Tx, double Ty, 0.0) The system first generates the matrix representing the translation. Then post multiplies this matrix with the CTM. Finally overwrites the CTM with the result. CTM Vertices  Before After CTM Vertices

Progressive Translation Example //draw a white head at (0,0) glColor3f( 1.0, 1.0, 1.0); draw_head(); //draw a green head at (-2,-1) glColor3f( 0.0, 1.0, 0.0); glPushMatrix(); glTranslatef( -2.0, -1.0, 0.0); glPopMatrix(); glColor3f( 1.0, 1.0, 1.0); //draw a title hkgluBitMapString( -1.9, 1.8, "Translation of (-2, -1)” ); Progressive Translation

Generate a matrix for the scaling. Post multiply it with the CTM To specify a scaling glScalef( double Sx, double Sy, 1.0) Generate a matrix for the scaling. Post multiply it with the CTM //Scale by Sx = 1.5, Sy = 2 glPushMatrix(); glScalef( 1.5, 2.0, 1.0); draw_head(); glPopMatrix(); In general, an object moves away from the origin when scaled up, moves towards when scaled down Progressive Scaling

To specify a rotation glRotatef( double degree, 0.0, 0.0, 1.0) glPushMatrix(); glRotatef( 45.0, 0.0, 0.0, 1.0); draw_head(); glPopMatrix(); (Note that the angles provided to gl functions are expressed in degrees instead of radians.) Progressive Rotation

First to scale( Sx =1.5, Sy =2) and then translate the picture to (-2, -1). Note that the transformations are specified in reverse order: first call glTranslatef(...), and then glScalef(…) CTM Vertices 

Progressive (Scaling + Translation) The program glPushMatrix(); glTranslatef( -2.0, -1.0, 0.0); glScalef( 1.5, 2.0, 1.0); draw_head(); glPopMatrix(); Progressive (Scaling + Translation)

Scaling relative to a fix point //Scaling relative to the //apex of the nose at (xf, yf) glPushMatrix(); glTranslatef( xf, yf, 0.0); glScalef( sx, sy, 1); glTranslatef( -xf, -yf, 0); draw_head(); glPopMatrix(); (xf, yf) Scaling relative to a fix point

Rotation about a pivot point //Rotate 90 degree about //the apex of the nose glPushMatrix(); glTranslatef( xf, yf, 0.0); glRotatef( 90., 0.0, 0.0, 1.0); glTranslatef( -xf, -yf, 0); draw_head(); glPopMatrix(); (xf, yf) Rotation about a pivot point

Reflection about the x axis The transformation matrix is the same as scaling matrix with Sx = 1 and Sy = 1. Thus, the reflection about the x axis can be achieved by calling glScalef( 1.0, -1.0, 1.0) Similarly, the reflection about the y axis is achieved by calling glScalef( -1.0, 1.0, 1.0) (x,y) (x,-y)

Reflection about x-axis Example glPushMatrix(); glScalef( 1, -1, 1); draw_head(); glPopMatrix(); Reflection about x-axis

Reflection along a line y =mx+b Reflection along a line Translate (0, -b) so that the line passes through the origin Rotate the line onto the x axis by -o Reflect about the x axis Backward rotate backward translate (Be reminded that these operations must be specified in reverse order.) b 

Reflection against an arbitrary line // To draw the reflection of the head about y = 2x + 0.5 // (we need to convert theta from radians to degrees) double m = 2.0, b = .5, theta = atan(m)*180.0/3.1416; glPushMatrix(); glTranslatef( 0, b, 0.); glRotatef( theta, 0.0, 0.0, 1.0); glScalef( 1, -1, 1); //Reflect glRotatef( -theta, 0.0, 0.0, 1.0); glTranslatef( 0, -b, 0.); draw_head(); glPopMatrix(); Reflection against an arbitrary line

Summary In this lecture we have taken a look at: 2D Transformations Translation Scaling Rotation Homogeneous coordinates Matrix multiplications Combining transformations Next time we’ll start to look at how we take these abstract shapes etc and get them on-screen

Equations xnew = xold + dx ynew = yold + dy Translation: Scaling: xnew = Sx × xold ynew = Sy × yold Rotation xnew = xold × cosθ – yold × sinθ ynew = xold × sinθ + yold × cosθ

Komputer Grafik Departemen Ilmu Komputer FMIPA-IPB 2011 Terima Kasih Komputer Grafik Departemen Ilmu Komputer FMIPA-IPB 2011 41

Exercises 1 Translate the shape below by (7, 2) y (2, 3) (1, 2) (3, 2) 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 2) (3, 2) (2, 1) x

Exercises 2 Scale the shape below by 3 in x and 2 in y y (2, 3) (1, 2) 1 2 3 4 5 6 7 8 9 10 (2, 3) (1, 2) (3, 2) (2, 1) x

Exercises 3 Rotate the shape below by 30° about the origin y (7, 3) 1 2 3 4 5 6 7 8 9 10 (7, 3) (6, 2) (8, 2) (7, 1) x

Exercise 4 Write out the homogeneous matrices for the previous three transformations Translation Scaling Rotation

Exercises 5 Using matrix multiplication calculate the rotation of the shape below by 45° about its centre (5, 3) x y 1 2 3 4 5 6 7 8 9 10 (5, 4) (6, 3) (4, 3) (5, 2)