-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtiv_TracarLinha.cpp
More file actions
75 lines (56 loc) · 1.05 KB
/
Ativ_TracarLinha.cpp
File metadata and controls
75 lines (56 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
By:
Jonathan Freitas Ferreira
Program in C++ that draws a Line in a received image
*/
#include "header.h"
Mat TracarLinha(Mat img, int x1, int y1, int x2, int y2){
//Variaveis
float x, y, dx, dy;
//Caso algum valor seja negativo
x1 = Positivar(x1);
x2 = Positivar(x2);
y1 = Positivar(y1);
y2 = Positivar(y2);
//Caso o Axis X final seja maior que o X inicial
if(x1 > x2){
int aux = x1;
x1 = x2;
x2 = aux;
}
//Caso o Axis Y final seja maior que o Y inicial
if(y1 > y2){
int aux = y1;
y1 = y2;
y2 = aux;
}
//Auxiliares
int i, length;
//Eixos absolutos
dx = x2 - x1;
dy = y2 - y1;
//Auxiliar
if(dx >= dy){
length = dx;
}else{
length = dy;
}
dx = dx/(float) length;
dy = dy/(float) length;
x = x1;
y = y1;
i = 1;
while(i <= length){
//putpixel(x,y,WHITE);
img.data[((int) y) * img.rows + (int) x] = 0;
x = x + dx;
y = y + dy;
i++;
}
return img;
/*
//Mostrando resultados
imshow("Linha Mágico", img);
waitKey(0);
*/
}