-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharcOfCircle.cpp
76 lines (62 loc) · 2.04 KB
/
arcOfCircle.cpp
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
#include <iostream>
#include <cmath>
using namespace std;
int graphHeight, graphWidth, aspectedGraphHeight, row, column, radius, x, y;
double startAngle, endAngle, angle, angleStep;
char circle[150][150];
int main(void)
{
cout<<"\n\n\t\t\t###### Draw Arc of Circle #######\n";
cout << "\n\t\tEnter graph Height: ";
cin >> graphHeight;
cout << "\t\tEnter graph Width: ";
cin >> graphWidth;
cout << "\t\tRadius of circle: ";
cin >> radius;
cout << "\t\tEnter starting Angle of arc: ";
cin >> startAngle;
cout << "\t\tEnter End Angle of arc: ";
cin >> endAngle;
aspectedGraphHeight = graphHeight/2 + .5;
//graphHeight is divided by scaling factor 2 for aspected ratio of characters in terminal
startAngle *= M_PI/180.;
endAngle *= M_PI/180.;
angleStep = (2* M_PI)/(2 * 2 * radius); //2 * 2 *radius = no. of dots
// define graphpaper
for(row=0; row<=aspectedGraphHeight; row++)
{
for(column=0; column<=graphWidth; column++)
{
circle[row][column]=' ';
}
}
//horizontal axis
for(column = 0; column <= graphWidth; column++)
{
row = aspectedGraphHeight / 2;
circle[row][column] = '-';
}
//vertical axis
for(row = 0; row <= aspectedGraphHeight; row++)
{
column = graphWidth / 2;
circle[row][column] = '|';
}
//points of arc
for (angle = startAngle; angle <= endAngle; angle += angleStep)
{
x = radius * cos(angle) +.5;
y = radius * sin(angle) +.5;
row = (aspectedGraphHeight/2 - y/2 +.5);
// y is divided by scaling factor 2 for aspected ratio of characters in terminal
column = graphWidth/2 + x;
circle[row][column] = '.';
}
//print circle
for(row = 0; row<=aspectedGraphHeight; row++)
{
for(column = 0; column<=graphWidth; column++)
cout << circle[row][column];
cout<<endl;
}
}