-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathellipse.c
More file actions
84 lines (68 loc) · 1.26 KB
/
ellipse.c
File metadata and controls
84 lines (68 loc) · 1.26 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
76
77
78
79
80
81
82
83
84
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// ellipse parameters
double a = 1.0;
double b = 0.5;
double c = 0.5;
/* function: get_square
input parameters:
phi - rotation angle
*/
double get_square(double phi)
{
// visible semi-axises of ellipse
double va;
double vb;
// find major semi-axis
// psi angle - radius-vector angle of maximum projection
double psi = 0;
if ( fabs( phi - M_PI / 2) > 1e-3 )
{
psi = atan( 1.0L * b / a * tan( phi ));
va = sqrt( pow( a * cos( psi ), 2) +
pow( b * sin( psi ), 2));
}
else
{
va = b;
}
// find minor semi-axis
vb = b;
//debug:
printf("%lf %lf %lf %lf %lf\n",
phi * 180 / M_PI,
psi * 180 / M_PI,
b / a * tan( phi ),
va,
M_PI * va * vb);
return M_PI * va * vb;
}
void run()
{
int N = 90;
double left = 0;
double right = M_PI / 2;
double step = (right - left) / N;
double alpha;
FILE *f;
f = fopen("ellipse.txt", "w");
for (int i=0; i < N + 1; i++)
{
fprintf(f, "%lf %lf\n",
alpha,
get_square(alpha));
alpha += step;
}
fclose(f);
}
void tests()
{
printf("circle square: %lf\n", M_PI * b * b);
}
int main( int arc, const char **argv )
{
// run();
tests();
return 0;
}