Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran COMPUTER GRAPHICS D10K-5C01 Seemster Ganjil 2016-2017 GK04a: Transformasi 2D Menggunakan C# Dr. Setiawan Hadi, M.Sc.CS. Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
Proses Transformasi
Langkah Transformasi
Sistem Koordinat Graphics g = e.Graphics; Point A = new Point(0, 0); Point B = new Point(120, 80); g.DrawLine(Pens.Black, A, B);
Translasi Koordinat Graphics g = e.Graphics; g.TranslateTransform(50, 40); Point A = new Point(0, 0); Point B = new Point(120, 80); g.DrawLine(Pens.Black, A, B);
Ukuran Pen dan Satuan g.PageUnit = GraphicsUnit.Inch; g.DrawLine(Pens.Black, 0, 0, 2, 1);
Operasi Matriks pada C# Before using the Matrix class in your applications, you need to add a reference to the System.Drawing.Drawing2D namespace. Matrix M1 = new Matrix(); Matrix M2 = new Matrix(2, 1, 3, 1, 0, 4); Matrix M3 = new Matrix(0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f);
Beberapa Properties Class Matrix Elements IsIdentity InInvertible OffsetX OffsetY
Contoh 1 private void InvertMenu_Click(object sender, System.EventArgs e) { string str = "Original values: "; Matrix X = new Matrix(2, 1, 3, 1, 0, 4); for(int i=0; i<X.Elements.Length; i++) { str += X.Elements[i].ToString(); str += ", "; } str += "\n"; str += "Inverted values: "; X.Invert(); float[] pts = X.Elements; for(int i=0; i<pts.Length; i++) { str += pts[i].ToString(); str += ", "; } MessageBox.Show(str); }
Contoh 2 private void MultiplyMenu_Click(object sender, System.EventArgs e) { string str = null; Matrix X = new Matrix(2.0f, 1.0f, 3.0f, 1.0f, 0.0f, 4.0f); Matrix Y = new Matrix(0.0f, 1.0f, -1.0f, 0.0f, 0.0f, 0.0f); X.Multiply(Y, MatrixOrder.Append); for(int i=0; i<X.Elements.Length; i++) { str += X.Elements[i].ToString(); str += ", "; } MessageBox.Show(str); }
Rotasi Pusat (50,50) private void rotasi_Click(object sender, System.EventArgs e) { Graphics g = this.CreateGraphics(); g.TranslateTransform(50,50); g.DrawLine(new Pen(Color.Green, 3), new Point(0, 0), new Point(200, 50)); g.RotateTransform(45); g.DrawLine(new Pen(Color.Yellow, 3), g.Dispose(); }
Rotasi
Pengantar Ingat kembali program menggambar titik Buat program grafis yang mampu Menggambar objek grafis dalam GDI+ Melakukan transformasi terhadap objek grafis Translasi Rotasi Refleksi Scaling Shear