Sunteți pe pagina 1din 4

Ministelul Educaiei al Republicii Moldova

Universitatea Tehnic a Moldovei


Facultatea: Calculatoarea Informatic Microelectronic
Catedra: Calculatoare

RAPORT
despre lucrarea de laborator nr.3
la disciplina: Grafica pe Calculator

Tema: Transformri Geometrice a Imaginilor

A ndeplinit:

A controlat: lect. un. Plotinic C.

Chiinu 2017
Scopul Lucrrii: Obinerea cunotinelor practice n realizarea
transformrilor geometrice 2D i 3D a imaginilor.
Sarcina Lucrrii:
1. De a elabora un program pentru sintetizarea i afiarea graficilor funciilor
conform variantei
Varianta de ndeplinire a lucrrii.
Var 5: y=sin e x ; y=sin x +2 ; y=xsin x
2. S se foloseasc transformarea fereastr-poart.
3. De a prezenta imagini n diferite pori de vizualizare.
Listingul Programului:
package GP.lab3;

import javax.swing.*;
import java.awt.*;

public class MyFrame extends JFrame {


MyJPanel panel;
MyFrame() {
this.setSize(1000, 700);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

this.panel = new MyJPanel();


this.add(panel);

this.setVisible(true);
}
public static void main(String[] args) {
MyFrame frame = new MyFrame();
}
}

class MyJPanel extends JPanel {


private Function f1 = x -> Math.sin(Math.pow(Math.E, x));
private Function f2 = x -> Math.sin(x) + 2;
private Function f3 = x -> x * Math.sin(x);
private Function f4 = x -> Math.sin(x);
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
this.init(g);
Rect window;
window = new Rect(-Math.PI, -1,5 * Math.PI, 1);
this.plotFunction(g, 1, f1, window);
window = new Rect(-2 * Math.PI, -1,2 * Math.PI, 4);
this.plotFunction(g, 3, f2, window);
window = new Rect(-2 * Math.PI, -10,2 * Math.PI, 10);
this.plotFunction(g, 4, f3, window);
}
private void init(Graphics g) {
int width = this.getWidth();
int height = this.getHeight();
g.drawLine(width / 2, 0, width / 2, height);
g.drawLine(0, height / 2, width, height / 2);
g.drawString("Lucrare de laborator: Nr3", 20, 50);
g.drawString("La Tema: Transformarea Fereastra-Poata", 20, 80);
g.drawString("al st. gr. C-151 Cervac Petru", 20, 110);
g.drawString("f1 = sin(e^x)", 20, 140);
g.drawString("f2 = sin(x) + 2", 20, 170);
g.drawString("f3 = x * sin(x)", 20, 200);
}
private void plotFunction(Graphics g, int part, Function func, Rect window) {
int gxm = part == 2 || part == 3 ? 0 : this.getWidth() / 2 ;
int gym = part == 1 || part == 2 ? 0 : this.getHeight() / 2 ;
System.out.println(gxm + " " + gym);
Rect gate = new Rect(gxm, gym, gxm + this.getWidth() / 2, gym + this.getHeight() / 2);

double sx = (gate.xM - gate.xm) / (window.xM - window.xm);


double sy = (gate.yM - gate.ym) / (window.yM - window.ym);
double tx = gate.xm - window.xm * sx;
double dx = (window.xM - window.xm) / (gate.xM - gate.xm);

System.out.printf("dx: %s sx: %s sy: %s tx: %s%n", dx, sx, sy, tx);

int oxp = new Double(window.xm * sx + tx).intValue();


int oyp = new Double(gate.yM - func.f(window.xm) * sy + window.ym * sy).intValue();

g.setColor(Color.RED);
g.drawLine( new Double(window.xm * sx + tx).intValue(),
new Double(gate.yM + window.ym * sy).intValue(),
new Double(window.xM * sx + tx).intValue(),
new Double(gate.yM + window.ym * sy).intValue());
g.drawLine( new Double(tx).intValue(),
new Double(gate.yM - window.ym * sy + window.ym * sy).intValue(),
new Double(tx).intValue(),
new Double(gate.yM - window.yM * sy + window.ym * sy).intValue());

g.setColor(Color.black);
for (double i = window.xm; i < window.xM; i += dx) {
int xp = new Double(i * sx + tx).intValue();
int yp = new Double(gate.yM - func.f(i) * sy + window.ym * sy).intValue();
System.out.printf("xp: %d yp: %d %f%n", xp, yp, func.f(i));
if (oyp >= window.ym && oyp <= window.yM && yp >= window.ym && yp <=
window.yM)
g.drawLine(oxp, oyp, xp, yp);
oxp = xp;
oyp = yp;
}
}
}
class Rect {
double xm;
double ym;
double xM;
double yM;
Rect(double xm, double ym, double xM, double yM) {
this.xm = xm;
this.ym = ym;
this.xM = xM;
this.yM = yM;
}
}

interface Function{
Double f(double x);
}

Verificare:

Concluzie: n aceast lucrare de laborator am studiat transformarea fereastr-


poart pentru trasarea graficilor funciilor. Am trasat graficile funciilor n diferite
cadrane ale ferestrei

S-ar putea să vă placă și