Sunteți pe pagina 1din 8

Universitatea Tehnic a Moldovei

Facultatea Calculatoare Informatic i


Microelectronic

Raport
La disciplina: Grafica pe calculator
Tema: TRANSFORMRI GEOMETRICE A IMAGINILOR

A efectuat:

Gori

A verificat:

Plotnic Constantin

Chiinu 2012

Victor

Scopul lucrrii: Obinerea cunotinelor practice n realizarea transformrilor geometrice 2D i 3D a


imaginilor
Sarcina lucrrii:
1. Elaborarea programului de rotire, scalare i deplasare a imaginilor n plan i n spaiu
a) Extragei la ecran un triunghi de culoarea R
b) Extragei la ecran un ptrat de culoarea S
c) ndeplinii transformarea tuturor punctelor de culoarea S n conformitate cu variantele (tabela 2).
Punctul ce se deplaseaz se recoloreaz n culoarea R. Pentru determinarea culorii punctului folosii
procedura GetPixel.
Rotirea s fie efectuat n jurul unui punct oarecare din spaiul coordonatelor ecran
Tabela 2. Variantele de ndeplinire a lucrrii
Nr.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Listingul programului:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
#include <graphics.h>
int cul;
using namespace std;
class patrat
{

Rotirea cu
unghiul
25
60
45
100
120
180
35
200
300
310
260
100
70
80
130
240
320
280
245
150

Coeficientul de Deplasarea
scalare
X i Y
0.5
10, 20
1.2
10, 30
1.6
20, 40
2.2
30, 40
0.8
100,100
2.0
10, 20
1.45
15, 25
1.8
25, 30
1.3
200, 20
2.1
100, 30
2.7
10,100
1.85
100, 10
0.4
30, 40
1.4
25, 45
0.6
28, 41
1.7
5, 20
0.8
32, 15
1.9
80, 64
1.25
240, 32
1.65
230, 50

public:
int tab[10];
int ini1, ini2;
void scal(int *s,int x,int y,int z)
{
for(int k=0;k<10;k+=2)
{
tab[k]=(int)(s[k]-x)*1.2+x;
tab[k+1]=(int)(s[k+1]-y)*2.2+y;
}

drawpoly(5,tab);
setfillstyle(1,cul);
floodfill(tab[0]+1,tab[1]+1, WHITE);
}
void rot(int *s,int x,int y,double i,int z)
{
for(int k=0;k<10;k+=2)
{
tab[k]=(int)((s[k]-x)*cos(i)-(s[k+1]-y)*sin(i)+x);
tab[k+1]=(int)((s[k]-x)*sin(i)+(s[k+1]-y)*cos(i)
+y);
}
drawpoly(5,tab);
setfillstyle(1,cul);
floodfill(350,140,WHITE);}
void depl(int *s,int z)
{
for(int k=0;k<10;k+=2)
{
tab[k]=s[k]+10;
tab[k+1]=s[k+1]+30;
}
drawpoly(5,tab);
setfillstyle(1,cul);
floodfill(tab[0]+1,tab[1]+1,WHITE);
floodfill(450,370,WHITE);
}
};
int main()
{
initwindow(900,700,"Exe");
patrat p;
int maxx,maxy,a=450,b=400;

double i=(100*3.1415)/180;
int x[10];
int tabel[8]={700,150,800,25,600,25,700,150};
drawpoly(4,tabel);//Desenam triunghiul
setfillstyle(1,GREEN);
floodfill(700,100,WHITE);
cul=getpixel(700,100);
int k;
int
s[10]={400,300,400,350,450,350,450,300,400,300
};
drawpoly(5,s);//Desenam patratul fix
setfillstyle(1,1);
floodfill(410,310,WHITE);
while(true){
outtextxy(10,10,"1 - Scalarea");
outtextxy(10,30,"2 - Deplasarea");
outtextxy(10,50,"3 - Rotatia");
switch(getch()){
case '1':
p.scal(s,a,b,k);
break;
case '2':
p.depl(s,k);
break;
case '3':
p.rot(s,a,b,i,k);
break;
default: return 0;}}
getch();
return 0;
}

REZULTATUL:

Sarcina Nr.2

Rotirea unui obiect n jurul unei axe:


a)
Desenarea unui cub specificat prin coordonatele vrfurilor sale
b) Rotirea cubului n jurul axelor orizontal i vertical care trec prin centrul sau, precum i n jurul axei
OZ

Listingul programului:
#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <windows.h>
#include <graphics.h>
#define pi 0.0175
#define raza 50
using namespace std;
int ini1, ini2;
void axe(int maxx,int maxy)
{
setcolor(WHITE);
outtextxy(maxx/2+5,maxy/2+5,"0");
outtextxy(maxx/2-20,maxy/2-155,"Y");
outtextxy(maxx/2+145,maxy/2+5,"X");
outtextxy(maxx/2-100,maxy/2+105,"Z");
line(maxx/2,maxy/2,maxx/2+150,maxy/2);
line(maxx/2+150,maxy/2,maxx/2+145,maxy/2-5);
line(maxx/2+150,maxy/2,maxx/2+145,maxy/2+5);
line(maxx/2,maxy/2,maxx/2,maxy/2-150);
line(maxx/2,maxy/2-150,maxx/2+5,maxy/2150+5);
line(maxx/2,maxy/2-150,maxx/2-5,maxy/2150+5);
line(maxx/2,maxy/2,maxx/2-100,maxy/2+100);
line(maxx/2-100,maxy/2+100,maxx/2100,maxy/2+100-7);
line(maxx/2-100,maxy/2+100,maxx/2100+7,maxy/2+100);
}
void cubX ( int i, int ini1, int ini2 )
{
line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+90)));
line(ini1+raza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+
90)),ini1+raza*cos(pi*(i+180)),ini2+raza*sin(pi*(i
+180)));

ini1+=35;
line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+90)));
line(ini1+raza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+
90)),ini1+raza*cos(pi*(i+180)),ini2+raza*sin(pi*(i
+180)));
line(ini1+raza*cos(pi*(i+180)),ini2+raza*sin(pi*(i
+180)),ini1+raza*cos(pi*(i+270)),ini2+raza*sin(pi
*(i+270)));
line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i-90)),ini2+raza*sin(pi*(i-90)));
line(ini135+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+raza*c
os(pi*i), ini2+raza*sin(pi*i));
line(ini135+raza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+90)),i
ni1+raza*cos(pi*(i+90)),
ini2+raza*sin(pi*(i+90)));
line(ini135+raza*cos(pi*(i+180)),ini2+raza*sin(pi*(i+180))
, ini1+raza*cos(pi*(i+180)),
ini2+raza*sin(pi*(i+180)));
line(ini1-35+raza*cos(pi*(i90)),ini2+raza*sin(pi*(i-90)),ini1+raza*cos(pi*(i90)), ini2+raza*sin(pi*(i-90)));
}
void cubY ( int i, int ini1, int ini2 )
{
line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i+90)), ini2+raza*sin(pi*(i+90)));
line(ini1+raza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+
90)),ini1+raza*cos(pi*(i+180)),
ini2+raza*sin(pi*(i+180)));
line(ini1+raza*cos(pi*(i+180)),ini2+raza*sin(pi*(i
+180)),ini1+raza*cos(pi*(i+270)),
ini2+raza*sin(pi*(i+270)));

line(ini1+raza*cos(pi*(i+180)),ini2+raza*sin(pi*(i
+180)),ini1+raza*cos(pi*(i+270)),ini2+raza*sin(pi
*(i+270)));

line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i-90)), ini2+raza*sin(pi*(i-90)));
ini2+=30;
ini1-=30;

line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i-90)),ini2+raza*sin(pi*(i-90)));

line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+90)));

line(ini1+raza*cos(pi*(i+90)),ini2+raza*sin(pi*(i+
90)),ini1+raza*cos(pi*(i+180)),
ini2+raza*sin(pi*(i+180)));
line(ini1+raza*cos(pi*(i+180)),ini2+raza*sin(pi*(i
+180)),ini1+raza*cos(pi*(i+270)),
ini2+raza*sin(pi*(i+270)));
line(ini1+raza*cos(pi*i),ini2+raza*sin(pi*i),ini1+r
aza*cos(pi*(i-90)), ini2+raza*sin(pi*(i-90)));
line(ini1+30+raza*cos(pi*i),ini230+raza*sin(pi*i),ini1+raza*cos(pi*i),
ini2+raza*sin(pi*i));
line(ini1+30+raza*cos(pi*(i+90)),ini230+raza*sin(pi*(i+90)),ini1+raza*cos(pi*(i+90)),
ini2+raza*sin(pi*(i+90)));
line(ini1+30+raza*cos(pi*(i+180)),ini230+raza*sin(pi*(i+180)),
ini1+raza*cos(pi*(i+180)),
ini2+raza*sin(pi*(i+180)));
line(ini1+30+raza*cos(pi*(i-90)),ini230+raza*sin(pi*(i-90)), ini1+raza*cos(pi*(i90)),ini2+raza*sin(pi*(i-90)));
}
void cubZ ( int i, int ini1, int ini2 )
{
line(ini1+raza*cos(pi*i),ini2+raza/3*sin(pi*i),ini1
+raza*cos(pi*(i+90)), ini2+raza/3*sin(pi*(i+90)));
line(ini1+raza*cos(pi*(i+90)),ini2+raza/3*sin(pi*(i
+90)),ini1+raza*cos(pi*(i+180)),
ini2+raza/3*sin(pi*(i+180)));
line(ini1+raza*cos(pi*(i+180)),ini2+raza/3*sin(pi*
(i+180)),ini1+raza*cos(pi*(i+270)),
ini2+raza/3*sin(pi*(i+270)));
line(ini1+raza*cos(pi*i),ini2+raza/3*sin(pi*i),ini1
+raza*cos(pi*(i-90)), ini2+raza/3*sin(pi*(i-90)));
ini2+=70;
line(ini1+raza*cos(pi*i),ini2+raza/3*sin(pi*i),ini1
+raza*cos(pi*(i+90)), ini2+raza/3*sin(pi*(i+90)));
line(ini1+raza*cos(pi*(i+90)),ini2+raza/3*sin(pi*(i
+90)),ini1+raza*cos(pi*(i+180)),
ini2+raza/3*sin(pi*(i+180)));
line(ini1+raza*cos(pi*(i+180)),ini2+raza/3*sin(pi*
(i+180)),ini1+raza*cos(pi*(i+270)),
ini2+raza/3*sin(pi*(i+270)));

line(ini1+raza*cos(pi*i),ini2+raza/3*sin(pi*i),ini1
+raza*cos(pi*(i-90)), ini2+raza/3*sin(pi*(i-90)));
line(ini1+raza*cos(pi*i),ini270+raza/3*sin(pi*i),ini1+raza*cos(pi*i),
ini2+raza/3*sin(pi*i));
line(ini1+raza*cos(pi*(i+90)),ini270+raza/3*sin(pi*(i+90)),ini1+raza*cos(pi*(i+90))
, ini2+raza/3*sin(pi*(i+90)));
line(ini1+raza*cos(pi*(i+180)),ini270+raza/3*sin(pi*(i+180)),
ini1+raza*cos(pi*(i+180)),ini2+raza/3*sin(pi*(i+1
80)));
line(ini1+raza*cos(pi*(i-90)),ini270+raza/3*sin(pi*(i-90)),ini1+raza*cos(pi*(i-90)),
ini2+raza/3*sin(pi*(i-90)));
}
int main()
{
initwindow(900,700,"Laborator 2.2");
//patrat p;
int a=450,b=200,maxx,maxy;
double i=(100*3.1415)/180;
while(true){
outtextxy(10,70,"1 - Rotirea cubului pe axa Oy");
outtextxy(10,90,"2 - Rotirea cubului pe axa Ox");
outtextxy(10,110,"3 - Rotirea cubului pe axa
Oz");
switch(getch()){
case '1':
cleardevice();
maxx=getmaxx();
maxy=getmaxy();
for(i=0 ; ;i++ )
{
setcolor(1);
cubZ(i,maxx/2,maxy/2-120);
Sleep(100);
setcolor(0);//SA RAMIIE INVIZIBIL
cubZ(i,maxx/2,maxy/2-120);
axe(maxx,maxy);
}
getch();
break;
case '2':
cleardevice();
maxx=getmaxx();
maxy=getmaxy();
for(i=0 ; ;i++ )
{
setcolor(3);
cubX(i,maxx/2+60,maxy/2);
Sleep(100);
setcolor(0);//SA RAMIIE INVIZIBIL

cubX(i,maxx/2+60,maxy/2);
axe(maxx,maxy);
}
getch();
break;
case '3':
cleardevice();
maxx=getmaxx();
maxy=getmaxy();
for(i=0 ; ;i++ )
{
setcolor(2);

cubY(i,maxx/2-60,maxy/2+60);
Sleep(100);
setcolor(0);//SA RAMIIE INVIZIBIL
cubY(i,maxx/2-60,maxy/2+60);
axe(maxx,maxy);
}
getch();
break;
default: return 0;}}
getch();
return 0;
}

Rezultatele afisarii:

Concluzie:
In urma efectuarii lucrarii de laborator nr.2 am fauct cunostinta cu transformarile elementare
in 2D si 3D.Respectiv transformarile in 2D au fost: rotatia,translatia si scalarea.In 3D am
folosit rotirea fiecarei linii a cubului in spatiu 3D.