// mainiigie lielumi:
// fi0 = Pi/180*2;  	// graados !!!!!!!
fi0 = 0.02;  	    // radianos !!!!!!!
stepC=0.02; 		// izmeers kontaktpunktaa (centraa)  
stepFI0=0.02; 		// izmers pie fi0


//
//  Autors: Didzis Goðko
//  Datums: 27.11.2005
//
//  1. sfçra (augðçjâ sfçra, pozitîvâ sfçra) - pozitîvajâ Z ass virzienâ
//  2. sfçra (apakðçjâ sfçra, negatîvâ sfçra) - negatîvajâ Z ass virzienâ
//  Punkti nummurçti no X ass pozitîvâ virzienâ uz negatîvo un virzienâ
//  no koordinâtu sâkumpunkta vispirms ejot pozitîvajâ Z ass virzienâ,
//  pçc tam negatîvajâ, vispirms tiek apskatîti punkti uz XY plaknes, kad Z=0
//  Lîniju apieðanas virzieni ir simetriski koordinâtu sâkumpunktam
//  Lînijas definçtas vispirms virzienâ prom no koord sâkumpunkta (ja paralçli
//  Z asij), tad apieðanas virzienos (pçc iespçjas)

//////////////////////////
// Definçjam parametrus //
//////////////////////////

R = 1;    // sfçru râdiuss

// stingri definçts!!!
d = 0;    // sfçru tuvâkâ punkta attâlums lîdz koordinâtu sâkumpunktam


// Apkârtçjâs telpas izmçri
Lmult = 10;
LX = R*Lmult;
LY = R*Lmult;
LZ = R*(Lmult+1)+d;

//#INSERT_PARAMS_HERE

// Konstante
fi60 = Pi/3;   // 60 grâdu leòíis
// Sfçru parametri (kopîgie)
fi = fi60*0.5;  // raksturîgais leòíis


// 1. sfçras parametri
R1 = R;     // 1. sfçras râdiuss
d1 = d;     // 1. pusfçras attâlums lîdz koord. sâkumpunktam
fi11 = fi;  // leòíis tuvâk koordinâtu sâkumpunktam
fi12 = fi;  // Sfçru parametri (kopîgie)
fi1 = fi0;

// leòíis tâlâk no koordinâtu sâkumpunkta

// 2. sfçras parametri
R2 = R;     // 2. sfçras râdiuss
d2 = d;     // 2. pusfçras attâlums lîdz koord. sâkumpunktam
fi21 = fi;  // leòíis tuvâk koordinâtu sâkumpunktam
fi22 = fi;  // leòíis tâlâk no koordinâtu sâkumpunkta
fi2 = fi0;


R0 = R;     // loka râdiuss pie koordinâtu sâkumpunkta XY plaknç, kad Z=0



/////////////////////////////
// Definçjam reþìa izmçrus //
/////////////////////////////

// Reþìa izmçri
ms1 = 04;     // 1. sfçras centra reþìa izmçra indekss
ms2 = 10;     // 2. sfçras centra reþìa izmçra indekss
msMult = 1;
msdef = msMult*R;  // noklusçtais reþìa izmçrs


msF = msdef*Sqrt(0.001);


ms[] = {
	//msdef*0.01,	// koordinâtu sâkumpunktam (sfçru saskares punktam)
	msdef*stepC, // sfeeru kontaktpunkts !!!
	msdef,	    // apkârtçjâs telpas stûriem
	msF,	      // pie R0
	msdef,	    // --- rezervçts
	msdef*0.1,	// 1. sfçras centrs
	msdef*stepFI0,  // 1. sfçras virsotnes pie fi1 !!!!!!!!!!!
	msdef*0.1,	// 1. sfçras tâlâkâ virsotne
	msdef*0.1,	// 1. sfçras virsotnçm uz ekvatora
	msF,	      // 1. sfçras virsotnçm pie fi11
	msdef*0.1,	// 1. sfçras virsotnçm pie fi12
	msdef*0.1,	// 2. sfçras centrs
	msdef*stepFI0,	// 2. sfçras virsotnes pie fi2  !!!!!!!!!
	msdef*0.1,	// 2. sfçras tâlâkâ virsotne
	msdef*0.1,	// 2. sfçras virsotnçm uz ekvatoramsCn
	msF,	      // 2. sfçras virsotnçm pie fi21
	msdef*0.1,	// 2. sfçras virsotnçm pie fi22
	msdef	// n-tam ptam
};



///////////////////////
// Definçjam punktus //
///////////////////////

p0 = 1;     // apkârtçjâs telpas p-ti
p1 = 100;   // 1. sfçras p-ti (augðçjâs sfçras)
p2 = 200;   // 2. sfçras p-ti (apakðçjâs sfçras)


// ***************
// Apkârtçjâ telpa
// ***************

// Pats centrs
Point(p0+0)   = {0,     0,     0, ms[0]};

// XY pl-ne, Z=0
Point(p0+1)   = {R0,    0,     0, ms[2]};
Point(p0+2)   = {LX,    0,     0, ms[1]};
Point(p0+3)   = {LX,    LY,    0, ms[1]};
Point(p0+4)   = {-LX,   LY,    0, ms[1]};
Point(p0+5)   = {-LX,   0,     0, ms[1]};
Point(p0+6)   = {-R0,   0,     0, ms[2]};
Point(p0+7)   = {0,     R0,    0, ms[2]};


// XY pl-ne, Z=LZ
Point(p0+10)   = {0,     0,     LZ, ms[1]};
Point(p0+11)   = {LX,    0,     LZ, ms[1]};
Point(p0+12)   = {LX,    LY,    LZ, ms[1]};
Point(p0+13)   = {-LX,   LY,    LZ, ms[1]};
Point(p0+14)   = {-LX,   0,     LZ, ms[1]};

// XY pl-ne, Z=-LZ
Point(p0+20)  = {0,     0,    -LZ, ms[1]};
Point(p0+21)  = {LX,    0,    -LZ, ms[1]};
Point(p0+22)  = {LX,    LY,   -LZ, ms[1]};
Point(p0+23)  = {-LX,   LY,   -LZ, ms[1]};
Point(p0+24)  = {-LX,   0,    -LZ, ms[1]};


// ******************
// 1. sfçra (augðçjâ)
// ******************

// Sfçras centrs
Point(p1+0)   = {0, 0, d1+R1, ms[ms1+0]};

// Virsotnes
//Point(p1+1)   = {0, 0, d1, ms[ms1+1]};
Point(p1+2)   = {0, 0, d1+2*R1, ms[ms1+2]};
// Papildus centri ekvatoram paralçlajâm riòía lînijâm
//Point(p1+3y)   = {0, 0, d1+R1-R1*Cos(fi11), ms[ms1+4]};
//Point(p1+4)   = {0, 0, d1+R1+R1*Cos(fi12), ms[ms1+5]};

// Ekvatora virsotnes
Point(p1+11)  = {R1, 0, d1+R1, ms[ms1+3]};
Point(p1+12)  = {R1*Cos(fi60), R1*Sin(fi60), d1+R1, ms[ms1+3]};
Point(p1+13)  = {-R1*Cos(fi60), R1*Sin(fi60), d1+R1, ms[ms1+3]};
Point(p1+14)  = {-R1, 0, d1+R1, ms[ms1+3]};

// Virsotnes pie fi11
Point(p1+21)   = {R1*Sin(fi11), 0, d1+R1-R1*Cos(fi11), ms[ms1+4]};
Point(p1+22)   = {R1*Cos(fi60)*Sin(fi11), R1*Sin(fi60)*Sin(fi11), d1+R1-R1*Cos(fi11), ms[ms1+4]};
Point(p1+23)   = {-R1*Cos(fi60)*Sin(fi11), R1*Sin(fi60)*Sin(fi11), d1+R1-R1*Cos(fi11), ms[ms1+4]};
Point(p1+24)  = {-R1*Sin(fi11), 0, d1+R1-R1*Cos(fi11), ms[ms1+4]};

// Virsotnes pie fi12
Point(p1+31)   = {R1*Sin(fi12), 0, d1+R1+R1*Cos(fi12), ms[ms1+5]};
Point(p1+32)   = {R1*Cos(fi60)*Sin(fi12), R1*Sin(fi60)*Sin(fi12), d1+R1+R1*Cos(fi12), ms[ms1+5]};
Point(p1+33)   = {-R1*Cos(fi60)*Sin(fi12), R1*Sin(fi60)*Sin(fi12), d1+R1+R1*Cos(fi12), ms[ms1+5]};
Point(p1+34)  = {-R1*Sin(fi12), 0, d1+R1+R1*Cos(fi12), ms[ms1+5]};


// Virsotnes pie fi1
Point(p1+41)   = {R1*Sin(fi1), 0, d1+R1-R1*Cos(fi1), ms[ms1+1]};
Point(p1+42)   = {R1*Cos(fi60)*Sin(fi1), R1*Sin(fi60)*Sin(fi1), d1+R1-R1*Cos(fi1), ms[ms1+1]};
Point(p1+43)   = {-R1*Cos(fi60)*Sin(fi1), R1*Sin(fi60)*Sin(fi1), d1+R1-R1*Cos(fi1), ms[ms1+1]};
Point(p1+44)  = {-R1*Sin(fi1), 0, d1+R1-R1*Cos(fi1), ms[ms1+1]};


// ******************
// 2. sfçra (apakðçjâ)
// ******************

// Sfçras centrs
Point(p2+0)   = {0, 0, -(d2+R2), ms[ms2+0]};

// Virsotnes
//Point(p2+1)   = {0, 0, -d2, ms[ms2+1]};
Point(p2+2)   = {0, 0, -(d2+2*R2), ms[ms2+2]};
// Papildus centri ekvatoram paralçlajâm riòía lînijâm
//Point(p2+3)   = {0, 0, -(d2+R2-R2*Cos(fi21)), ms[ms2+4]};
//Point(p2+4)   = {0, 0, -(d2+R2+R2*Cos(fi22)), ms[ms2+5]};

// Ekvatora virsotnes
Point(p2+11)  = {R2, 0, -(d2+R2), ms[ms2+3]};
Point(p2+12)  = {R2*Cos(fi60), R2*Sin(fi60), -(d2+R2), ms[ms2+3]};
Point(p2+13)  = {-R2*Cos(fi60), R2*Sin(fi60), -(d2+R2), ms[ms2+3]};
Point(p2+14)  = {-R2, 0, -(d2+R2), ms[ms2+3]};

// Virsotnes pie fi21
Point(p2+21)  = {R2*Sin(fi21), 0, -(d2+R2-R2*Cos(fi21)), ms[ms2+4]};
Point(p2+22)  = {R2*Cos(fi60)*Sin(fi21), R2*Sin(fi60)*Sin(fi21), -(d2+R2-R2*Cos(fi21)), ms[ms2+4]};
Point(p2+23)  = {-R2*Cos(fi60)*Sin(fi21), R2*Sin(fi60)*Sin(fi21), -(d2+R2-R2*Cos(fi21)), ms[ms2+4]};
Point(p2+24)  = {-R2*Sin(fi21), 0, -(d2+R2-R2*Cos(fi21)), ms[ms2+4]};

// Virsotnes pie fi22
Point(p2+31)  = {R2*Sin(fi22), 0, -(d2+R2+R2*Cos(fi22)), ms[ms2+5]};
Point(p2+32)  = {R2*Cos(fi60)*Sin(fi22), R2*Sin(fi60)*Sin(fi22), -(d2+R2+R2*Cos(fi22)), ms[ms2+5]};
Point(p2+33)  = {-R2*Cos(fi60)*Sin(fi22), R2*Sin(fi60)*Sin(fi22), -(d2+R2+R2*Cos(fi22)), ms[ms2+5]};
Point(p2+34)  = {-R2*Sin(fi22), 0, -(d2+R2+R2*Cos(fi22)), ms[ms2+5]};

// Virsotnes pie fi2
Point(p2+41)  = {R2*Sin(fi2), 0, -(d2+R2-R2*Cos(fi2)), ms[ms2+1]};
Point(p2+42)  = {R2*Cos(fi60)*Sin(fi2), R2*Sin(fi60)*Sin(fi2), -(d2+R2-R2*Cos(fi2)), ms[ms2+1]};
Point(p2+43)  = {-R2*Cos(fi60)*Sin(fi2), R2*Sin(fi60)*Sin(fi2), -(d2+R2-R2*Cos(fi2)), ms[ms2+1]};
Point(p2+44)  = {-R2*Sin(fi2), 0, -(d2+R2-R2*Cos(fi2)), ms[ms2+1]};


///////////////////////
// Definçjam lînijas //
///////////////////////

l0 = 0;     // apkârtejâs telpas lînijas
l1 = 1000;  // 1. sfçras lînijas
l2 = 2000;  // 2. sfçras lînijas


// ***************
// Apkârtçjâ telpa
// ***************

// XY pl-ne, Z=0
Line(l0+0)    = {p0+0, p0+1};
Line(l0+1)    = {p0+1, p0+2};
Line(l0+2)    = {p0+2, p0+3};
Line(l0+3)    = {p0+3, p0+4};
Line(l0+4)    = {p0+4, p0+5};
Line(l0+5)    = {p0+5, p0+6};
Line(l0+6)    = {p0+6, p0+0};
Circle(l0+7)  = {p0+1, p0+0, p0+7};
Circle(l0+8)  = {p0+7, p0+0, p0+6};

// XY pl-ne, Z=LZ
Line(l0+10)   = {p0+10, p0+11};
Line(l0+11)   = {p0+11, p0+12};
Line(l0+12)   = {p0+12, p0+13};
Line(l0+13)   = {p0+13, p0+14};
Line(l0+14)   = {p0+14, p0+10};

// XY pl-ne, Z=-LZ
Line(l0+20)   = {p0+20, p0+21};
Line(l0+21)   = {p0+21, p0+22};
Line(l0+22)   = {p0+22, p0+23};
Line(l0+23)   = {p0+23, p0+24};
Line(l0+24)   = {p0+24, p0+20};


// Vertikâlâs lînijas

// Caur pusfçram
//Line(l0+31)   = {p0+0, p1+1};
Line(l0+32)   = {p1+2, p0+10};
//Line(l0+33)   = {p0+0, p2+1};
Line(l0+34)   = {p2+2, p0+20};


// Augðçjais pozitîvais tilpums
Line(l0+61)   = {p0+2, p0+11};
Line(l0+62)   = {p0+3, p0+12};
Line(l0+63)   = {p0+4, p0+13};
Line(l0+64)   = {p0+5, p0+14};

// Apakðçjais pozitîvais tilpums
Line(l0+71)   = {p0+2, p0+21};
Line(l0+72)   = {p0+3, p0+22};
Line(l0+73)   = {p0+4, p0+23};
Line(l0+74)   = {p0+5, p0+24};


// ******************
// 1. sfçra (augðçjâ)
// ******************


// Vertikâlâ pusfçru ass
Line(l1+1)    = {p0+0, p1+0};
Line(l1+3)    = {p1+0, p1+2};

// Vertikâlâs meridiânas
Circle(l1+11) = {p0+0, p1+0, p1+41};
Circle(l1+15) = {p1+41, p1+0, p1+21};
Circle(l1+12) = {p1+21, p1+0, p1+11};
Circle(l1+13) = {p1+11, p1+0, p1+31};
Circle(l1+14) = {p1+31, p1+0, p1+2};

Circle(l1+21) = {p0+0, p1+0, p1+42};
Circle(l1+25) = {p1+42, p1+0, p1+22};
Circle(l1+22) = {p1+22, p1+0, p1+12};
Circle(l1+23) = {p1+12, p1+0, p1+32};
Circle(l1+24) = {p1+32, p1+0, p1+2};

Circle(l1+31) = {p0+0, p1+0, p1+43};
Circle(l1+35) = {p1+43, p1+0, p1+23};
Circle(l1+32) = {p1+23, p1+0, p1+13};
Circle(l1+33) = {p1+13, p1+0, p1+33};
Circle(l1+34) = {p1+33, p1+0, p1+2};

Circle(l1+41) = {p0+0, p1+0, p1+44};
Circle(l1+45) = {p1+44, p1+0, p1+24};
Circle(l1+42) = {p1+24, p1+0, p1+14};
Circle(l1+43) = {p1+14, p1+0, p1+34};
Circle(l1+44) = {p1+34, p1+0, p1+2};

// Ekvators
Circle(l1+51) = {p1+11, p1+0, p1+12};
Circle(l1+52) = {p1+12, p1+0, p1+13};
Circle(l1+53) = {p1+13, p1+0, p1+14};

// Ekvatoram paralçlâs riòía lînijas
Circle(l1+61) = {p1+21, p1+0, p1+22};
Circle(l1+62) = {p1+22, p1+0, p1+23};
Circle(l1+63) = {p1+23, p1+0, p1+24};

Circle(l1+71) = {p1+31, p1+0, p1+32};
Circle(l1+72) = {p1+32, p1+0, p1+33};
Circle(l1+73) = {p1+33, p1+0, p1+34};

Circle(l1+81) = {p1+41, p1+0, p1+42};
Circle(l1+82) = {p1+42, p1+0, p1+43};
Circle(l1+83) = {p1+43, p1+0, p1+44};


// ******************
// 2. sfçra (apakðçjâ)
// ******************


// Vertikâlâ pusfçru ass
Line(l2+1)    = {p0+0, p2+0};
Line(l2+3)    = {p2+0, p2+2};

// Vertikâlâs meridiânas
Circle(l2+11) = {p0+0, p2+0, p2+41};
Circle(l2+15) = {p2+41, p2+0, p2+21};
Circle(l2+12) = {p2+21, p2+0, p2+11};
Circle(l2+13) = {p2+11, p2+0, p2+31};
Circle(l2+14) = {p2+31, p2+0, p2+2};

Circle(l2+21) = {p0+0, p2+0, p2+42};
Circle(l2+25) = {p2+42, p2+0, p2+22};
Circle(l2+22) = {p2+22, p2+0, p2+12};
Circle(l2+23) = {p2+12, p2+0, p2+32};
Circle(l2+24) = {p2+32, p2+0, p2+2};

Circle(l2+31) = {p0+0, p2+0, p2+43};
Circle(l2+35) = {p2+43, p2+0, p2+23};
Circle(l2+32) = {p2+23, p2+0, p2+13};
Circle(l2+33) = {p2+13, p2+0, p2+33};
Circle(l2+34) = {p2+33, p2+0, p2+2};

Circle(l2+41) = {p0+0, p2+0, p2+44};
Circle(l2+45) = {p2+44, p2+0, p2+24};
Circle(l2+42) = {p2+24, p2+0, p2+14};
Circle(l2+43) = {p2+14, p2+0, p2+34};
Circle(l2+44) = {p2+34, p2+0, p2+2};

// Ekvators
Circle(l2+51) = {p2+11, p2+0, p2+12};
Circle(l2+52) = {p2+12, p2+0, p2+13};
Circle(l2+53) = {p2+13, p2+0, p2+14};

// Ekvatoram paralçlâs riòía lînijas
Circle(l2+61) = {p2+21, p2+0, p2+22};
Circle(l2+62) = {p2+22, p2+0, p2+23};
Circle(l2+63) = {p2+23, p2+0, p2+24};

Circle(l2+71) = {p2+31, p2+0, p2+32};
Circle(l2+72) = {p2+32, p2+0, p2+33};
Circle(l2+73) = {p2+33, p2+0, p2+34};

Circle(l2+81) = {p2+41, p2+0, p2+42};
Circle(l2+82) = {p2+42, p2+0, p2+43};
Circle(l2+83) = {p2+43, p2+0, p2+44};



////////////////////////
// Definçjam kontûras //
////////////////////////


ll0 = 10000;
ll1 = ll0+1000;
ll2 = ll0+2000;

// ***************
// Apkârtçjâ telpa
// ***************

// Horizontâlais kontûrs

// R0 kontûrs
Line Loop(ll0+0)    = {l0+0,l0+7,l0+8,l0+6};
// Kontûrs XY pl-nç, kad Z=0
Line Loop(ll0+1)    = {-(l0+7),l0+1,l0+2,l0+3,l0+4,l0+5,-(l0+8)};
// Kontûrs XY pl-nç, kad Z=LZ
Line Loop(ll0+10)    = {l0+10,l0+11,l0+12,l0+13,l0+14};
// Kontûrs XY pl-nç, kad Z=-LZ
Line Loop(ll0+20)    = {l0+20,l0+21,l0+22,l0+23,l0+24};

// Vertikâlais kontûrs

// Augðçjam tilpumam
Line Loop(ll0+11)   = {l0+0,l0+1,l0+61,-(l0+10),-(l0+32),-(l1+14),-(l1+13),-(l1+12),-(l1+15),-(l1+11)};
Line Loop(ll0+12)   = {l0+2,l0+62,-(l0+11),-(l0+61)};
Line Loop(ll0+13)   = {l0+3,l0+63,-(l0+12),-(l0+62)};
Line Loop(ll0+14)   = {-(l0+4),l0+63,l0+13,-(l0+64)};
Line Loop(ll0+15)   = {-(l0+6),-(l0+5),l0+64,l0+14,-(l0+32),-(l1+44),-(l1+43),-(l1+42),-(l1+45),-(l1+41)};


// Apakðçjam tilpumam
Line Loop(ll0+21)   = {l0+0,l0+1,l0+71,-(l0+20),-(l0+34),-(l2+14),-(l2+13),-(l2+12),-(l2+15),-(l2+11)};
Line Loop(ll0+22)   = {l0+2,l0+72,-(l0+21),-(l0+71)};
Line Loop(ll0+23)   = {l0+3,l0+73,-(l0+22),-(l0+72)};
Line Loop(ll0+24)   = {-(l0+4),l0+73,l0+23,-(l0+74)};
Line Loop(ll0+25)   = {-(l0+6),-(l0+5),l0+74,l0+24,-(l0+34),-(l2+44),-(l2+43),-(l2+42),-(l2+45),-(l2+41)};


// ******************
// 1. sfçra (augðçjâ)
// ******************

// XY pl-nç
Line Loop(ll1+1)    = {l1+11,l1+15,l1+12,l1+13,l1+14,-(l1+3),-(l1+1)};
Line Loop(ll1+2)    = {l1+41,l1+45,l1+42,l1+43,l1+44,-(l1+3),-(l1+1)};

// Mediânas
Line Loop(ll1+11)   = {l1+11,l1+81,-(l1+21)};
Line Loop(ll1+12)   = {l1+15,l1+61,-(l1+25),-(l1+81)};
Line Loop(ll1+13)   = {l1+12,l1+51,-(l1+22),-(l1+61)};
Line Loop(ll1+14)   = {l1+13,l1+71,-(l1+23),-(l1+51)};
Line Loop(ll1+15)   = {l1+14,-(l1+24),-(l1+71)};

Line Loop(ll1+21)   = {l1+21,l1+82,-(l1+31)};
Line Loop(ll1+22)   = {l1+25,l1+62,-(l1+35),-(l1+82)};
Line Loop(ll1+23)   = {l1+22,l1+52,-(l1+32),-(l1+62)};
Line Loop(ll1+24)   = {l1+23,l1+72,-(l1+33),-(l1+52)};
Line Loop(ll1+25)   = {l1+24,-(l1+34),-(l1+72)};

Line Loop(ll1+31)   = {l1+31,l1+83,-(l1+41)};
Line Loop(ll1+32)   = {l1+35,l1+63,-(l1+45),-(l1+83)};
Line Loop(ll1+33)   = {l1+32,l1+53,-(l1+42),-(l1+63)};
Line Loop(ll1+34)   = {l1+33,l1+73,-(l1+43),-(l1+53)};
Line Loop(ll1+35)   = {l1+34,-(l1+44),-(l1+73)};


// ******************
// 2. sfçra (apakðçjâ)
// ******************

// XY pl-nç
Line Loop(ll2+1)    = {l2+11,l2+15,l2+12,l2+13,l2+14,-(l2+3),-(l2+1)};
Line Loop(ll2+2)    = {l2+41,l2+45,l2+42,l2+43,l2+44,-(l2+3),-(l2+1)};

// Mediânas
Line Loop(ll2+11)   = {l2+11,l2+81,-(l2+21)};
Line Loop(ll2+12)   = {l2+15,l2+61,-(l2+25),-(l2+81)};
Line Loop(ll2+13)   = {l2+12,l2+51,-(l2+22),-(l2+61)};
Line Loop(ll2+14)   = {l2+13,l2+71,-(l2+23),-(l2+51)};
Line Loop(ll2+15)   = {l2+14,-(l2+24),-(l2+71)};

Line Loop(ll2+21)   = {l2+21,l2+82,-(l2+31)};
Line Loop(ll2+22)   = {l2+25,l2+62,-(l2+35),-(l2+82)};
Line Loop(ll2+23)   = {l2+22,l2+52,-(l2+32),-(l2+62)};
Line Loop(ll2+24)   = {l2+23,l2+72,-(l2+33),-(l2+52)};
Line Loop(ll2+25)   = {l2+24,-(l2+34),-(l2+72)};

Line Loop(ll2+31)   = {l2+31,l2+83,-(l2+41)};
Line Loop(ll2+32)   = {l2+35,l2+63,-(l2+45),-(l2+83)};
Line Loop(ll2+33)   = {l2+32,l2+53,-(l2+42),-(l2+63)};
Line Loop(ll2+34)   = {l2+33,l2+73,-(l2+43),-(l2+53)};
Line Loop(ll2+35)   = {l2+34,-(l2+44),-(l2+73)};


///////////////////////
// Definçjam virsmas //
///////////////////////


s0 = 0;
s1 = 100;
s2 = 200;


// ***************
// Apkârtçjâ telpa
// ***************

// Horizontâlâs plaknes

// XY pl-ne, Z=0
Plane Surface(s0+0)  = {ll0+0};
Plane Surface(s0+1)  = {ll0+1};
// XY pl-ne, Z=LZ
Plane Surface(s0+2)  = {ll0+10};
// XY pl-ne, Z=-LZ
Plane Surface(s0+3)  = {ll0+20};

// Vertikâlâs plaknes
Plane Surface(s0+10)  = {ll0+11};
Plane Surface(s0+11)  = {ll0+15};
Plane Surface(s0+12)  = {ll0+12};
Plane Surface(s0+13)  = {ll0+13};
Plane Surface(s0+14)  = {ll0+14};


Plane Surface(s0+20)  = {ll0+21};
Plane Surface(s0+21)  = {ll0+25};
Plane Surface(s0+22)  = {ll0+22};
Plane Surface(s0+23)  = {ll0+23};
Plane Surface(s0+24)  = {ll0+24};


// ******************
// 1. sfçra (augðçjâ)
// ******************

Plane Surface(s1+0)   = {ll1+1};
Plane Surface(s1+1)   = {ll1+2};
Ruled Surface(s1+10)  = {ll1+11};
Ruled Surface(s1+11)  = {ll1+12};
Ruled Surface(s1+12)  = {ll1+13};
Ruled Surface(s1+13)  = {ll1+14};
Ruled Surface(s1+14)  = {ll1+21};
Ruled Surface(s1+15)  = {ll1+22};
Ruled Surface(s1+16)  = {ll1+23};
Ruled Surface(s1+17)  = {ll1+24};
Ruled Surface(s1+18)  = {ll1+31};
Ruled Surface(s1+19)  = {ll1+32};
Ruled Surface(s1+20)  = {ll1+33};
Ruled Surface(s1+21)  = {ll1+34};
Ruled Surface(s1+22)  = {ll1+15};
Ruled Surface(s1+23)  = {ll1+25};
Ruled Surface(s1+24)  = {ll1+35};


// *******************
// 2. sfçra (apakðçjâ)
// *******************

Plane Surface(s2+0)   = {ll2+1};
Plane Surface(s2+1)   = {ll2+2};
Ruled Surface(s2+10)  = {ll2+11};
Ruled Surface(s2+11)  = {ll2+12};
Ruled Surface(s2+12)  = {ll2+13};
Ruled Surface(s2+13)  = {ll2+14};
Ruled Surface(s2+14)  = {ll2+21};
Ruled Surface(s2+15)  = {ll2+22};
Ruled Surface(s2+16)  = {ll2+23};
Ruled Surface(s2+17)  = {ll2+24};
Ruled Surface(s2+18)  = {ll2+31};
Ruled Surface(s2+19)  = {ll2+32};
Ruled Surface(s2+20)  = {ll2+33};
Ruled Surface(s2+21)  = {ll2+34};
Ruled Surface(s2+22)  = {ll2+15};
Ruled Surface(s2+23)  = {ll2+25};
Ruled Surface(s2+24)  = {ll2+35};



///////////////////////////////
// Definçjam slçgtas virsmas //
///////////////////////////////

sl0 = 0;
sl1 = 10;
sl2 = 20;

// Apkârtejâ telpa

Surface Loop(sl0+1) = {s0+0, s0+1, s0+2, s0+10, s0+11, s0+12, s0+13, s0+14, s1+10, s1+11, s1+12, s1+13, s1+14, s1+15, s1+16, s1+17, s1+18, s1+19, s1+20, s1+21};
Surface Loop(sl0+2) = {s0+0, s0+1, s0+3, s0+20, s0+21, s0+22, s0+23, s0+24, s2+10, s2+11, s2+12, s2+13, s2+14, s2+15, s2+16, s2+17, s2+18, s2+19, s2+20, s2+21};

// 1. sfçra
Surface Loop(sl1+0) = {s1+0, s1+1, s1+10, s1+11, s1+12, s1+13, s1+14, s1+15, s1+16, s1+17, s1+18, s1+19, s1+20, s1+21, s1+22, s1+23, s1+24};

// 2. sfçra
Surface Loop(sl2+0) = {s2+0, s2+1, s2+10, s2+11, s2+12, s2+13, s2+14, s2+15, s2+16, s2+17, s2+18, s2+19, s2+20, s2+21, s2+22, s2+23, s2+24};




///////////////////////
// Definçjam tilpumu //
///////////////////////

v0 = 0;
v1 = 10;
v2 = 20;

// Apkârtçjâ telpa
Volume(v0+1) = {sl0+1};
Volume(v0+2) = {sl0+2};

// 1. sfçra
Volume(v1+0) = {sl1+0};

// 2. sfçra
Volume(v2+0) = {sl2+0};




///////////////////////////////////
// Iekïaujam pçcapstrâdes skatus //
///////////////////////////////////

/*
Include "qsphere.pos";

//General.Trackball = 0 ;
//General.RotationX = 0 ;
//General.RotationY = 0 ;
//General.RotationZ = 0 ;
//General.Color.Background = White ;
//General.Color.Foreground = Black ;
//General.Color.Text = Black ;
//General.Orthographic = 0 ;
//General.Axes = 0 ;
//General.SmallAxes = 0 ;

//View[0].IntervalsType = 2;
//View[0].NbIso = 90 ;
//View[0].SmoothNormals = 1;
//View[0].ShowScale = 1;
//View[0].Type = 3;

View[0].Visible = 0;
View[1].Visible = 1;
View[2].Visible = 0;
View[3].Visible = 0;
View[4].Visible = 0;
View[5].Visible = 0;
View[6].Visible = 0;
View[7].Visible = 0;
View[8].Visible = 0;
View[9].Visible = 0;

View[1].Boundary = 1;
View[3].Boundary = 1;
View[5].Boundary = 1;
View[7].Boundary = 1;
View[9].Boundary = 1;

Plugin(CutPlane).A = 1;
Plugin(CutPlane).B = 2;
Plugin(CutPlane).C = 1;
Plugin(CutPlane).D = 0;
//Plugin(CutPlane).Run;
*/
// vim: set filetype=gmsh :  // 
