1 | #include <stdio.h>
|
---|
2 | #include <stdlib.h>
|
---|
3 | #include <math.h>
|
---|
4 |
|
---|
5 | #define PI 3.14159265
|
---|
6 |
|
---|
7 | int main()
|
---|
8 | {
|
---|
9 | double ct_f, k, diameter;
|
---|
10 | double f, x, y, z, sx, sy, thetan, phin, xn, yn, zn;
|
---|
11 | double x_min, y_min, x_max, y_max, a;
|
---|
12 | double norm;
|
---|
13 | double step; /* (cm) separation of mirror centers = length of mirror side */
|
---|
14 |
|
---|
15 | long x_index, y_index;
|
---|
16 | long i_mirror;
|
---|
17 | char dummy[256];
|
---|
18 |
|
---|
19 | step = 50.;
|
---|
20 |
|
---|
21 | ct_f = 16.97; // In meters-> camera will then be at 17 m to focus at 10 km
|
---|
22 |
|
---|
23 | // Convert to cm:
|
---|
24 | ct_f *= 100;
|
---|
25 |
|
---|
26 | k = 1./(4.*ct_f);
|
---|
27 |
|
---|
28 |
|
---|
29 | diameter = 17; // meters
|
---|
30 |
|
---|
31 | x_max = y_max = 8.25; // floor(diameter/2+0.5)-0.25;
|
---|
32 | x_min = y_min = -x_max;
|
---|
33 |
|
---|
34 |
|
---|
35 | // Convert to cm:
|
---|
36 | diameter *= 100;
|
---|
37 | x_max *= 100;
|
---|
38 | y_max *= 100;
|
---|
39 | x_min *= 100;
|
---|
40 | y_min *= 100;
|
---|
41 |
|
---|
42 | i_mirror = 0;
|
---|
43 |
|
---|
44 | for (x = x_min ; x < x_max+1; x += step)
|
---|
45 | for (y = y_min ; y < y_max+1; y += step)
|
---|
46 | {
|
---|
47 |
|
---|
48 | if ( (fabs(x)+fabs(y)) > diameter*0.72)
|
---|
49 | continue;
|
---|
50 |
|
---|
51 | if ((x >-150 && x < 50) && fabs(y) < 50)
|
---|
52 | continue;
|
---|
53 |
|
---|
54 | if ( (x == 825. || x == -825.) && (y == 75. || y == -75.) )
|
---|
55 | continue;
|
---|
56 |
|
---|
57 | x_index = x > 0? (int)(x+50)/100 : (int)(x-50)/100 ;
|
---|
58 | y_index = y > 0? (int)(y+50)/100 : (int)(y-50)/100 ;
|
---|
59 |
|
---|
60 | // printf("%d %d %.0f %.0f\n", x_index, y_index, x, y);
|
---|
61 |
|
---|
62 | i_mirror++;
|
---|
63 |
|
---|
64 | z = k*(x*x+y*y);
|
---|
65 |
|
---|
66 | // Curvilinear coordinates:
|
---|
67 |
|
---|
68 | sx = (2*k*x*sqrt(1+4*k*k*x*x)+asinh(2*k*x))/4/k;
|
---|
69 | sy = (2*k*y*sqrt(1+4*k*k*y*y)+asinh(2*k*y))/4/k;
|
---|
70 |
|
---|
71 | phin = atan2(y,x);
|
---|
72 | if (phin < 0)
|
---|
73 | phin += 2*PI;
|
---|
74 |
|
---|
75 | //
|
---|
76 | // OLD: (before chessboarding) Valid only if mirror is ON the parabola
|
---|
77 | // xn = - x / sqrt(x*x+y*y+4*ct_f*ct_f);
|
---|
78 | // yn = - y / sqrt(x*x+y*y+4*ct_f*ct_f);
|
---|
79 | // zn = 2*ct_f / sqrt(x*x+y*y+4*ct_f*ct_f);
|
---|
80 | // printf("%.6f %.6f %.6f\n", xn, yn, zn);
|
---|
81 |
|
---|
82 | //
|
---|
83 | // Shift z for chessboarding:
|
---|
84 | //
|
---|
85 | if (!((x_index+y_index)%2 != 0 ||
|
---|
86 | (x_index+y_index) == 12 ||
|
---|
87 | (x_index+y_index) == -12 ||
|
---|
88 | (x_index-y_index) == 12 ||
|
---|
89 | (x_index-y_index) == -12 ) )
|
---|
90 | z += 8.;
|
---|
91 |
|
---|
92 | //
|
---|
93 | // NEW: Valid also (correct focusing) if we shift mirrors from the parabola,
|
---|
94 | // since we use explicitely the z coordinate:
|
---|
95 | //
|
---|
96 | xn = - x / sqrt(x*x+y*y+(ct_f-z)*(ct_f-z));
|
---|
97 | yn = - y / sqrt(x*x+y*y+(ct_f-z)*(ct_f-z));
|
---|
98 | zn = 1 + (ct_f - z) / sqrt(x*x+y*y+(ct_f-z)*(ct_f-z));
|
---|
99 |
|
---|
100 | norm = sqrt(xn*xn+yn*yn+zn*zn);
|
---|
101 | xn /= norm;
|
---|
102 | yn /= norm;
|
---|
103 | zn /= norm;
|
---|
104 |
|
---|
105 | // printf("%.6f %.6f %.6f\n\n", xn, yn, zn);
|
---|
106 |
|
---|
107 |
|
---|
108 | thetan = acos(zn);
|
---|
109 |
|
---|
110 | a = 2*ct_f;
|
---|
111 |
|
---|
112 | //
|
---|
113 | // Focal distance of the mirror:
|
---|
114 | //
|
---|
115 | f= 0.5 * (a*sqrt((1.+(x*x+y*y)/(a*a))*
|
---|
116 | (1.+(x*x+y*y)/(a*a))*
|
---|
117 | (1.+(x*x+y*y)/(a*a))) + sqrt(x*x+y*y)/
|
---|
118 | (sin(atan(sqrt(x*x+y*y)/a))))/2.;
|
---|
119 |
|
---|
120 |
|
---|
121 | printf("%3d %9.4f %9.4f %9.4f %9.4f %9.4f %9.4f %9.8f %9.8f %9.8f %9.8f %9.8f\n", i_mirror, f, sx, sy, x, y, z, thetan, phin, xn, yn, zn);
|
---|
122 | }
|
---|
123 |
|
---|
124 | return 0;
|
---|
125 | }
|
---|
126 |
|
---|
127 |
|
---|