source: trunk/MagicSoft/Simulation/Detector/ReflectorII/writemagicdef/writemagicdef.c@ 14098

Last change on this file since 14098 was 5441, checked in by moralejo, 20 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <math.h>
4
5#define PI 3.14159265
6
7int 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 // Skip non existent mirrors:
48
49 if ( (fabs(x)+fabs(y)) > diameter*0.72)
50 continue;
51
52 if ((x >-150 && x < 50) && fabs(y) < 50)
53 continue;
54
55 if ( (x == 825. || x == -825.) && (y == 75. || y == -75.) )
56 continue;
57
58
59 x_index = x > 0? (int)(x+50)/100 : (int)(x-50)/100 ;
60 y_index = y > 0? (int)(y+50)/100 : (int)(y-50)/100 ;
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 // Shift z if chessboarding is desired:
77 //
78 // if (!((x_index+y_index)%2 != 0 ||
79 // (x_index+y_index) == 12 ||
80 // (x_index+y_index) == -12 ||
81 // (x_index-y_index) == 12 ||
82 // (x_index-y_index) == -12 ) )
83 // z += 8.; // cm
84
85 //
86 // Calculate orientation of vector normal to the mirror:
87 //
88 // Add the versor pointing from the mirror element center (x,y,z)
89 // to the camera center (0,0,ct_f), and versor (0,0,1). The
90 // direction of the resulting vector is that of the bisector of
91 // the two versors. If the normal of the mirror element is
92 // oriented along that direction, light rays paralel to the
93 // telescope axis and impinging on the center of the mirror
94 // element will be reflected to the center of the camera.
95 //
96 //
97 xn = - x / sqrt(x*x+y*y+(ct_f-z)*(ct_f-z));
98 yn = - y / sqrt(x*x+y*y+(ct_f-z)*(ct_f-z));
99 zn = 1 + (ct_f - z) / sqrt(x*x+y*y+(ct_f-z)*(ct_f-z));
100
101 //
102 // Normalize the vector to obtain the versor:
103 //
104 norm = sqrt(xn*xn+yn*yn+zn*zn);
105 xn /= norm;
106 yn /= norm;
107 zn /= norm;
108
109 //
110 // Get angle between the normal to the mirror and the
111 // telescope axis:
112 //
113 thetan = acos(zn);
114
115 a = 2*ct_f;
116
117 //
118 // Focal distance of the mirror:
119 //
120 f= 0.5 * (a*sqrt((1.+(x*x+y*y)/(a*a))*
121 (1.+(x*x+y*y)/(a*a))*
122 (1.+(x*x+y*y)/(a*a))) + sqrt(x*x+y*y)/
123 (sin(atan(sqrt(x*x+y*y)/a))))/2.;
124
125
126 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);
127 }
128
129 return 0;
130}
131
132
Note: See TracBrowser for help on using the repository browser.