-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhypocycloid.cpp
72 lines (59 loc) · 2.07 KB
/
hypocycloid.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
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int graphHeight, graphWidth, radius1, radius2, angle, aspectedGraphHeight, row, column, x, y, angleStep;
char hypocycloid[150][150];
cout<<"\n\n\t\t\t###### Draw hypocycloid #######\n";
cout << "\n\t\tEnter graph Height: ";
cin >> graphHeight;
cout << "\t\tEnter graph Width: ";
cin >> graphWidth;
cout << "\t\tRadius of hypocycloid: ";
cin >> radius2;
int k=3;
radius1 = k * radius2;
//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++)
{
hypocycloid[row][column]=' ';
}
}
//horizontal axis
for(column = 0; column <= graphWidth; column++)
{
row = aspectedGraphHeight / 2;
hypocycloid[row][column] = '-';
}
//vertical axis
for(row = 0; row <= aspectedGraphHeight; row++)
{
column = graphWidth / 2;
hypocycloid[row][column] = '|';
}
//points of hypocycloid
for (angle = 0; angle <= 360; angle += 1)
{
x = ((radius1- radius2) * cos(angle)) + (radius2 * cos((radius1/radius2 - 1.0)*angle)) +.5;
y = ((radius1- radius2) * sin(angle)) - (radius2 * sin((radius1/radius2 - 1.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;
hypocycloid[row][column] = '.';
}
//print hypocycloid
for(row = 0; row<=aspectedGraphHeight; row++)
{
for(column = 0; column<=graphWidth; column++)
cout << hypocycloid[row][column];
cout<<endl;
}
}