//Èñõîäíûé äàííûå
L1 = 500 ;//ìì
D1 = 400 ;//ìì

L2 = 400 ;//ìì
D2 = 50 ;//ìì

A  = 150 ;//ìì
//Òî÷íîñòü ìîäåëè
Lc = 0.05; //ì
//Ïðèâåäåíèå ê ñèñòåìå ÑÈ
L1 = L1/1000;
D1 = D1/1000;
L2 = L2/1000;
D2 = D2/1000;
A  = A /1000;
//Ïðîâåðêà óñëîâèé

//Ðåøåíèå
N = 10; //êîëè÷åñòâî ðàçáèåíèé ðàçðåçà íà îòðåçêå â 90 ãðàäóñîâ

Point(0) = {0,0,0,Lc};
Point(1) = {0, D1/2,0,Lc};
Point(2) = {0,-D1/2,0,Lc};
//Point(3) = {0,0, D1/2,Lc};
Point(4) = {0,0,-D1/2,Lc};

Point(5) = {L1/2,0,0,Lc};
Point(6) = {L1/2, D1/2,0,Lc};
Point(7) = {L1/2,-D1/2,0,Lc};
//Point(8) = {L1/2,0, D1/2,Lc};//
Point(8) = {L1/2,A,Sqrt((D1/2)^2-A^2),Lc};
Point(9) = {L1/2,0,-D1/2,Lc};

Point(10) = {-L1/2,0,0,Lc};
Point(11) = {-L1/2, D1/2,0,Lc};
Point(12) = {-L1/2,-D1/2,0,Lc};
//Point(13) = {-L1/2,0, D1/2,Lc};//
Point(13) = {-L1/2,A, Sqrt((D1/2)^2-A^2),Lc};
Point(14) = {-L1/2,0,-D1/2,Lc};

///////////////////////////////////
Point(20) = {0,A,L2,Lc};
Point(21) = { D2/2,A,L2,Lc};
Point(22) = {-D2/2,A,L2,Lc};
Point(23) = {0,A+D2/2,L2,Lc};
Point(24) = {0,A-D2/2,L2,Lc};


//
Circle(1) = {11, 10, 13};
Circle(2) = {13, 10, 12};
Circle(3) = {12, 10, 14};
Circle(4) = {14, 10, 11};
Circle(5) = {6, 5, 8};
Circle(6) = {8, 5, 7};
Circle(7) = {7, 5, 9};
Circle(8) = {9, 5, 6};
Circle(9) = {1, 0, 4};
Circle(10) = {4, 0, 2};
Circle(11) = {23, 20, 21};
Circle(12) = {21, 20, 24};
Circle(13) = {24, 20, 22};
Circle(14) = {22, 20, 23};
Line(15) = {11, 1};
Line(16) = {1, 6};
Line(17) = {14, 4};
Line(18) = {4, 9};
Line(19) = {12, 2};
Line(20) = {2, 7};
//
N=N*4;
For i In {0:N}
	alpha = i/N*2*3.1415926;
	Point (50+i) = {D2/2*Sin(alpha),A+D2/2*Cos(alpha),Sqrt((D1/2)^2-(A+D2/2*Cos(alpha))^2),Lc};
EndFor

Line(51) = {23, 50};
Line(52) = {21, 50+N/4};
Line(53) = {24, 50+2*N/4};
Line(54) = {22, 50+3*N/4};

//
//L_temp = 3.1415926*D1*(3.1415926/2-Asin((A+D2/2)/(D1/2)))/(2*3.1415926);
N_temp = 20; //L_temp/Lc-Fmod(L_temp,Lc);
For i In {0:N_temp}
	alpha = i/N_temp*(3.1415926/2-Asin((A+D2/2)/(D1/2)));
	Point (100+N+i) = {0,D1/2*Cos(alpha),D1/2*Sin(alpha),Lc};
EndFor
Spline(58) = 
{1, 
100+N+01, 100+N+02, 100+N+03, 100+N+04, 100+N+05, 
100+N+06, 100+N+07, 100+N+08, 100+N+09, 100+N+10,
100+N+11, 100+N+12, 100+N+13, 100+N+14, 100+N+15, 
100+N+16, 100+N+17, 100+N+18, 100+N+19, 100+N+20,
50};
For i In {0:N_temp}
	alpha = i/N_temp*(3.1415926/2-Asin((-A+D2/2)/(D1/2)));
	Point (200+N+i) = {0,-D1/2*Cos(alpha),D1/2*Sin(alpha),Lc};
EndFor
Spline(59) = 
{2, 
200+N+01, 200+N+02, 200+N+03, 200+N+04, 200+N+05, 
200+N+06, 200+N+07, 200+N+08, 200+N+09, 200+N+10,
200+N+11, 200+N+12, 200+N+13, 200+N+14, 200+N+15, 
200+N+16, 200+N+17, 200+N+18, 200+N+19, 200+N+20,
50+2/4*N};
Spline(60) = {80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 50};


//

Point(300+N  ) = { (L1/2+D2/2)/2,A,Sqrt((D1/2)^2-A^2),Lc};
Point(300+N+1) = { -((L1/2+D2/2)/2),A,Sqrt((D1/2)^2-A^2),Lc};
Line(61) = {13, 341};
Line(62) = {341, 80};
Line(63) = {60, 340};
Line(64) = {340, 8};


//

For i In {0:N}
	alpha = i/N*2*3.1415926;
	If (i <= N/4)
	Point (500+i) = {	((L1/2+D2/2)/2)*Sin(alpha),
				A+(D1/2-A)*Cos(alpha),
				Sqrt((D1/2)^2-(A+(D1/2-A)*Cos(alpha))^2),
				Lc};
	EndIf
	If (i >= N*3/4)
	Point (500+i) = {	((L1/2+D2/2)/2)*Sin(alpha),
				A+(D1/2-A)*Cos(alpha),
				Sqrt((D1/2)^2-(A+(D1/2-A)*Cos(alpha))^2),
				Lc};
	EndIf
	If (i > N/4 && i < N*3/4)
	Point (500+i) = {	((L1/2+D2/2)/2)*Sin(alpha),
				A+(D1/2+A)*Cos(alpha),
				Sqrt((D1/2)^2-(A+(D1/2+A)*Cos(alpha))^2),
				Lc};
	EndIf
EndFor
Spline(65) = {341, 531, 532, 533, 534, 535, 536, 537, 538, 539, 1};
Line Loop(66) = {62, 60, -58, -65};
Ruled Surface(67) = {66};
Line Loop(68) = {61, 65, -15, 1};
Ruled Surface(69) = {68};
Spline(70) = {60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50};
Line Loop(71) = {70, -58, 16, 5, -64, -63};

Spline(72) = {340, 509, 508, 507, 506, 505, 504, 503, 502, 501, 1};
Line Loop(73) = {70, -58, -72, -63};
Ruled Surface(74) = {73};
Line Loop(75) = {70, -51, 11, 52};
Ruled Surface(76) = {75};
Line Loop(77) = {54, 60, -51, -14};
Ruled Surface(78) = {77};
Line Loop(79) = {72, 16, 5, -64};
Ruled Surface(80) = {79};




//



Spline(81) = {80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70};
Spline(82) = {70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60};
Spline(83) = {2, 519, 518, 517, 516, 515, 514, 513, 512, 511, 340};
Spline(84) = {2, 521, 522, 523, 524, 525, 526, 527, 528, 529, 341};
Line Loop(85) = {81, -59, 84, 62};
Ruled Surface(86) = {85};
Line Loop(87) = {84, -61, 2, 19};
Ruled Surface(88) = {87};
Line Loop(89) = {59, 82, 63, -83};
Ruled Surface(90) = {89};
Line Loop(91) = {83, 64, 6, -20};
Ruled Surface(92) = {91};
Line Loop(93) = {20, 7, -18, 10};
Ruled Surface(94) = {93};
Line Loop(95) = {3, 17, 10, -19};
Ruled Surface(96) = {95};
Line Loop(97) = {4, 15, 9, -17};
Ruled Surface(98) = {97};
Line Loop(99) = {9, 18, 8, -16};
Ruled Surface(100) = {99};
Line Loop(101) = {53, 82, -52, 12};
Ruled Surface(102) = {101};
Line Loop(103) = {54, 81, -53, 13};
Ruled Surface(104) = {103};
Ruled Surface(105) = {66};