lc = 0.002;

// deux sections circulaires principales
x0 = 0.8155;
r0 = 0.0525;

Point(1) = {x0, 0, -r0, lc};
Point(2) = {x0, r0, 0, lc};
Point(3) = {x0, 0, r0, lc};
Point(4) = {x0, 0, 0, lc};

x1 = 0;
r1 = 0.0525;

Point(5) = {x1, 0, -r1, lc};
Point(6) = {x1, r1, 0, lc};
Point(7) = {x1, 0, r1, lc};
Point(8) = {x1, 0, 0, lc};

// fente
x2 = 0.448;
y2 = 0.0525;
r2 = 0.0025;
N = 50;
For i In {1:N}
  teta = 0.5*Pi*(i-1)/(N-1);
  x = (x2-r2) + r2*Cos(teta);
  z = r2*Sin(teta);
  coef = r1/Sqrt(y2*y2+z*z);
  Point(10+i) = {x, coef*y2, coef*z, lc};
  Point(10+i+N) = {x, coef*y2, -coef*z, lc};
EndFor

Spline(1) = {11:10+N};
Spline(2) = {11+N:10+2*N};

x3 = 0.3595;
y3 = 0.0525;
r3 = 0.006;
teta0 = Asin(r2/r3);
For i In {1:N}
  teta = teta0 + (Pi-teta0)*(i-1)/(N-1);
  x = (x3+r3) + r3*Cos(teta);
  z = r3*Sin(teta);
  coef = r1/Sqrt(y3*y3+z*z);
  Point(10+i+2*N) = {x, coef*y3, coef*z, lc};
  Point(10+i+3*N) = {x, coef*y3, -coef*z, lc};
EndFor

Spline(3) = {11+2*N:10+3*N};
Spline(4) = {11+3*N:10+4*N};

Circle(5) = {3, 4, 2};
Circle(6) = {2, 4, 1};

Circle(7) = {7, 8, 6};
Circle(8) = {6, 8, 5};
Line(9) = {11, 2};

Line(10) = {10+3*N, 6};
Line(13) = {10+2*N, 11+3*N};
Line(14) = {11+2*N, 10+N};

teta1 = Atan(r2/r1);
h3 = 0.02;
Extrude {{-h3, 0, 0}, {1,0,0}, {0, 0, 0}, Pi/2} { Point{10+3*N}; }
Extrude {{-h3, 0, 0}, {1,0,0}, {0, 0, 0}, -Pi/2} { Point{10+3*N}; }

Extrude {{h3, 0, 0}, {1,0,0}, {0, 0, 0}, Pi/2-teta1} { Point{11+2*N}; }
Extrude {{h3, 0, 0}, {1,0,0}, {0, 0, 0}, -Pi/2+teta1} { Point{11+3*N}; }

Extrude {{h3, 0, 0}, {1,0,0}, {0, 0, 0}, Pi/2} { Point{11}; }
Extrude {{h3, 0, 0}, {1,0,0}, {0, 0, 0}, -Pi/2} { Point{11}; }

Extrude {{-h3, 0, 0}, {1,0,0}, {0, 0, 0}, Pi/2-teta1} { Point{10+N}; }
Extrude {{-h3, 0, 0}, {1,0,0}, {0, 0, 0}, -Pi/2+teta1} { Point{10+2*N}; }

Line(23) = {7, 215};
Line(24) = {220, 5};
Line(25) = {220, 230};
Line(26) = {230, 250};
Line(27) = {250, 240};
Line(28) = {240, 1};
Line(29) = {3, 235};
Line(30) = {235, 245};
Line(31) = {245, 225};
Line(32) = {225, 215};
Line Loop(33) = {6, -28, -20, 9};
Ruled Surface(34) = {33};

Line Loop(35) = {27, -20, 2, 22};
Ruled Surface(36) = {35};

Line Loop(37) = {22, -26, -18, -13};
Ruled Surface(38) = {37};

Line Loop(39) = {25, -18, 4, 16};
Ruled Surface(40) = {39};

Line Loop(41) = {24, -8, -10, 16};
Ruled Surface(42) = {41};

Line Loop(43) = {7, -10, 15, -23};
Ruled Surface(44) = {43};

Line Loop(45) = {15, -32, -17, 3};
Ruled Surface(46) = {45};

Line Loop(47) = {17, -31, -21, -14};
Ruled Surface(48) = {47};

Line Loop(49) = {21, -30, -19, 1};
Ruled Surface(50) = {49};

Line Loop(51) = {29, -19, 9, -5};
Ruled Surface(52) = {51};

Physical Surface(1) = {44, 42, 40, 38, 36, 34, 52, 50, 48, 46};

Line(53) = {3, 4};
Line(54) = {4, 1};
Line Loop(55) = {5, 6, -54, -53};
Plane Surface(56) = {55};

// ailes du satellite
x4 = 0.365500;
y4 = 0.0765;
r4 = 0.005;

xmin = 0.3405;
xmax = 0.3905;
ymin = 0.0545;
ymax = 0.1745;
zmin = -1.05e-3;
zmax = 9.5e-4;

teta4 = Asin(zmax/r4);
teta4b = Asin(zmin/r4);

Point(300) = {x4, y4, 0, lc};
Point(301) = {x4+r4*Cos(teta4), y4, r4*Sin(teta4), lc};
Point(302) = {x4-r4*Cos(teta4), y4, r4*Sin(teta4), lc};

Point(303) = {x4+r4*Cos(teta4b), y4, r4*Sin(teta4b), lc};
Point(304) = {x4-r4*Cos(teta4b), y4, r4*Sin(teta4b), lc};

Point(305) = {x4, ymin, 0, lc};
Point(306) = {x4+r4*Cos(teta4), ymin, r4*Sin(teta4), lc};
Point(307) = {x4-r4*Cos(teta4), ymin, r4*Sin(teta4), lc};

Point(308) = {x4+r4*Cos(teta4b), ymin, r4*Sin(teta4b), lc};
Point(309) = {x4-r4*Cos(teta4b), ymin, r4*Sin(teta4b), lc};

Point(310) = {xmin, ymin, zmin, lc};
Point(311) = {xmin, ymin, zmax, lc};
Point(312) = {xmin, ymax, zmin, lc};
Point(313) = {xmin, ymax, zmax, lc};
Point(314) = {xmax, ymin, zmin, lc};
Point(315) = {xmax, ymin, zmax, lc};
Point(316) = {xmax, ymax, zmin, lc};
Point(317) = {xmax, ymax, zmax, lc};

y5 = 0.046;
x5m = 0.3555;
x5p = 0.3805;
z5m = -0.015;
z5p = 0.015;

Point(318) = {x5m, 0, z5m, lc};
Point(319) = {x5m, 0, z5p, lc};
Point(320) = {x5m, y5, z5m, lc};
Point(321) = {x5m, y5, z5p, lc};
Point(322) = {x5p, 0, z5m, lc};
Point(323) = {x5p, 0, z5p, lc};
Point(324) = {x5p, y5, z5m, lc};
Point(325) = {x5p, y5, z5p, lc};

Point(326) = {x4, y5, 0, lc};
Point(327) = {x4+r4*Cos(teta4), y5, r4*Sin(teta4), lc};
Point(328) = {x4-r4*Cos(teta4), y5, r4*Sin(teta4), lc};

Point(329) = {x4+r4*Cos(teta4b), y5, r4*Sin(teta4b), lc};
Point(330) = {x4-r4*Cos(teta4b), y5, r4*Sin(teta4b), lc};

Circle(57) = {303, 300, 304};
Circle(58) = {301, 300, 302};
Circle(59) = {309, 305, 308};
Circle(60) = {307, 305, 306};
Line(61) = {310, 312};
Line(62) = {313, 311};
Line(63) = {310, 309};
Line(64) = {307, 311};
Line(65) = {307, 302};
Line(66) = {309, 304};
Line(67) = {308, 303};
Line(68) = {308, 314};
Line(69) = {314, 315};
Line(70) = {315, 306};
Line(71) = {315, 317};
Line(72) = {314, 316};
Line(73) = {316, 317};
Line(74) = {312, 316};
Line(75) = {317, 313};
Line(76) = {313, 312};
Line(77) = {321, 325};
Line(78) = {325, 324};
Line(79) = {324, 320};
Line(80) = {320, 321};
Line(81) = {321, 319};
Line(82) = {319, 323};
Line(83) = {323, 322};
Line(84) = {322, 318};
Line(85) = {318, 319};
Line(86) = {322, 324};
Line(87) = {320, 318};
Line(88) = {323, 325};
Line(93) = {310, 311};
Circle(94) = {307, 305, 309};
Circle(95) = {306, 305, 308};
Circle(96) = {328, 326, 330};
Circle(97) = {330, 326, 329};
Circle(98) = {329, 326, 327};
Circle(99) = {327, 326, 328};
Line(100) = {328, 307};
Line(101) = {309, 330};

Line(102) = {327, 306};
Line(103) = {329, 308};
Line Loop(104) = {66, -57, -67, -59};
Ruled Surface(105) = {104};
Line(106) = {301, 306};
Line Loop(107) = {58, -65, 60, -106};
Ruled Surface(108) = {107};
Line Loop(109) = {97, 103, -59, 101};
Ruled Surface(110) = {109};
Line Loop(111) = {101, -96, 100, 94};
Ruled Surface(112) = {111};
Line Loop(113) = {99, 100, 60, -102};
Ruled Surface(114) = {113};
Line Loop(115) = {102, 95, -103, 98};
Ruled Surface(116) = {115};
Line(117) = {303, 304};
Line(118) = {302, 301};
Line Loop(119) = {117, -57};
Plane Surface(120) = {119};
Line Loop(121) = {118, 58};
Plane Surface(122) = {121};
Line Loop(123) = {61, 74, -72, -68, 67, 117, -66, -63};
Plane Surface(124) = {123};
Line Loop(125) = {75, 76, 74, 73};
Plane Surface(126) = {125};
Line Loop(127) = {71, -73, -72, 69};
Plane Surface(128) = {127};
Line Loop(129) = {76, -61, 93, -62};
Plane Surface(130) = {129};
Line Loop(131) = {64, -93, 63, -94};
Plane Surface(132) = {131};
Line Loop(133) = {70, 95, 68, 69};
Plane Surface(134) = {133};
Line Loop(135) = {75, 62, -64, 65, 118, 106, -70, 71};
Plane Surface(136) = {135};
Line Loop(137) = {80, 77, 78, 79};
Line Loop(138) = {97, 98, 99, 96};
Plane Surface(139) = {137, 138};
Line Loop(140) = {87, 85, -81, -80};
Plane Surface(141) = {140};
Line Loop(142) = {82, 88, -77, 81};
Plane Surface(143) = {142};
Line Loop(144) = {83, 84, 85, 82};
Plane Surface(145) = {144};
Line Loop(146) = {87, -84, 86, 79};
Plane Surface(147) = {146};
Line Loop(148) = {88, 78, -86, -83};
Plane Surface(149) = {148};

Physical Surface(2) = {130, 136, 124, 128, 126, 132, 134, 122, 108, 120, 105, 110, 112, 114, 116, 139, 141, 143, 145, 147, 149};
