h si Sistem cartezian
int main()
{
printf("Limitele domeniului orizontal:\n");
printf("Atentie, x_1<0<x_2 si y_1<0<y_2 \n");
printf("x_1="); scanf("%f", &x_1); //x_1<0<x_2
printf("x_2="); scanf("%f", &x_2);
printf("Limitele domeniului vertical:\n");
printf("y_1="); scanf("%f", &y_1); //y_1<0<y_2
printf("y_2="); scanf("%f", &y_2);
initwindow(800, 600, "AXE", 200, 200);
setbkcolor(BLACK);
cleardevice();
a = getmaxx(); //nr. maxim de pixeli pe coord. x
b = getmaxy();
axe();
getch();
closegraph();
return 0;
}
Laborator II. Reprezentari 2D parametrice
I. Cartezian.
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <windows.h>
#include <iostream>
void cerc() {
float theta = 0;
float x, y;
float pas = 0.001 ;
float raza = 1;
while (theta <= 2 * pi) {
x = raza * cos(theta);
y = raza * sin(theta);
putpixel(xe(x), ye(y), 14);
theta = theta + pas;
}
}
int main()
{
printf("Limitele domeniului orizontal:\n");
printf("Atentie, x_1<0<x_2 si y_1<0<y_2 \n");
printf("x_1="); scanf("%f", &x_1); //x_1<0<x_2
printf("x_2="); scanf("%f", &x_2);
printf("Limitele domeniului vertical:\n");
printf("y_1="); scanf("%f", &y_1); //y_1<0<y_2
printf("y_2="); scanf("%f", &y_2);
initwindow(800, 800, "AXE", 200, 200);
setbkcolor(BLACK);
cleardevice();
a = getmaxx(); //nr. maxim de pixeli pe coord. x
b = getmaxy();
axe();
getch();
closegraph();
return 0;
}
Laborator III. Transformari ale unui punct in 2D.
int a, b;
int xe(float x)// normalizarea coordonatei x
{
return((int)((x - x_1) / (x_2 - x_1) * a));
}
int ye(float y)// normalizarea coordonatei y
{
return((int)((y_2 - y) / (y_2 - y_1) * b));
}
void axe() {
setcolor(WHITE);
outtextxy(xe(x_2) - 20, ye(0) - 20, "x");
outtextxy(xe(x_2) - 18, ye(0) - 8, ">");
outtextxy(xe(0) - 15, ye(y_2) + 15, "y");
outtextxy(xe(0) - 15, ye(0) - 15, "O");
outtextxy(xe(0) - 1, ye(y_2)-3, "^");
line(xe(x_1), ye(0), xe(x_2), ye(0));
line(xe(0), ye(y_1), xe(0), ye(y_2));
}
void simetrie(); // Pentru simetrie, dam ca input scalarii: -1,1 sau 1,-1 sau -1-1.
void rotatie2D()
{
float xaa = xa;
float xbb = xb;
float xcc = xc;
xa = xa * cos(theta) - ya * sin(theta);
ya = xaa * sin(theta) + ya * cos(theta);
xb = xb * cos(theta) - yb * sin(theta);
yb = xbb * sin(theta) + yb * cos(theta);
xc = xc * cos(theta) - yc * sin(theta);
yc = xcc * sin(theta) + yc * cos(theta);
}
int main()
{
/////////////////////////////////////////////
printf("Limitele domeniului orizontal:\n");
printf("Atentie, x_1<0<x_2 si y_1<0<y_2 \n");
printf("x_1="); scanf("%f", &x_1); //x_1<0<x_2
printf("x_2="); scanf("%f", &x_2);
printf("Limitele domeniului vertical:\n");
printf("y_1="); scanf("%f", &y_1); //y_1<0<y_2
printf("y_2="); scanf("%f", &y_2);
initwindow(800, 800, "AXE", 200, 200);
setbkcolor(BLACK);
cleardevice();
a = getmaxx(); //nr. maxim de pixeli pe coord. x
b = getmaxy();
axe();
//////////////////////////////////////////////
xa = 7; ya = 10;//initializare coord triunghi
xb = 10; yb = 4;
xc = 1; yb = 1;
float sum_t = 0.f;
///////////////////////////////////////////////
// Pentru translatie si scalare:
do
{
cleardevice();
axe();
deseneazatriunghi();
delay(500);
scalare(2,3);
sum_t = sum_t + theta;
} while (sum_t <= 2);
// Pentru rotatie:
//do
//{
// cleardevice();
// axe();
// deseneazatriunghi();
// delay(100);
// rotatie2D();
// sum_t = sum_t + theta;
//} while (sum_t <= 2 * pi);
getch();
closegraph();
return 0;
}
Laborator III. Reprezentari 3D
I. Axe. In primul rand, avem 3 axe in loc de 2. In loc de axa Y vom avea axa Z (z-ul va fi cel
vertical). Atentie, in cod vom defini doar axa x si z iar y-ul il vom desena in functie de x si z.
#include "graphics.h"
#include <math.h>
#include <stdlib.h>
#include <dos.h>
#include <windows.h>
#include <iostream>
using namespace std;
#define pi 3.14159265359
float x_1, x_2, y_1, y_2, alfa = 3.1415 / 8;
int xemax, yemax;
///////////////////////////////////////////////////////////
int xe(float x)
// normalizarea coordonatei x
{
return((int)floor((x - x_1) / (x_2 - x_1) * xemax)); // Aici definim cele doua
axe X si Z
}
int ze(float z)
// normalizarea coordonatei y
{
return((int)floor((y_2 - z) / (y_2 - y_1) * yemax));
}
///////////////////////////////////////////////////////////
void axe()
{
setcolor(0);
line(xe(x_1 / 2), ze(0), xe(x_2), ze(0));
line(xe(0), ze(0), xe(0), ze(y_2));
line(xe(0), ze(0), xe(0 + x_1 * cos(alfa)), ze(0 + x_1 * sin(alfa))); // Aici
desenam axele. Axa Y va fi desenata folsindu-ne de un unghi
outtextxy(xe(0) - 15, ze(0) - 15, "O");
Translatie.
[1 0 0 xtr] [x]
[0 1 0 ytr]*[y]
[0 0 1 ztr] [z]
[0 0 0 1] [1]
Scalare.
[xsc 0 0 0] [x]
[0 ysc 0 0]*[y]
[0 0 zsc 0] [z]
[0 0 0 1] [1]
Rotatie.
a) In raport cu axa Z: [cosθ sinθ 0 0] [x]
[-sinθ cosθ 0 0] * [y]
[0 0 1 0] [z]
[0 0 0 1] [1]