-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcardiod.cpp
70 lines (57 loc) · 1.89 KB
/
cardiod.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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int graphHeight, graphWidth, radius, angle, aspectedGraphHeight, row, column, x, y, angleStep;
char cardoid[150][150];
cout<<"\n\n\t\t\t###### Draw circle #######\n";
cout << "\n\t\tEnter graph Height: ";
cin >> graphHeight;
cout << "\t\tEnter graph Width: ";
cin >> graphWidth;
cout << "\t\tRadius of circle: ";
cin >> radius;
//converting degree to radian by multiplying with pi/180
angle = angle * M_PI/180;
//graphHeight is divided by scaling factor 2 for aspected ratio of characters in terminal
//.5 is for precision
aspectedGraphHeight = graphHeight/2 + .5;
// 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 circle
for (angle = 0; angle <= 200; angle += 1)
{
x = radius * (2.0*cos(angle) - cos(2.0*angle))+.5;
y = radius * (2.0*sin(angle) - sin(2.0*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;
}
}