TITIK A
Xn = Xp+(X-Xp) cos Ɵ – (y – Yp) sin Ɵ
= 200 +(50-200)* 0.8 – (150-200)*0.6 =110
Yn = Yp + (X-Xp) sinƟ+ ( y-Yp)cos Ɵ
= 200 + (50-200)*0.6- (150-200)*0.8 = 150
TITIK B
Xn = Xp+(X-Xp)Cos Ɵ – ( y- Yp)sin Ɵ
= 200 + (150-200)*0.8 –
(100-200)*0.6=220
yn = Yp + (X-Xp) sinƟ+ ( y-Yp)cos Ɵ
= 200 + (150-200)*0.6 –
(100-200)*0.8 = 250
TITIK C
Xn = Xp+(X-Xp)Cos Ɵ – ( y- Yp)sin Ɵ
= 200 + ( 150 –
200)*0.8 – (200 – 200)*0.6 =160
yn = Yp + (X-Xp) sinƟ+ ( y-Yp)cos Ɵ
= 200+ ( 150 – 200)*0.6
– (200 -200)* 0.8 = 170
TRANSLASI
A.
X” = 50 + 50
=
100
Y”= 150 +(-70)
= 75
X” = (100,75)
B.
X’ = 150 +
50
=
200
Y’= 100 + (-75)
= 25
B’ = (200,25)
C.
X’ = 150 +
50
=
200
Y’ = 200 + (-75)
=
125
C’= (200,125)
TITIK A
Xn = Xp+(X-Xp) cos Ɵ – (y – Yp) sin Ɵ
= 200 +(50-200)* 0.8 – (150-200)*0.6 =110
Yn = Yp + (X-Xp) sinƟ+ ( y-Yp)cos Ɵ
= 200 + (50-200)*0.6- (150-200)*0.8 = 150
TITIK B
Xn = Xp+(X-Xp)Cos Ɵ – ( y- Yp)sin Ɵ
= 200 + (150-200)*0.8 –
(100-200)*0.6=220
yn = Yp + (X-Xp) sinƟ+ ( y-Yp)cos Ɵ
= 200 + (150-200)*0.6 –
(100-200)*0.8 = 250
TITIK C
Xn = Xp+(X-Xp)Cos Ɵ – ( y- Yp)sin Ɵ
= 200 + ( 150 – 200)*0.8 – (200
– 200)*0.6 =160
yn = Yp + (X-Xp) sinƟ+ ( y-Yp)cos Ɵ
= 200+ ( 150 – 200)*0.6 – (200
-200)* 0.8 = 170
TRANSLASI
A. X” = 50 + 50
= 100
Y” = 150 +(-70)
= 75
X” = (100,75)
B. X’ = 150 + 50
= 200
Y’ = 100 + (-75)
= 25
B’ = (200,25)
C. X’ = 150 + 50
= 200
Y’ = 200 + (-75)
= 125
C’ = (200,125)
2. Listing
Program Rotasi
package
projeckomputer.grafik;
import java.awt.*;
import java.awt.event.*;
public class ProjecKomputerGrafik extends Frame implements ActionListener{
int x = 200;
int y = 200;
public static void main(String[] args) {
Frame frame = new ProjecKomputerGrafik();
frame.setSize(640, 480);
frame.setVisible(true);
}
public ProjecKomputerGrafik() {
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) {
x = ev.getX();
y = ev.getY();
repaint();
}
};
addMouseListener(mouseListener);
}
public void paint(Graphics g) {
int xasalA = 50; int yasalA = 150;
int xasalB = 150; int yasalB = 100;
int xasalC = 150; int yasalC = 200;
int sudut = -40;
double phi=22/7;
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*phi/40)-(yasalA-y)*Math.sin(sudut*phi/40));
long yA = Math.round(x+(xasalA-x)*Math.sin(sudut*phi/40)-(yasalA-y)*Math.cos(sudut*phi/40));
long xB = Math.round(x+(xasalB-x)*Math.cos(sudut*phi/40)-(yasalB-y)*Math.sin(sudut*phi/40));
long yB = Math.round(x+(xasalB-x)*Math.sin(sudut*phi/40)-(yasalB-y)*Math.cos(sudut*phi/40));
long xC = Math.round(x+(xasalC-x)*Math.cos(sudut*phi/40)-(yasalC-y)*Math.sin(sudut*phi/40));
long yC = Math.round(x+(xasalC-x)*Math.sin(sudut*phi/40)-(yasalC-y)*Math.cos(sudut*phi/40));
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);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
import java.awt.*;
import java.awt.event.*;
public class ProjecKomputerGrafik extends Frame implements ActionListener{
int x = 200;
int y = 200;
public static void main(String[] args) {
Frame frame = new ProjecKomputerGrafik();
frame.setSize(640, 480);
frame.setVisible(true);
}
public ProjecKomputerGrafik() {
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) {
x = ev.getX();
y = ev.getY();
repaint();
}
};
addMouseListener(mouseListener);
}
public void paint(Graphics g) {
int xasalA = 50; int yasalA = 150;
int xasalB = 150; int yasalB = 100;
int xasalC = 150; int yasalC = 200;
int sudut = -40;
double phi=22/7;
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*phi/40)-(yasalA-y)*Math.sin(sudut*phi/40));
long yA = Math.round(x+(xasalA-x)*Math.sin(sudut*phi/40)-(yasalA-y)*Math.cos(sudut*phi/40));
long xB = Math.round(x+(xasalB-x)*Math.cos(sudut*phi/40)-(yasalB-y)*Math.sin(sudut*phi/40));
long yB = Math.round(x+(xasalB-x)*Math.sin(sudut*phi/40)-(yasalB-y)*Math.cos(sudut*phi/40));
long xC = Math.round(x+(xasalC-x)*Math.cos(sudut*phi/40)-(yasalC-y)*Math.sin(sudut*phi/40));
long yC = Math.round(x+(xasalC-x)*Math.sin(sudut*phi/40)-(yasalC-y)*Math.cos(sudut*phi/40));
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);
}
public void actionPerformed(ActionEvent ev) {
String command = ev.getActionCommand();
if ("Exit".equals(command)) {
System.exit(0);
}
}
}
Tidak ada komentar:
Posting Komentar