MIDLE GRAFIK KOMPUTER

Nama : ERMELINDA M.H AMFOTIS
Nim       :11110067
Kelas     :A
Soal :
1.       Rotasikan titik – titik A ,B, C terhadap titik putar (200,200) dengan sudut putar -40 derajat
2.       Move/trqnslasi gambar tersebut terhadap  T[50,-75]
Dari kedua nomor tersebut :
a)      Carilah titik-titik hasil translasi & rotasinya!
b)      Buatlah listing programnya!

Jawab:

1.    Transformasi translasi merupakan suatu operasi yang menyebabkan perpindahan
objek 2D dari satu tempat ke tempat yang lain. Perubahan ini berlaku dalam arah yang sejajar dengan sumbu X dan sumbu Y.

x‟ = x + sx (x,y) = titik asal sebelum diskala
y„= y + sy (x‟,y‟) = titik setelah diskala

Jadi jawabannya:
A=(50,150)
B=(150,100)
C=(150,200)
Tx,Ty=(50,-75)
Rumus:   X’’ =x + tx
                         Y’’ =y + ty
A= x’ =50 + 50 = 100
            Y’=150 + -75 =75
            A’’= (100,75)
B= x’ =150 + 50 = 200
            Y’=100 + -75 =25
            B’’= (200,25)
C = x’ =150 + 50 = 200
            Y’=200 + -75 =125
            A’’= (200,125)




2.    Putaran adalah suatu operasi yang menyebabkan objek bergerak berputar pada titik
pusat atau pada sumbu putar yang dipilih berdasarkan sudut putaran tertentu. Untu
melakukan rotasi diperlukan sudut rotasi dan pivot point (xp,yp) dimana objek akan
dirotasi.
Rotasi dapat dinyatakan dengan :
x‟=r cos( + ) = r cos cos - r sin sin
y‟=r sin ( + ) = r soc sin + r sin cos

sedangkan di ketahui x=
r cos , y = r sin
lakukan subtitusi, maka :
x‟=x cos - y sin
y‟=x sin + y cos
matriks rotasi dinyatakan dengan :
P‟ = R.P
R = cos –sin
sin cos
Rotasi suatu titik terhadap pivot point (xp,yp) :
x‟= xp+(x - xp) cos - (y - yp) sin
y‟= yp+(x - xp) sin + (y - yp) cos

Jadi Jawabannya :
Titik A : x‟= xp+(x - xp) cos - (y - yp) sin
                                    =200 + (50 – 200) * 0.9 – (150 – 200) * 0.3 =60
                        y‟= yp+(x - xp) sin + (y - yp) cos
                                    =200 + (50 – 200) * 0.3 – (150 – 200) * 0.9 =15
                        Titik A’’ =(60,15)
Titik B : x‟= xp+(x - xp) cos - (y - yp) sin
                                    =200 + (150 – 200) * 0.9 – (100 – 200) * 0.3 =125
                        y‟= yp+(x - xp) sin + (y - yp) cos
                                    =200 + (150 – 200) * 0.3 – (100 – 200) * 0.9 =135
                        Titik A’’ =(125,135)
Titik  C : x‟= xp+(x - xp) cos - (y - yp) sin
                                    =200 + (50 – 200) * 0.9 – (200 – 200) * 0.3 =0
                        y‟= yp+(x - xp) sin + (y - yp) cos
                                    =200 + (150 – 200) * 0.3 – (200 – 200) * 0.9 =45
                        Titik A’’ =(0,45)


A.   Listing Program Translasi

package JavaApplication6;

import java.awt.*;
import java.awt.event.*;
public class JavaApplication6 extends Frame implements ActionListener{
    int x = 50;
    int y = -75;
public static void main(String[] args) {
    Frame frame = new JavaApplication6();
    frame.setSize(640, 480);
    frame.setVisible(true);
}
public JavaApplication6() {
setTitle("AWT Demo");
// create menu
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu menu = new Menu("File");
    mb.add(menu);
    MenuItem mi = new MenuItem("Exit");
    mi.addActionListener(this);
    menu.add(mi);
// end program when window is closed
    WindowListener l = new WindowAdapter()  {
    public void windowClosing(WindowEvent ev) {
    System.exit(0);
    }
    };
this.addWindowListener(l);
// mouse event handler
MouseListener mouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent ev) {
   int x = 50;
   int y = -75;
    repaint();
}
};
addMouseListener(mouseListener);
}

public void paint(Graphics g) {

g.drawLine(100, 200, 200, 75);
g.drawLine(75+x, 25+y, 125+x, 300+y);



}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}

Outputnya :


B.   Listing Program Rotasi
package JavaApplication8;

import java.awt.*;
import java.awt.event.*;
public class JavaApplication8 extends Frame implements ActionListener{
    int x = 200;
    int y = 200;
public static void main(String[] args) {
    Frame frame = new JavaApplication8();
    frame.setSize(240, 360);
    frame.setVisible(true);
}
public JavaApplication8() {
setTitle("Membuat rotasi");
// create menu
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu menu = new Menu("File");
    mb.add(menu);
    MenuItem mi = new MenuItem("Exit");
    mi.addActionListener(this);
    menu.add(mi);
// end program when window is closed
    WindowListener l = new WindowAdapter()  {
            @Override
    public void windowClosing(WindowEvent ev) {
    System.exit(0);
    }
    };
this.addWindowListener(l);
// mouse event handler
MouseListener mouseListener = new MouseAdapter() {
            @Override
public void mouseClicked(MouseEvent ev) {
    x = ev.getX();
    y = ev.getY();
    repaint();
}
};
addMouseListener(mouseListener);
}

    @Override
public void paint(Graphics g) {
int xasalA = 60; int yasalA = 15;
int xasalB = 125; int yasalB = 135;
int xasalC =0 ; int yasalC = 45;

int sudut = -40;

g.setColor(Color.blue);
g.drawLine(xasalA,yasalA, xasalB,yasalB);
g.drawLine(xasalB,yasalB,xasalC,yasalC);
long xA = Math.round(x+(xasalA-x)*Math.cos(sudut)-(yasalA-y)*Math.sin(sudut));
long yA = Math.round(x+(xasalA-x)*Math.sin(sudut)-(yasalA-y)*Math.cos(sudut));
long xB = Math.round(x+(xasalB-x)*Math.cos(sudut)-(yasalB-y)*Math.sin(sudut));
long yB = Math.round(x+(xasalB-x)*Math.sin(sudut)-(yasalB-y)*Math.cos(sudut));
long xC = Math.round(x+(xasalC-x)*Math.cos(sudut)-(yasalC-y)*Math.sin(sudut));
long yC = Math.round(x+(xasalC-x)*Math.sin(sudut)-(yasalC-y)*Math.cos(sudut));

int xA1 = (int)xA; int yA1 = (int)yA;
int xB1 = (int)xB; int yB1 = (int)yB;
int xC1 = (int)xC; int yC1 = (int)yC;

g.drawLine(xA1,yA1, xB1,yB1);
g.drawLine(xB1,yB1, xC1,yC1);

}
    @Override
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
Hasil outputnya :


Komentar

Postingan populer dari blog ini

Lirik Lagu Seribu Kota / Walau Sekejap - Ari Wibowo

cara kerja memori

KRITIK MENGENAI TEKNOLOGI MAJU