Sunteți pe pagina 1din 7

Universitatea Tehnica a Moldovei

Facultatea Calculatoare, Informatic i Microelectronic

Raport
Lucrarea de laborator .2
la disciplina Grafica pe Calculator

Tema: Transformri geometrice a imaginilor

A efectuat:

A verificat: lector superior Plotnic Constantin

Chiinu 2017
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. Rotirea cu Coeficientul de Deplasarea


unghiul scalare X i Y
4 25 0.5 10, 20

2. Rotirea unui obiect n jurul unei axe


3. 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.

Exercitiul 1
#include <stdio.h>

#include <conio.h>

#include <graphics.h>

#include <math.h>

#define R GREEN

#define S BLUE

void main() {

int gdriver = DETECT, gmode, errorcode;

initgraph(&gdriver, &gmode, "D:\\TC\\BGI");

errorcode = graphresult();

if (errorcode != grOk) {

printf("Graphics error: %s\n", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

return;

int triunghi[6] = {480, 30, 420, 70, 515, 60};

setfillstyle(1, R);
fillpoly(3, triunghi);

int patrat[8] = {250, 200, 310, 200, 310, 260, 250, 260};

setfillstyle(1, S);

fillpoly(4, patrat);

int temp[8]; //copie a patratului

int pxRot = 100;//punctul de rotatie x,y

int pyRot = 100;

float u = 25*M_PI/180; //unghiul de rotatie

line(pxRot-2, pyRot-2, pxRot+2, pyRot+2); //deseneaza punctul,cruciulita

line(pxRot-2, pyRot+2, pxRot+2, pyRot-2);

outtextxy(pxRot+4, pyRot-4, "r");

for (int i = 0; i < 8; i+=2) {

// rotim patratului,

temp[i] = (patrat[i]-pxRot)*cos(u) - (patrat[i+1]-pyRot)*sin(u) + pxRot;

temp[i+1] = (patrat[i]-pxRot)*sin(u) + (patrat[i+1]-pyRot)*cos(u) + pyRot;

setfillstyle(1, R);

fillpoly(4, temp);

int pxScal = 100; //PUN SCAL

int pyScal = 180;

double scalare = 0.5;

line(pxScal-2, pyScal-2, pxScal+2, pyScal+2);

line(pxScal-2, pyScal+2, pxScal+2, pyScal-2);

outtextxy(pxScal+4, pyScal-4, "s");

for (i = 0; i < 8; i+=2) {

// asa,mutam punctele de scalare

temp[i] = (patrat[i]-pxScal)*scalare + pxScal;

temp[i+1] = (patrat[i+1]-pyScal)*scalare + pyScal;

setfillstyle(1, R);

fillpoly(4, temp);

int depx = 10;

int depy = 20;


for (i = 0; i < 8; i+=2) {

temp[i] = patrat[i] + depx;

temp[i+1] = patrat[i+1] + depy;

setfillstyle(1, R);

fillpoly(4, temp);

getch();

closegraph();

Exercitiul 2
#include<graphics.h> line(300,250,170,380);}
#include<conio.h> void cub()
#include<math.h> { Rxx=15;
int i; Ryx=45;
float Rxy=45;
xx[8],yx[8],Rxx,Ryx,xy[8],yy[8],Rxy,Ry Ryy=15;
y,xz[8],yz[8],Rxz,Ryz,angle; Rxz=40;
void border() Ryz=40;
{rectangle(2,2,638,478);} angle=0;
void axes() setbkcolor(BLUE);
{ line(300,250,500,250); setcolor(4);
line(300,250,300,50); do
{xx[0]=430+Rxx*cos(angle); line(xx[1],yx[1],xx[5],yx[5]);
xx[1]=430+Rxx*cos(angle+M_PI/2); line(xx[2],yx[2],xx[6],yx[6]);
xx[2]=430+Rxx*cos(angle+M_PI); line(xx[3],yx[3],xx[7],yx[7]);
xx[3]=430+Rxx*cos(angle+3*M_PI/2); //Cubul pe axa oY
xx[4]=370+Rxx*cos(angle); setcolor(14);
xx[5]=370+Rxx*cos(angle+M_PI/2); line(xy[0],yy[0],xy[1],yy[1]);
xx[6]=370+Rxx*cos(angle+M_PI); line(xy[1],yy[1],xy[2],yy[2]);
xx[7]=370+Rxx*cos(angle+3*M_PI/2); line(xy[2],yy[2],xy[3],yy[3]);
yx[0]=250+Ryx*sin(angle); line(xy[3],yy[3],xy[0],yy[0]);
yx[1]=250+Ryx*sin(angle+M_PI/2); line(xy[4],yy[4],xy[5],yy[5]);
yx[2]=250+Ryx*sin(angle+M_PI); line(xy[5],yy[5],xy[6],yy[6]);
yx[3]=250+Ryx*sin(angle+3*M_PI/2); line(xy[6],yy[6],xy[7],yy[7]);
yx[4]=250+Ryx*sin(angle); line(xy[7],yy[7],xy[4],yy[4]);
yx[5]=250+Ryx*sin(angle+M_PI/2); line(xy[0],yy[0],xy[4],yy[4]);
yx[6]=250+Ryx*sin(angle+M_PI); line(xy[1],yy[1],xy[5],yy[5]);
yx[7]=250+Ryx*sin(angle+3*M_PI/2); line(xy[2],yy[2],xy[6],yy[6]);
xy[0]=300+Rxy*cos(angle); line(xy[3],yy[3],xy[7],yy[7]);
xy[1]=300+Rxy*cos(angle+M_PI/2); //Cubul pe axa oZ
xy[2]=300+Rxy*cos(angle+M_PI); setcolor(11);
xy[3]=300+Rxy*cos(angle+3*M_PI/2); line(xz[0],yz[0],xz[1],yz[1]);
xy[4]=300+Rxy*cos(angle); line(xz[1],yz[1],xz[2],yz[2]);
xy[5]=300+Rxy*cos(angle+M_PI/2); line(xz[2],yz[2],xz[3],yz[3]);
xy[6]=300+Rxy*cos(angle+M_PI); line(xz[3],yz[3],xz[0],yz[0]);
xy[7]=300+Rxy*cos(angle+3*M_PI/2); line(xz[4],yz[4],xz[5],yz[5]);
yy[0]=120+Ryy*sin(angle); line(xz[5],yz[5],xz[6],yz[6]);
yy[1]=120+Ryy*sin(angle+M_PI/2); line(xz[6],yz[6],xz[7],yz[7]);
yy[2]=120+Ryy*sin(angle+M_PI); line(xz[7],yz[7],xz[4],yz[4]);
yy[3]=120+Ryy*sin(angle+3*M_PI/2); line(xz[0],yz[0],xz[4],yz[4]);
yy[4]=180+Ryy*sin(angle); line(xz[1],yz[1],xz[5],yz[5]);
yy[5]=180+Ryy*sin(angle+M_PI/2); line(xz[2],yz[2],xz[6],yz[6]);
yy[6]=180+Ryy*sin(angle+M_PI); line(xz[3],yz[3],xz[7],yz[7]);
yy[7]=180+Ryy*sin(angle+3*M_PI/2); setcolor(15);
xz[0]=270+Rxz*cos(angle); line(300,250,300,50);
xz[1]=270+Rxz*cos(angle+M_PI/2); line(300,250,500,250);
xz[2]=270+Rxz*cos(angle+M_PI); line(300,250,170,380);
xz[3]=270+Rxz*cos(angle+3*M_PI/2); setcolor(0);
xz[4]=240+Rxz*cos(angle); line(xx[0],yx[0],xx[1],yx[1]);
xz[5]=240+Rxz*cos(angle+M_PI/2); line(xx[1],yx[1],xx[2],yx[2]);
xz[6]=240+Rxz*cos(angle+M_PI); line(xx[2],yx[2],xx[3],yx[3]);
xz[7]=240+Rxz*cos(angle+3*M_PI/2); line(xx[3],yx[3],xx[0],yx[0]);
yz[0]=280+Ryz*sin(angle); line(xx[4],yx[4],xx[5],yx[5]);
yz[1]=280+Ryz*sin(angle+M_PI/2); line(xx[5],yx[5],xx[6],yx[6]);
yz[2]=280+Ryz*sin(angle+M_PI); line(xx[6],yx[6],xx[7],yx[7]);
yz[3]=280+Ryz*sin(angle+3*M_PI/2); line(xx[7],yx[7],xx[4],yx[4]);
yz[4]=310+Ryz*sin(angle); line(xx[0],yx[0],xx[4],yx[4]);
yz[5]=310+Ryz*sin(angle+M_PI/2); line(xx[1],yx[1],xx[5],yx[5]);
yz[6]=310+Ryz*sin(angle+M_PI); line(xx[2],yx[2],xx[6],yx[6]);
yz[7]=310+Ryz*sin(angle+3*M_PI/2); line(xx[3],yx[3],xx[7],yx[7]);
//Cubul pe axa oX line(xy[0],yy[0],xy[1],yy[1]);
setcolor(12); line(xy[1],yy[1],xy[2],yy[2]);
line(xx[0],yx[0],xx[1],yx[1]); line(xy[2],yy[2],xy[3],yy[3]);
line(xx[1],yx[1],xx[2],yx[2]); line(xy[3],yy[3],xy[0],yy[0]);
line(xx[2],yx[2],xx[3],yx[3]); line(xy[4],yy[4],xy[5],yy[5]);
line(xx[3],yx[3],xx[0],yx[0]); line(xy[5],yy[5],xy[6],yy[6]);
line(xx[4],yx[4],xx[5],yx[5]); line(xy[6],yy[6],xy[7],yy[7]);
line(xx[5],yx[5],xx[6],yx[6]); line(xy[7],yy[7],xy[4],yy[4]);
line(xx[6],yx[6],xx[7],yx[7]); line(xy[0],yy[0],xy[4],yy[4]);
line(xx[7],yx[7],xx[4],yx[4]); line(xy[1],yy[1],xy[5],yy[5]);
line(xx[0],yx[0],xx[4],yx[4]); line(xy[2],yy[2],xy[6],yy[6]);
line(xy[3],yy[3],xy[7],yy[7]); angle+=0.01;} while(!kbhit());}
line(xz[0],yz[0],xz[1],yz[1]); int main()
line(xz[1],yz[1],xz[2],yz[2]); {int gdriver=DETECT, gmode;
line(xz[2],yz[2],xz[3],yz[3]); initgraph(&gdriver,&gmode,"Lab 2.2");
line(xz[3],yz[3],xz[0],yz[0]); setcolor(2);
line(xz[4],yz[4],xz[5],yz[5]); border();
line(xz[5],yz[5],xz[6],yz[6]); setcolor(15);
line(xz[6],yz[6],xz[7],yz[7]); axes();
line(xz[7],yz[7],xz[4],yz[4]); setcolor(1);
line(xz[0],yz[0],xz[4],yz[4]); cub();
line(xz[1],yz[1],xz[5],yz[5]); getch();
line(xz[2],yz[2],xz[6],yz[6]); closegraph();}
line(xz[3],yz[3],xz[7],yz[7]);
Concluzie: n aceast lucrare de laborator am fcut cunotin cu metodele
de transformare a figurilor 2d i 3d. Am fcut cunotin cu matricile de
tranformare 3d a figurilor. Am efectuat rotirea, scalarea i rotirea a figurilor att
n plan 2d ct i n plan 3d. Cu ajutorul matricilor de tranformare am efectuat
proiectarea isometric a unui obiect 3d n plan 2d.

Evaluare