-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslate_Object_in_2D.cpp
More file actions
39 lines (38 loc) · 992 Bytes
/
Translate_Object_in_2D.cpp
File metadata and controls
39 lines (38 loc) · 992 Bytes
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
// Write a Program to Translate an Object in 2D plane.
#include<bits/stdc++.h>
#include<graphics.h>
using namespace std;
// function to translate line
void translateLine ( int P[][2], int T[])
{
/* init graph and line() are used for
representing line through graphical
functions
*/
int gd = DETECT, gm, errorcode;
initgraph (&gd, &gm, "c:\\tc\\bgi");
// drawing original line using graphics functions
setcolor (2);
line(P[0][0], P[0][1], P[1][0], P[1][1]);
// calculating translated coordinates
P[0][0] = P[0][0] + T[0];
P[0][1] = P[0][1] + T[1];
P[1][0] = P[1][0] + T[0];
P[1][1] = P[1][1] + T[1];
// drawing translated line using graphics functions
setcolor(3);
line(P[0][0], P[0][1], P[1][0], P[1][1]);
int temp;
cin >> temp;
closegraph();
}
// driver program
int main()
{
int P[2][2] = {5, 8, 12, 18}; // coordinates of point
int T[] = {2, 1}; // translation factor
translateLine (P, T);
int temp;
cin >> temp;
return 0;
}