qem.h 45.2 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
/*******************************************************************************
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 * CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
 * version 0.1                                                                  *
 * Copyright (C) 2009-2012, IGG Team, LSIIT, University of Strasbourg           *
 *                                                                              *
 * This library is free software; you can redistribute it and/or modify it      *
 * under the terms of the GNU Lesser General Public License as published by the *
 * Free Software Foundation; either version 2.1 of the License, or (at your     *
 * option) any later version.                                                   *
 *                                                                              *
 * This library is distributed in the hope that it will be useful, but WITHOUT  *
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
 * for more details.                                                            *
 *                                                                              *
 * You should have received a copy of the GNU Lesser General Public License     *
 * along with this library; if not, write to the Free Software Foundation,      *
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
 *                                                                              *
 * Web site: http://cgogn.unistra.fr/                                           *
 * Contact information: cgogn@unistra.fr                                        *
 *                                                                              *
 *******************************************************************************/
Pierre Kraemer's avatar
Pierre Kraemer committed
24
25
26
27

#ifndef __QEM__
#define __QEM__

28
#include "Utils/os_spec.h" // allow compilation under windows
29
#include <cmath>
30

Pierre Kraemer's avatar
Pierre Kraemer committed
31
32
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
33
#include "Geometry/tensor.h"
Pierre Kraemer's avatar
Pierre Kraemer committed
34
35
#include "Geometry/plane_3d.h"

36
37
// Eigen includes
#include <Eigen/Dense>
38

39
40
#define CONST_VAL -5212368.54127

41
42
43
44
namespace CGoGN {

//namespace Utils {

Pierre Kraemer's avatar
Pierre Kraemer committed
45
46
47
48
49
50
template <typename REAL>
class Quadric
{
public:
	static std::string CGoGNnameOfType() { return "Quadric" ; }

51
52
53
	typedef Geom::Vector<3,REAL> VEC3 ;
	typedef Geom::Vector<4,REAL> VEC4 ;
	typedef Geom::Matrix<4,4,double> MATRIX44 ; // double is crucial here !
Pierre Kraemer's avatar
Pierre Kraemer committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67

	Quadric()
	{
		A.zero() ;
	}

	Quadric(int i)
	{
		A.zero() ;
	}

	Quadric(VEC3& p1, VEC3& p2, VEC3& p3)
	{
		// compute the equation of the plane of the 3 points
68
69
70
71
72
		Geom::Plane3D<REAL> plane(p1, p2, p3) ;
		const VEC3& n = plane.normal() ;

		Geom::Vector<4,double> p = Geom::Vector<4,double>(n[0],n[1],n[2],plane.d()) ;
		A = Geom::transposed_vectors_mult(p,p) ;
Pierre Kraemer's avatar
Pierre Kraemer committed
73
74
75
76
77
78
79
80
81
82
83
84
	}

	void zero()
	{
		A.zero() ;
	}

	void operator= (const Quadric<REAL>& q)
	{
		A = q.A ;
	}
	Quadric& operator+= (const Quadric<REAL>& q)
85
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
86
87
		A += q.A ;
		return *this ;
88
					}
Pierre Kraemer's avatar
Pierre Kraemer committed
89
	Quadric& operator -= (const Quadric<REAL>& q)
90
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
91
92
		A -= q.A ;
		return *this ;
93
					}
Pierre Kraemer's avatar
Pierre Kraemer committed
94
	Quadric& operator *= (REAL v)
95
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
96
97
		A *= v ;
		return *this ;
98
					}
Pierre Kraemer's avatar
Pierre Kraemer committed
99
	Quadric& operator /= (REAL v)
100
					{
Pierre Kraemer's avatar
Pierre Kraemer committed
101
102
		A /= v ;
		return *this ;
103
					}
Pierre Kraemer's avatar
Pierre Kraemer committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

	REAL operator() (const VEC4& v) const
	{
		return evaluate(v) ;
	}

	REAL operator() (const VEC3& v) const
	{
		VEC4 hv(v[0], v[1], v[2], 1.0f) ;
		return evaluate(hv) ;
	}

	friend std::ostream& operator<<(std::ostream& out, const Quadric<REAL>& q)
	{
		out << q.A ;
		return out ;
	}

	friend std::istream& operator>>(std::istream& in, Quadric<REAL>& q)
	{
		in >> q.A ;
		return in ;
	}

	bool findOptimizedPos(VEC3& v)
	{
		VEC4 hv ;
		bool b = optimize(hv) ;
		if(b)
		{
			v[0] = hv[0] ;
			v[1] = hv[1] ;
			v[2] = hv[2] ;
		}
		return b ;
	}

private:
	MATRIX44 A ;

144
	REAL evaluate(const VEC4& v) const
Pierre Kraemer's avatar
Pierre Kraemer committed
145
	{
146
147
		// Double computation is crucial for stability
		Geom::Vector<4, double> Av = A * v ;
Pierre Kraemer's avatar
Pierre Kraemer committed
148
149
150
151
152
		return v * Av ;
	}

	bool optimize(VEC4& v) const
	{
153
		if (std::isnan(A(0,0)))
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
154
155
			return false ;

Pierre Kraemer's avatar
Pierre Kraemer committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
		MATRIX44 A2(A) ;
		for(int i = 0; i < 3; ++i)
			A2(3,i) = 0.0f ;
		A2(3,3) = 1.0f ;

		MATRIX44 Ainv ;
		REAL det = A2.invert(Ainv) ;

		if(det > -1e-6 && det < 1e-6)
			return false ;

		VEC4 right(0,0,0,1) ;
		v = Ainv * right ;

		return true;
	}
} ;

174
175
176
177
178
179
180
181
182
183
184
template <typename REAL, unsigned int N>
class QuadricNd
{
public:
	static std::string CGoGNnameOfType() { return "QuadricNd" ; }

	typedef Geom::Vector<N,REAL> VECN ;
	typedef Geom::Vector<N+1,REAL> VECNp ;

	QuadricNd()
	{
185
186
187
		A.zero() ;
		b.zero() ;
		c = 0 ;
188
189
190
191
	}

	QuadricNd(int i)
	{
192
193
194
		A.zero() ;
		b.zero() ;
		c = 0 ;
195
196
197
198
199
200
201
202
203
	}

	QuadricNd(const VECN& p1_r, const VECN& p2_r, const VECN& p3_r)
	{
		const Geom::Vector<N,double>& p1 = p1_r ;
		const Geom::Vector<N,double>& p2 = p2_r ;
		const Geom::Vector<N,double>& p3 = p3_r ;

		Geom::Vector<N,double> e1 = p2 - p1 ; 						e1.normalize() ;
204
		Geom::Vector<N,double> e2 = (p3 - p1) - (e1*(p3-p1))*e1 ; 	e2.normalize() ;
205
206

		A.identity() ;
207
		A -= Geom::transposed_vectors_mult(e1,e1) + Geom::transposed_vectors_mult(e2,e2) ;
208

209
		b = (p1*e1)*e1 + (p1*e2)*e2 - p1 ;
210

211
		c = p1*p1 - pow((p1*e1),2) - pow((p1*e2),2) ;
212
213
214
215
	}

	void zero()
	{
216
217
218
		A.zero() ;
		b.zero() ;
		c = 0 ;
219
220
221
222
	}

	void operator= (const QuadricNd<REAL,N>& q)
	{
223
224
225
		A = q.A ;
		b = q.b ;
		c = q.c ;
226
227
	}
	QuadricNd& operator+= (const QuadricNd<REAL,N>& q)
228
					{
229
230
231
		A += q.A ;
		b += q.b ;
		c += q.c ;
232
		return *this ;
233
					}
234

235
	QuadricNd& operator -= (const QuadricNd<REAL,N>& q)
236
					{
237
238
239
		A -= q.A ;
		b -= q.b ;
		c -= q.c ;
240
		return *this ;
241
					}
242

243
	QuadricNd& operator *= (REAL v)
244
					{
245
246
247
		A *= v ;
		b *= v ;
		c *= v ;
248
		return *this ;
249
					}
250
	QuadricNd& operator /= (REAL v)
251
					{
252
253
254
		A /= v ;
		b /= v ;
		c /= v ;
255
		return *this ;
256
					}
257
258
259

	REAL operator() (const VECNp& v) const
	{
260
261
262
263
		VECN hv ;
		for (unsigned int i = 0 ; i < N ; ++i)
			hv[i] = v[i] ;

264
265
266
267
268
		return evaluate(v) ;
	}

	REAL operator() (const VECN& v) const
	{
269
		return evaluate(v) ;
270
271
272
273
	}

	friend std::ostream& operator<<(std::ostream& out, const QuadricNd<REAL,N>& q)
	{
274
		out << "(" << q.A << ", " << q.b << ", " << q.c << ")" ;
275
276
277
278
279
		return out ;
	}

	friend std::istream& operator>>(std::istream& in, QuadricNd<REAL,N>& q)
	{
280
281
282
		in >> q.A ;
		in >> q.b ;
		in >> q.c ;
283
284
285
		return in ;
	}

286
	bool findOptimizedVec(VECN& v)
287
	{
288
		return optimize(v) ;
289
290
291
	}

private:
292
293
294
295
	// Double computation is crucial for stability
	Geom::Matrix<N,N,double> A ;
	Geom::Vector<N,double> b ;
	double c ;
296

297
	REAL evaluate(const VECN& v) const
298
	{
299
300
		Geom::Vector<N, double> v_d = v ;
		return v_d*A*v_d + 2.*(b*v_d) + c ;
301
302
	}

303
	bool optimize(VECN& v) const
304
	{
305
		if (std::isnan(A(0,0)))
306
307
			return false ;

308
309
		Geom::Matrix<N,N,double> Ainv ;
		double det = A.invert(Ainv) ;
310
311
312
313

		if(det > -1e-6 && det < 1e-6)
			return false ;

314
315
		v.zero() ;
		v -= Ainv * b ;
316

317
		return true ;
318
319
320
	}
} ;

321
322
323
324
325
326
template <typename REAL>
class QuadricHF
{
public:
	static std::string CGoGNnameOfType() { return "QuadricHF" ; }

327
	typedef Geom::Vector<3,REAL> VEC3 ;
328
329

	QuadricHF()
330
	{}
331

332
	QuadricHF(int i)
333
	{
334
		m_A.resize(i,i) ;
335
336
337
338
339
340
341
342
343
344
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			m_b[c].resize(i) ;
			m_c[c] = 0 ;
		}
	}

	QuadricHF(const std::vector<VEC3>& v, const REAL& gamma, const REAL& alpha)
	{
		*this = QuadricHF(tensorsFromCoefs(v), gamma, alpha) ;
345
346
	}

347
	QuadricHF(const Geom::Tensor3d* T, const REAL& gamma, const REAL& alpha)
348
	{
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
		const unsigned int nbcoefs = ((T[0].order() + 1) * (T[0].order() + 2)) / 2. ;

		//m_A.resize(nbcoefs, nbcoefs) ;

		// 2D rotation
		const Geom::Matrix33d R = rotateMatrix(gamma) ;
		Geom::Tensor3d* Trot = new Geom::Tensor3d[3] ;
		for (unsigned int c = 0 ; c < 3 ; ++c)
			Trot[c] = rotate(T[c],R) ;
		std::vector<VEC3> coefsR = coefsFromTensors(Trot) ;

		// parameterized integral on intersection

		// build A, b and c
		m_A = buildIntegralMatrix_A(alpha,nbcoefs) ; // Parameterized integral matrix A
		Eigen::MatrixXd integ_b = buildIntegralMatrix_B(alpha,nbcoefs) ; // Parameterized integral matrix b
		Eigen::MatrixXd integ_c = buildIntegralMatrix_C(alpha,nbcoefs) ; // Parameterized integral matrix c

//		for (unsigned int i = 0 ; i < nbcoefs ; ++i)
//			for (unsigned int j = 0 ; j < nbcoefs ; ++j)
//				std::cout << "(" << i << "," << j << ")=" << m_A(i,j) << std::endl ;
//
//		for (unsigned int i = 0 ; i < nbcoefs ; ++i)
//			for (unsigned int j = 0 ; j < nbcoefs ; ++j)
//				std::cout << "(" << i << "," << j << ")=" << integ_b(i,j) << std::endl ;
//
//		for (unsigned int i = 0 ; i < nbcoefs ; ++i)
//			for (unsigned int j = 0 ; j < nbcoefs ; ++j)
//				std::cout << "(" << i << "," << j << ")=" << integ_c(i,j) << std::endl ;

		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			Eigen::VectorXd v ;	v.resize(nbcoefs) ;
			for (unsigned int i = 0 ; i < nbcoefs ; ++i) // copy into vector
				v[i] = coefsR[i][c] ;

			m_b[c] = integ_b * v ; // Vector b
			m_c[c] = v.transpose() * (integ_c * v) ; // Constant c
		}
388
	}
389

390
	~QuadricHF()
391
392
393
394
395
	{
		//delete m_A ;
		//for (unsigned int c = 0 ; c < 3 ; ++c)
		//	delete m_b[c] ;
	}
396
397
398

	void zero()
	{
399
		m_A.setZero() ;
400
401
402
403
404
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			m_b[c].setZero() ;
			m_c[c] = 0 ;
		}
405
406
	}

407
	QuadricHF& operator= (const QuadricHF<REAL>& q)
408
	{
409
		m_A = q.m_A ;
410
411
412
413
414
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			m_b[c] = q.m_b[c] ;
			m_c[c] = q.m_c[c] ;
		}
415
416

		return *this ;
417
	}
418

419
420
	QuadricHF& operator+= (const QuadricHF<REAL>& q)
	{
421
422
		assert(((m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && m_b[0].size() == q.m_b[0].size()) || !"Incompatible add of matrices") ;
		if (!(m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && (m_b[0].size() == q.m_b[0].size()))
423
424
			return *this ;

425
		m_A += q.m_A ;
426
427
428
429
430
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			m_b[c] += q.m_b[c] ;
			m_c[c] += q.m_c[c] ;
		}
431

432
433
434
435
		return *this ;
	}

	QuadricHF& operator -= (const QuadricHF<REAL>& q)
436
437
438
					{
		assert(((m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && m_b[0].size() == q.m_b[0].size()) || !"Incompatible substraction of matrices") ;
		if ((m_A.cols() == q.m_A.cols()) && (m_A.rows() == q.m_A.rows()) && (m_b[0].size() == q.m_b[0].size()))
439
440
			return *this ;

441
		m_A -= q.m_A ;
442
443
444
445
446
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			m_b[c] -= q.m_b[c] ;
			m_c[c] -= q.m_c[c] ;
		}
447

448
		return *this ;
449
					}
450

451
	QuadricHF& operator *= (const REAL& v)
452
					{
453
		m_A *= v ;
454
455
456
457
458
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			m_b[c] *= v ;
			m_c[c] *= v ;
		}
459

460
		return *this ;
461
462
					}

463
	QuadricHF& operator /= (const REAL& v)
464
					{
465
		const REAL& inv = 1. / v ;
466

467
		(*this) *= inv ;
468

469
		return *this ;
470
					}
471

472
473
474
475
476
477
478
479
	//	REAL operator() (const VECNp& v) const
	//	{
	//		VECN hv ;
	//		for (unsigned int i = 0 ; i < 3 ; ++i)
	//			hv[i] = v[i] ;
	//
	//		return evaluate(v) ;
	//	}
480
481

	REAL operator() (const std::vector<VEC3>& coefs) const
482
	{
483
		return evaluate(coefs) ;
484
485
486
487
	}

	friend std::ostream& operator<<(std::ostream& out, const QuadricHF<REAL>& q)
	{
488
		// TODO out << "(" << q.m_A << ", " << q.m_b << ", " << q.m_c << ")" ;
489
490
491
492
493
		return out ;
	}

	friend std::istream& operator>>(std::istream& in, QuadricHF<REAL>& q)
	{
494
		// TODO
495
496
497
		//		in >> q.A ;
		//		in >> q.b ;
		//		in >> q.c ;
498
499
500
		return in ;
	}

501
	bool findOptimizedCoefs(std::vector<VEC3>& coefs)
502
	{
503
504
505
506
507
508
509
510
511
512
//		unsigned int nbcoefs = 6 ;
//		for (unsigned int i = 0 ; i < nbcoefs ; ++i)
//			for (unsigned int j = 0 ; j < nbcoefs ; ++j)
//				std::cout << "A(" << i << "," << j << ")=" << m_A(i,j) << std::endl ;
//
//		for (unsigned int i = 0 ; i < nbcoefs ; ++i)
//				std::cout << "b(" << i << ")=" << m_b[0][i] << std::endl ;
//
//		std::cout << "c=" << m_c[0] << std::endl ;

513
		return optimize(coefs) ;
514
515
516
517
	}

private:
	// Double computation is crucial for stability
518
	Eigen::MatrixXd m_A ;
519
520
	Eigen::VectorXd m_b[3] ;
	double m_c[3] ;
521

522
	REAL evaluate(const std::vector<VEC3>& coefs) const
523
	{
524
525
526
527
528
529
530
531
532
533
534
535
536
537
		VEC3 res ;
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			Eigen::VectorXd tmp(coefs.size()) ;
			for (unsigned int i = 0 ; i < coefs.size() ; ++i)
				tmp[i] = coefs[i][c] ;
			res[c] = tmp.transpose() * m_A * tmp ;		// A
			res[c] -= 2. * (m_b[c]).transpose() * tmp ;	// - 2b
			res[c] += m_c[c] ;							// + c
		}

		res /= 2*M_PI ; // max integral value over hemisphere

		return (res[0] + res[1] + res[2]) / 3. ;
538
539
	}

540
	bool optimize(std::vector<VEC3>& coefs) const
541
	{
542
		coefs.resize(m_b[0].size()) ;
543

544
		if (fabs(m_A.determinant()) < 1e-6 )
545
546
			return false ;

547
		Eigen::MatrixXd Ainv = m_A.inverse() ;
548

549
550
551
552
553
554
555
		for (unsigned int c = 0 ; c < 3 ; ++c)
		{
			Eigen::VectorXd tmp(m_b[0].size()) ;
			tmp = Ainv * m_b[c] ;
			for (unsigned int i = 0 ; i < m_b[c].size() ; ++i)
				coefs[i][c] = tmp[i] ;
		}
556
557
558

		return true ;
	}
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278

	Geom::Matrix33d rotateMatrix(const REAL& gamma)
	{
		Geom::Matrix33d R ;
		R.identity() ;
		R(0,0) = cos(gamma) ;
		R(0,1) = sin(gamma) ;
		R(1,0) = -sin(gamma) ;
		R(1,1) = cos(gamma) ;

		return R ;
	}

	Geom::Tensor3d rotate(const Geom::Tensor3d& T, const Geom::Matrix33d& R)
	{
		Geom::Tensor3d Tp(T.order()) ;
		std::vector<unsigned int> p ; p.resize(T.order(), 0) ;
		for (unsigned int i = 0 ; i < T.nbElem() ; ++i)
		{
			REAL S = 0 ;
			std::vector<unsigned int> q ; q.resize(T.order(), 0) ;
			for (unsigned int j = 0 ; j < T.nbElem() ; ++j)
			{
				REAL P = T[j] ;
				for (unsigned int k = 0 ; k < T.order() ; ++k)
					P *= R(q[k],p[k]) ;
				S += P ;
				Geom::Tensor3d::incremIndex(q) ;
			}
			Tp[i] = S ;
			Geom::Tensor3d::incremIndex(p) ;
		}

		return Tp ;
	}

	Eigen::MatrixXd buildIntegralMatrix_A(const REAL& alpha, unsigned int size)
	{
		Eigen::MatrixXd A(size,size) ;

		A( 0 , 0 ) =  2*(M_PI-alpha) ;
		A( 0 , 1 ) =  M_PI*sin(alpha)/2.0 ;
		A( 0 , 2 ) =  0 ;
		A( 0 , 3 ) =  0 ;
		A( 0 , 4 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.0 ;
		A( 0 , 5 ) =  2.0*(M_PI-alpha)/3.0 ;
		A( 1 , 0 ) =  M_PI*sin(alpha)/2.0 ;
		A( 1 , 1 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.0 ;
		A( 1 , 2 ) =  0 ;
		A( 1 , 3 ) =  0 ;
		A( 1 , 4 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/8.0 ;
		A( 1 , 5 ) =  M_PI*sin(alpha)/8.0 ;
		A( 2 , 0 ) =  0 ;
		A( 2 , 1 ) =  0 ;
		A( 2 , 2 ) =  2.0*(M_PI-alpha)/3.0 ;
		A( 2 , 3 ) =  M_PI*sin(alpha)/8.0 ;
		A( 2 , 4 ) =  0 ;
		A( 2 , 5 ) =  0 ;
		A( 3 , 0 ) =  0 ;
		A( 3 , 1 ) =  0 ;
		A( 3 , 2 ) =  M_PI*sin(alpha)/8.0 ;
		A( 3 , 3 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		A( 3 , 4 ) =  0 ;
		A( 3 , 5 ) =  0 ;
		A( 4 , 0 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.0 ;
		A( 4 , 1 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/8.0 ;
		A( 4 , 2 ) =  0 ;
		A( 4 , 3 ) =  0 ;
		A( 4 , 4 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/3.0E+1 ;
		A( 4 , 5 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		A( 5 , 0 ) =  2.0*(M_PI-alpha)/3.0 ;
		A( 5 , 1 ) =  M_PI*sin(alpha)/8.0 ;
		A( 5 , 2 ) =  0 ;
		A( 5 , 3 ) =  0 ;
		A( 5 , 4 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		A( 5 , 5 ) =  2.0*(M_PI-alpha)/5.0 ;

		if (size < 7)
			return A ;

		A( 6 , 0 ) =  0 ;
		A( 6 , 1 ) =  0 ;
		A( 6 , 2 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		A( 6 , 3 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/4.8E+1 ;
		A( 6 , 4 ) =  0 ;
		A( 6 , 5 ) =  0 ;
		A( 6 , 6 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/2.1E+2 ;
		A( 6 , 7 ) =  0 ;
		A( 6 , 8 ) =  0 ;
		A( 6 , 9 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		A( 7 , 0 ) =  M_PI*sin(alpha)/8.0 ;
		A( 7 , 1 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		A( 7 , 2 ) =  0 ;
		A( 7 , 3 ) =  0 ;
		A( 7 , 4 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/4.8E+1 ;
		A( 7 , 5 ) =  M_PI*sin(alpha)/1.6E+1 ;
		A( 7 , 6 ) =  0 ;
		A( 7 , 7 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		A( 7 , 8 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/2.1E+2 ;
		A( 7 , 9 ) =  0 ;
		A( 8 , 0 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/8.0 ;
		A( 8 , 1 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/3.0E+1 ;
		A( 8 , 2 ) =  0 ;
		A( 8 , 3 ) =  0 ;
		A( 8 , 4 ) =  M_PI*(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/4.8E+1 ;
		A( 8 , 5 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/4.8E+1 ;
		A( 8 , 6 ) =  0 ;
		A( 8 , 7 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/2.1E+2 ;
		A( 8 , 8 ) =  -(9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha-60*M_PI )/2.1E+2 ;
		A( 8 , 9 ) =  0 ;
		A( 9 , 0 ) =  0 ;
		A( 9 , 1 ) =  0 ;
		A( 9 , 2 ) =  2.0*(M_PI-alpha)/5.0 ;
		A( 9 , 3 ) =  M_PI*sin(alpha)/1.6E+1 ;
		A( 9 , 4 ) =  0 ;
		A( 9 , 5 ) =  0 ;
		A( 9 , 6 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		A( 9 , 7 ) =  0 ;
		A( 9 , 8 ) =  0 ;
		A( 9 , 9 ) =  2.0*(M_PI-alpha)/7.0 ;

		if (size < 11)
			return A ;

		A( 10 , 0 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		A( 10 , 1 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/4.8E+1 ;
		A( 10 , 2 ) =  0 ;
		A( 10 , 3 ) =  0 ;
		A( 10 , 4 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/2.1E+2 ;
		A( 10 , 5 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		A( 10 , 6 ) =  0 ;
		A( 10 , 7 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/1.28E+2 ;
		A( 10 , 8 ) =  M_PI*(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/3.84E+2 ;
		A( 10 , 9 ) =  0 ;
		A( 10 , 10 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/6.3E+2 ;
		A( 10 , 11 ) =  0 ;
		A( 10 , 12 ) =  0 ;
		A( 10 , 13 ) =  -(9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha-60*M_PI )/1.89E+3 ;
		A( 10 , 14 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/6.3E+1 ;
		A( 11 , 0 ) =  0 ;
		A( 11 , 1 ) =  0 ;
		A( 11 , 2 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/4.8E+1 ;
		A( 11 , 3 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/2.1E+2 ;
		A( 11 , 4 ) =  0 ;
		A( 11 , 5 ) =  0 ;
		A( 11 , 6 ) =  M_PI*(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/3.84E+2 ;
		A( 11 , 7 ) =  0 ;
		A( 11 , 8 ) =  0 ;
		A( 11 , 9 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/1.28E+2 ;
		A( 11 , 10 ) =  0 ;
		A( 11 , 11 ) =  -(9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha-60*M_PI )/1.89E+3 ;
		A( 11 , 12 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/6.3E+2 ;
		A( 11 , 13 ) =  0 ;
		A( 11 , 14 ) =  0 ;
		A( 12 , 0 ) =  0 ;
		A( 12 , 1 ) =  0 ;
		A( 12 , 2 ) =  M_PI*sin(alpha)/1.6E+1 ;
		A( 12 , 3 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		A( 12 , 4 ) =  0 ;
		A( 12 , 5 ) =  0 ;
		A( 12 , 6 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/1.28E+2 ;
		A( 12 , 7 ) =  0 ;
		A( 12 , 8 ) =  0 ;
		A( 12 , 9 ) =  5.0*M_PI*sin(alpha)/1.28E+2 ;
		A( 12 , 10 ) =  0 ;
		A( 12 , 11 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/6.3E+2 ;
		A( 12 , 12 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/6.3E+1 ;
		A( 12 , 13 ) =  0 ;
		A( 12 , 14 ) =  0 ;
		A( 13 , 0 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/3.0E+1 ;
		A( 13 , 1 ) =  M_PI*(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/4.8E+1 ;
		A( 13 , 2 ) =  0 ;
		A( 13 , 3 ) =  0 ;
		A( 13 , 4 ) =  -(9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha-60*M_PI )/2.1E+2 ;
		A( 13 , 5 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/2.1E+2 ;
		A( 13 , 6 ) =  0 ;
		A( 13 , 7 ) =  M_PI*(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/3.84E+2 ;
		A( 13 , 8 ) =  -M_PI*(5*pow(sin(alpha),7)-21*pow(sin(alpha),5)+35*pow(sin(alpha),3)-35*sin(alpha))/1.28E+2 ;
		A( 13 , 9 ) =  0 ;
		A( 13 , 10 ) =  -(9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha-60*M_PI )/1.89E+3 ;
		A( 13 , 11 ) =  0 ;
		A( 13 , 12 ) =  0 ;
		A( 13 , 13 ) =  -(3*sin(8*alpha)+168*sin(4*alpha)-128*pow(sin(2*alpha),3)+768*sin(2*alpha)+840*alpha-840*M_PI)/3.78E+3 ;
		A( 13 , 14 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/6.3E+2 ;
		A( 14 , 0 ) =  2.0*(M_PI-alpha)/5.0 ;
		A( 14 , 1 ) =  M_PI*sin(alpha)/1.6E+1 ;
		A( 14 , 2 ) =  0 ;
		A( 14 , 3 ) =  0 ;
		A( 14 , 4 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		A( 14 , 5 ) =  2.0*(M_PI-alpha)/7.0 ;
		A( 14 , 6 ) =  0 ;
		A( 14 , 7 ) =  5.0*M_PI*sin(alpha)/1.28E+2 ;
		A( 14 , 8 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/1.28E+2 ;
		A( 14 , 9 ) =  0 ;
		A( 14 , 10 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/6.3E+1 ;
		A( 14 , 11 ) =  0 ;
		A( 14 , 12 ) =  0 ;
		A( 14 , 13 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/6.3E+2 ;
		A( 14 , 14 ) =  2.0*(M_PI-alpha)/9.0 ;

		return A ;
	}

	Eigen::MatrixXd buildIntegralMatrix_B(const REAL& alpha, unsigned int size)
	{
		Eigen::MatrixXd B(size,size) ;

		B( 0 , 0 ) =  2*(M_PI-alpha) ;
		B( 0 , 1 ) =  M_PI*(sin(2*alpha)+sin(alpha))/2.0 ;
		B( 0 , 2 ) =  0 ;
		B( 0 , 3 ) =  0 ;
		B( 0 , 4 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.0 ;
		B( 0 , 5 ) =  2.0*(M_PI-alpha)/3.0 ;
		B( 1 , 0 ) =  M_PI*sin(alpha)/2.0 ;
		B( 1 , 1 ) =  4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/3.0 ;
		B( 1 , 2 ) =  0 ;
		B( 1 , 3 ) =  0 ;
		B( 1 , 4 ) =  3.0*M_PI*((sin(5*alpha)+3*sin(3*alpha)+6*sin(alpha))/1.2E+1+sin( 2*alpha)/3.0)/8.0 ;
		B( 1 , 5 ) =  M_PI*sin(alpha)/8.0 ;
		B( 2 , 0 ) =  0 ;
		B( 2 , 1 ) =  0 ;
		B( 2 , 2 ) =  2.0*(M_PI-alpha)/3.0 ;
		B( 2 , 3 ) =  M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
		B( 2 , 4 ) =  0 ;
		B( 2 , 5 ) =  0 ;
		B( 3 , 0 ) =  0 ;
		B( 3 , 1 ) =  0 ;
		B( 3 , 2 ) =  M_PI*sin(alpha)/8.0 ;
		B( 3 , 3 ) =  4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/1.5E+1 ;
		B( 3 , 4 ) =  0 ;
		B( 3 , 5 ) =  0 ;
		B( 4 , 0 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.0 ;
		B( 4 , 1 ) =  3.0*M_PI*((sin(4*alpha)+6*sin(2*alpha))/1.2E+1+sin(alpha)/3.0 )/8.0 ;
		B( 4 , 2 ) =  0 ;
		B( 4 , 3 ) =  0 ;
		B( 4 , 4 ) =  1.6E+1*(5.0*sin(2*alpha)/3.2E+1-(sin(6*alpha)+4*sin(4*alpha)+4* sin(2*alpha)+(4*alpha-4*M_PI)*cos(2*alpha)+8*alpha-8*M_PI)/3.2E+1 )/1.5E+1 ;
		B( 4 , 5 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		B( 5 , 0 ) =  2.0*(M_PI-alpha)/3.0 ;
		B( 5 , 1 ) =  M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
		B( 5 , 2 ) =  0 ;
		B( 5 , 3 ) =  0 ;
		B( 5 , 4 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
		B( 5 , 5 ) =  2.0*(M_PI-alpha)/5.0 ;

		if (size < 7)
			return B ;

		B( 6 , 0 ) =  0 ;
		B( 6 , 1 ) =  0 ;
		B( 6 , 2 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		B( 6 , 3 ) =  M_PI*((sin(4*alpha)+6*sin(2*alpha))/1.2E+1+sin(alpha)/3.0)/1.6E+1 ;
		B( 6 , 4 ) =  0 ;
		B( 6 , 5 ) =  0 ;
		B( 6 , 6 ) =  1.6E+1*(5.0*sin(2*alpha)/3.2E+1-(sin(6*alpha)+4*sin(4*alpha)+4* sin(2*alpha)+(4*alpha-4*M_PI)*cos(2*alpha)+8*alpha-8*M_PI)/3.2E+1 )/1.05E+2 ;
		B( 6 , 7 ) =  0 ;
		B( 6 , 8 ) =  0 ;
		B( 6 , 9 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		B( 7 , 0 ) =  M_PI*sin(alpha)/8.0 ;
		B( 7 , 1 ) =  4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/1.5E+1 ;
		B( 7 , 2 ) =  0 ;
		B( 7 , 3 ) =  0 ;
		B( 7 , 4 ) =  M_PI*((sin(5*alpha)+3*sin(3*alpha)+6*sin(alpha))/1.2E+1+sin(2*alpha )/3.0)/1.6E+1 ;
		B( 7 , 5 ) =  M_PI*sin(alpha)/1.6E+1 ;
		B( 7 , 6 ) =  0 ;
		B( 7 , 7 ) =  4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/3.5E+1 ;
		B( 7 , 8 ) =  1.6E+1*((3*sin(3*alpha)+6*sin(alpha))/3.2E+1-(sin(7*alpha)+2*sin(5 *alpha)+6*sin(3*alpha)+(12*alpha-12*M_PI)*cos(alpha))/3.2E+1)/1.05E+2 ;
		B( 7 , 9 ) =  0 ;
		B( 8 , 0 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/8.0 ;
		B( 8 , 1 ) =  1.6E+1*(5.0*sin(alpha)/3.2E+1-(sin(5*alpha)+6*sin(3*alpha)+2*sin(alpha)+(12*alpha-12*M_PI)*cos(alpha))/3.2E+1)/1.5E+1 ;
		B( 8 , 2 ) =  0 ;
		B( 8 , 3 ) =  0 ;
		B( 8 , 4 ) =  5.0*M_PI*((3*sin(7*alpha)+15*sin(5*alpha)+55*sin(3*alpha)+75*sin (alpha))/2.4E+2+sin(2*alpha)/5.0)/1.6E+1 ;
		B( 8 , 5 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/4.8E+1 ;
		B( 8 , 6 ) =  0 ;
		B( 8 , 7 ) =  1.6E+1*(5.0*sin(alpha)/3.2E+1-(sin(5*alpha)+6*sin(3*alpha)+2*sin(alpha)+(12*alpha-12*M_PI)*cos(alpha))/3.2E+1)/1.05E+2 ;
		B( 8 , 8 ) =  3.2E+1*((29*sin(3*alpha)+45*sin(alpha))/3.84E+2-(2*sin(9*alpha)+9*sin(7*alpha)+27*sin(5*alpha)+54*sin(3*alpha)+(12*alpha-12*M_PI)*cos(3*alpha)+18*sin(alpha)+(108*alpha-108*M_PI)*cos(alpha))/3.84E+2)/3.5E+1 ;
		B( 8 , 9 ) =  0 ;
		B( 9 , 0 ) =  0 ;
		B( 9 , 1 ) =  0 ;
		B( 9 , 2 ) =  2.0*(M_PI-alpha)/5.0 ;
		B( 9 , 3 ) =  M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
		B( 9 , 4 ) =  0 ;
		B( 9 , 5 ) =  0 ;
		B( 9 , 6 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		B( 9 , 7 ) =  0 ;
		B( 9 , 8 ) =  0 ;
		B( 9 , 9 ) =  2.0*(M_PI-alpha)/7.0 ;

		if (size < 11)
			return B ;

		B( 10 , 0 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/1.5E+1 ;
		B( 10 , 1 ) =  M_PI*((sin(4*alpha)+6*sin(2*alpha))/1.2E+1+sin(alpha)/3.0)/1.6E+1 ;
		B( 10 , 2 ) =  0 ;
		B( 10 , 3 ) =  0 ;
		B( 10 , 4 ) =  1.6E+1*(5.0*sin(2*alpha)/3.2E+1-(sin(6*alpha)+4*sin(4*alpha)+4* sin(2*alpha)+(4*alpha-4*M_PI)*cos(2*alpha)+8*alpha-8*M_PI)/3.2E+1 )/1.05E+2 ;
		B( 10 , 5 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;
		B( 10 , 6 ) =  0 ;
		B( 10 , 7 ) =  3.0*M_PI*((sin(4*alpha)+6*sin(2*alpha))/1.2E+1+sin(alpha)/3.0 )/1.28E+2 ;
		B( 10 , 8 ) =  5.0*M_PI*((3*sin(8*alpha)+10*sin(6*alpha)+30*sin(4*alpha)+90*sin (2*alpha))/2.4E+2+(7*sin(3*alpha)+15*sin(alpha))/6.0E+1)/1.28E+2 ;
		B( 10 , 9 ) =  0 ;
		B( 10 , 10 ) =  1.6E+1*(5.0*sin(2*alpha)/3.2E+1-(sin(6*alpha)+4*sin(4*alpha)+4* sin(2*alpha)+(4*alpha-4*M_PI)*cos(2*alpha)+8*alpha-8*M_PI)/3.2E+1 )/3.15E+2 ;
		B( 10 , 11 ) =  0 ;
		B( 10 , 12 ) =  0 ;
		B( 10 , 13 ) =  3.2E+1*((7*sin(4*alpha)+30*sin(2*alpha))/1.92E+2-(sin(10*alpha)+3* sin(8*alpha)+9*sin(6*alpha)+24*sin(4*alpha)+18*sin(2*alpha)+(24 *alpha-24*M_PI)*cos(2*alpha)+36*alpha-36*M_PI)/1.92E+2)/3.15E+2 ;
		B( 10 , 14 ) =  -(sin(2*alpha)+2*alpha-2*M_PI)/6.3E+1 ;
		B( 11 , 0 ) =  0 ;
		B( 11 , 1 ) =  0 ;
		B( 11 , 2 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/4.8E+1 ;
		B( 11 , 3 ) =  1.6E+1*(5.0*sin(alpha)/3.2E+1-(sin(5*alpha)+6*sin(3*alpha)+2*sin(alpha)+(12*alpha-12*M_PI)*cos(alpha))/3.2E+1)/1.05E+2 ;
		B( 11 , 4 ) =  0 ;
		B( 11 , 5 ) =  0 ;
		B( 11 , 6 ) =  5.0*M_PI*((3*sin(7*alpha)+15*sin(5*alpha)+55*sin(3*alpha)+75*sin (alpha))/2.4E+2+sin(2*alpha)/5.0)/1.28E+2 ;
		B( 11 , 7 ) =  0 ;
		B( 11 , 8 ) =  0 ;
		B( 11 , 9 ) =  -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/1.28E+2 ;
		B( 11 , 10 ) =  0 ;
		B( 11 , 11 ) =  3.2E+1*((29*sin(3*alpha)+45*sin(alpha))/3.84E+2-(2*sin(9*alpha)+9*sin(7*alpha)+27*sin(5*alpha)+54*sin(3*alpha)+(12*alpha-12*M_PI)* cos(3*alpha)+18*sin(alpha)+(108*alpha-108*M_PI)*cos(alpha))/3.84E+2)/3.15E+2 ;
		B( 11 , 12 ) =  1.6E+1*(5.0*sin(alpha)/3.2E+1-(sin(5*alpha)+6*sin(3*alpha)+2*sin(alpha)+(12*alpha-12*M_PI)*cos(alpha))/3.2E+1)/3.15E+2 ;
		B( 11 , 13 ) =  0 ;
		B( 11 , 14 ) =  0 ;
		B( 12 , 0 ) =  0 ;
		B( 12 , 1 ) =  0 ;
		B( 12 , 2 ) =  M_PI*sin(alpha)/1.6E+1 ;
		B( 12 , 3 ) =  4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/3.5E+1 ;
		B( 12 , 4 ) =  0 ;
		B( 12 , 5 ) =  0 ;
		B( 12 , 6 ) =  3.0*M_PI*((sin(5*alpha)+3*sin(3*alpha)+6*sin(alpha))/1.2E+1+sin( 2*alpha)/3.0)/1.28E+2 ;
		B( 12 , 7 ) =  0 ;
		B( 12 , 8 ) =  0 ;
		B( 12 , 9 ) =  5.0*M_PI*sin(alpha)/1.28E+2 ;
		B( 12 , 10 ) =  0 ;
		B( 12 , 11 ) =  1.6E+1*((3*sin(3*alpha)+6*sin(alpha))/3.2E+1-(sin(7*alpha)+2*sin(5 *alpha)+6*sin(3*alpha)+(12*alpha-12*M_PI)*cos(alpha))/3.2E+1)/3.15E+2 ;
		B( 12 , 12 ) =  4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/6.3E+1 ;
		B( 12 , 13 ) =  0 ;
		B( 12 , 14 ) =  0 ;
		B( 13 , 0 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/3.0E+1 ;
		B( 13 , 1 ) =  5.0*M_PI*((3*sin(6*alpha)+20*sin(4*alpha)+95*sin(2*alpha))/2.4E+2 + sin(alpha)/5.0)/1.6E+1 ;
		B( 13 , 2 ) =  0 ;
		B( 13 , 3 ) =  0 ;
		B( 13 , 4 ) =  3.2E+1*(1.1E+1*sin(2*alpha)/9.6E+1-(sin(8*alpha)+6*sin(6*alpha)+21 *sin(4*alpha)+24*sin(2*alpha)+(24*alpha-24*M_PI)*cos(2*alpha)+36 *alpha-36*M_PI)/1.92E+2)/3.5E+1 ;
		B( 13 , 5 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/2.1E+2 ;
		B( 13 , 6 ) =  0 ;
		B( 13 , 7 ) =  5.0*M_PI*((3*sin(6*alpha)+20*sin(4*alpha)+95*sin(2*alpha))/2.4E+2+sin(alpha)/5.0)/1.28E+2 ;
		B( 13 , 8 ) =  3.5E+1*M_PI*((5*sin(10*alpha)+28*sin(8*alpha)+91*sin(6*alpha)+280*sin(4*alpha)+630*sin(2*alpha))/2.24E+3+(13*sin(3*alpha)+21*sin(alpha))/1.4E+2)/1.28E+2 ;
		B( 13 , 9 ) =  0 ;
		B( 13 , 10 ) =  3.2E+1*(1.1E+1*sin(2*alpha)/9.6E+1-(sin(8*alpha)+6*sin(6*alpha)+21 *sin(4*alpha)+24*sin(2*alpha)+(24*alpha-24*M_PI)*cos(2*alpha)+36 *alpha-36*M_PI)/1.92E+2)/3.15E+2 ;
		B( 13 , 11 ) =  0 ;
		B( 13 , 12 ) =  0 ;
		B( 13 , 13 ) =  2.56E+2*((103*sin(4*alpha)+352*sin(2*alpha))/3.072E+3-(3*sin(12*alpha)+16*sin(10*alpha)+52*sin(8*alpha)+144*sin(6*alpha)+324*sin(4*alpha)+(24*alpha-24*M_PI)*cos(4*alpha)+288*sin(2*alpha)+(384*alpha-384*M_PI)*cos(2*alpha)+432*alpha-432*M_PI)/3.072E+3)/3.15E+2 ;
		B( 13 , 14 ) =  -(sin(4*alpha)+8*sin(2*alpha)+12*alpha-12*M_PI)/6.3E+2 ;
		B( 14 , 0 ) =  2.0*(M_PI-alpha)/5.0 ;
		B( 14 , 1 ) =  M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
		B( 14 , 2 ) =  0 ;
		B( 14 , 3 ) =  0 ;
		B( 14 , 4 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		B( 14 , 5 ) =  2.0*(M_PI-alpha)/7.0 ;
		B( 14 , 6 ) =  0 ;
		B( 14 , 7 ) =  5.0*M_PI*(sin(2*alpha)+sin(alpha))/1.28E+2 ;
		B( 14 , 8 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/1.28E+2 ;
		B( 14 , 9 ) =  0 ;
		B( 14 , 10 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/6.3E+1 ;
		B( 14 , 11 ) =  0 ;
		B( 14 , 12 ) =  0 ;
		B( 14 , 13 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/3.15E+2 ;
		B( 14 , 14 ) =  2.0*(M_PI-alpha)/9.0 ;

		return B ;
	}

	Eigen::MatrixXd buildIntegralMatrix_C(const REAL& alpha, unsigned int size)
	{
		Eigen::MatrixXd C(size,size) ;

		C( 0 , 0 ) =  2*(M_PI-alpha) ;
		C( 0 , 1 ) =  M_PI*(sin(2*alpha)+sin(alpha))/2.0 ;
		C( 0 , 2 ) =  0 ;
		C( 0 , 3 ) =  0 ;
		C( 0 , 4 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.0 ;
		C( 0 , 5 ) =  2.0*(M_PI-alpha)/3.0 ;
		C( 1 , 0 ) =  M_PI*(sin(2*alpha)+sin(alpha))/2.0 ;
		C( 1 , 1 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.0 ;
		C( 1 , 2 ) =  0 ;
		C( 1 , 3 ) =  0 ;
		C( 1 , 4 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/8.0 ;
		C( 1 , 5 ) =  M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
		C( 2 , 0 ) =  0 ;
		C( 2 , 1 ) =  0 ;
		C( 2 , 2 ) =  2.0*(M_PI-alpha)/3.0 ;
		C( 2 , 3 ) =  M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
		C( 2 , 4 ) =  0 ;
		C( 2 , 5 ) =  0 ;
		C( 3 , 0 ) =  0 ;
		C( 3 , 1 ) =  0 ;
		C( 3 , 2 ) =  M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
		C( 3 , 3 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
		C( 3 , 4 ) =  0 ;
		C( 3 , 5 ) =  0 ;
		C( 4 , 0 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.0 ;
		C( 4 , 1 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/8.0 ;
		C( 4 , 2 ) =  0 ;
		C( 4 , 3 ) =  0 ;
		C( 4 , 4 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.5E+1 ;
		C( 4 , 5 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
		C( 5 , 0 ) =  2.0*(M_PI-alpha)/3.0 ;
		C( 5 , 1 ) =  M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
		C( 5 , 2 ) =  0 ;
		C( 5 , 3 ) =  0 ;
		C( 5 , 4 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
		C( 5 , 5 ) =  2.0*(M_PI-alpha)/5.0 ;

		if (size < 7)
			return C ;

		C( 6 , 0 ) =  0 ;
		C( 6 , 1 ) =  0 ;
		C( 6 , 2 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
		C( 6 , 3 ) =  M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin (alpha))/3.0)/1.6E+1 ;
		C( 6 , 4 ) =  0 ;
		C( 6 , 5 ) =  0 ;
		C( 6 , 6 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.05E+2 ;
		C( 6 , 7 ) =  0 ;
		C( 6 , 8 ) =  0 ;
		C( 6 , 9 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		C( 7 , 0 ) =  M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
		C( 7 , 1 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
		C( 7 , 2 ) =  0 ;
		C( 7 , 3 ) =  0 ;
		C( 7 , 4 ) =  M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin (alpha))/3.0)/1.6E+1 ;
		C( 7 , 5 ) =  M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
		C( 7 , 6 ) =  0 ;
		C( 7 , 7 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		C( 7 , 8 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.05E+2 ;
		C( 7 , 9 ) =  0 ;
		C( 8 , 0 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/8.0 ;
		C( 8 , 1 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.5E+1 ;
		C( 8 , 2 ) =  0 ;
		C( 8 , 3 ) =  0 ;
		C( 8 , 4 ) =  5.0*M_PI*((3*pow(sin(2*alpha),5)-10*pow(sin(2*alpha),3)+15*sin(2*alpha)) /1.5E+1+(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/1.5E+1 )/1.6E+1 ;
		C( 8 , 5 ) =  M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin (alpha))/3.0)/1.6E+1 ;
		C( 8 , 6 ) =  0 ;
		C( 8 , 7 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.05E+2 ;
		C( 8 , 8 ) =  3.2E+1*((9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha )/1.92E+2-(9*sin(8*alpha)-4*pow(sin(4*alpha),3)+48*sin(4*alpha)+120 *alpha-60*M_PI)/1.92E+2)/3.5E+1 ;
		C( 8 , 9 ) =  0 ;
		C( 9 , 0 ) =  0 ;
		C( 9 , 1 ) =  0 ;
		C( 9 , 2 ) =  2.0*(M_PI-alpha)/5.0 ;
		C( 9 , 3 ) =  M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
		C( 9 , 4 ) =  0 ;
		C( 9 , 5 ) =  0 ;
		C( 9 , 6 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		C( 9 , 7 ) =  0 ;
		C( 9 , 8 ) =  0 ;
		C( 9 , 9 ) =  2.0*(M_PI-alpha)/7.0 ;

		if (size < 11)
			return C ;

		C( 10 , 0 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
		C( 10 , 1 ) =  M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin (alpha))/3.0)/1.6E+1 ;
		C( 10 , 2 ) =  0 ;
		C( 10 , 3 ) =  0 ;
		C( 10 , 4 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.05E+2 ;
		C( 10 , 5 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		C( 10 , 6 ) =  0 ;
		C( 10 , 7 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/1.28E+2 ;
		C( 10 , 8 ) =  5.0*M_PI*((3*pow(sin(2*alpha),5)-10*pow(sin(2*alpha),3)+15*sin(2*alpha)) /1.5E+1+(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/1.5E+1)/1.28E+2 ;
		C( 10 , 9 ) =  0 ;
		C( 10 , 10 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/3.15E+2 ;
		C( 10 , 11 ) =  0 ;
		C( 10 , 12 ) =  0 ;
		C( 10 , 13 ) =  3.2E+1*((9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha )/1.92E+2-(9*sin(8*alpha)-4*pow(sin(4*alpha),3)+48*sin(4*alpha)+120 *alpha-60*M_PI)/1.92E+2)/3.15E+2 ;
		C( 10 , 14 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/6.3E+1 ;
		C( 11 , 0 ) =  0 ;
		C( 11 , 1 ) =  0 ;
		C( 11 , 2 ) =  M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin (alpha))/3.0)/1.6E+1 ;
		C( 11 , 3 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.05E+2 ;
		C( 11 , 4 ) =  0 ;
		C( 11 , 5 ) =  0 ;
		C( 11 , 6 ) =  5.0*M_PI*((3*pow(sin(2*alpha),5)-10*pow(sin(2*alpha),3)+15*sin(2*alpha)) /1.5E+1+(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/1.5E+1 )/1.28E+2 ;
		C( 11 , 7 ) =  0 ;
		C( 11 , 8 ) =  0 ;
		C( 11 , 9 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/1.28E+2 ;
		C( 11 , 10 ) =  0 ;
		C( 11 , 11 ) =  3.2E+1*((9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha )/1.92E+2-(9*sin(8*alpha)-4*pow(sin(4*alpha),3)+48*sin(4*alpha)+120 *alpha-60*M_PI)/1.92E+2)/3.15E+2 ;
		C( 11 , 12 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/3.15E+2 ;
		C( 11 , 13 ) =  0 ;
		C( 11 , 14 ) =  0 ;
		C( 12 , 0 ) =  0 ;
		C( 12 , 1 ) =  0 ;
		C( 12 , 2 ) =  M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
		C( 12 , 3 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		C( 12 , 4 ) =  0 ;
		C( 12 , 5 ) =  0 ;
		C( 12 , 6 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/1.28E+2 ;
		C( 12 , 7 ) =  0 ;
		C( 12 , 8 ) =  0 ;
		C( 12 , 9 ) =  5.0*M_PI*(sin(2*alpha)+sin(alpha))/1.28E+2 ;
		C( 12 , 10 ) =  0 ;
		C( 12 , 11 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/3.15E+2 ;
		C( 12 , 12 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/6.3E+1 ;
		C( 12 , 13 ) =  0 ;
		C( 12 , 14 ) =  0 ;
		C( 13 , 0 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.5E+1 ;
		C( 13 , 1 ) =  5.0*M_PI*((3*pow(sin(2*alpha),5)-10*pow(sin(2*alpha),3)+15*sin(2*alpha)) /1.5E+1+(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/1.5E+1 )/1.6E+1 ;
		C( 13 , 2 ) =  0 ;
		C( 13 , 3 ) =  0 ;
		C( 13 , 4 ) =  3.2E+1*((9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha )/1.92E+2-(9*sin(8*alpha)-4*pow(sin(4*alpha),3)+48*sin(4*alpha)+120 *alpha-60*M_PI)/1.92E+2)/3.5E+1 ;
		C( 13 , 5 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/1.05E+2 ;
		C( 13 , 6 ) =  0 ;
		C( 13 , 7 ) =  5.0*M_PI*((3*pow(sin(2*alpha),5)-10*pow(sin(2*alpha),3)+15*sin(2*alpha)) /1.5E+1+(3*pow(sin(alpha),5)-10*pow(sin(alpha),3)+15*sin(alpha))/1.5E+1 )/1.28E+2 ;
		C( 13 , 8 ) =  3.5E+1*M_PI*(-(5*pow(sin(2*alpha),7)-21*pow(sin(2*alpha),5)+35*pow(sin(2*alpha),3)-35*sin(2*alpha))/3.5E+1-(5*pow(sin(alpha),7)-21*pow(sin(alpha),5)+35*pow(sin(alpha),3)-35*sin(alpha))/3.5E+1)/1.28E+2 ;
		C( 13 , 9 ) =  0 ;
		C( 13 , 10 ) =  3.2E+1*((9*sin(4*alpha)-4*pow(sin(2*alpha),3)+48*sin(2*alpha)+60*alpha )/1.92E+2-(9*sin(8*alpha)-4*pow(sin(4*alpha),3)+48*sin(4*alpha)+120 *alpha-60*M_PI)/1.92E+2)/3.15E+2 ;
		C( 13 , 11 ) =  0 ;
		C( 13 , 12 ) =  0 ;
		C( 13 , 13 ) =  2.56E+2*((3*sin(8*alpha)+168*sin(4*alpha)-128*pow(sin(2*alpha),3)+768* sin(2*alpha)+840*alpha)/3.072E+3-(3*sin(16*alpha)+168*sin(8*alpha)-128*pow(sin(4*alpha),3)+768*sin(4*alpha)+1680*alpha-840*M_PI)/3.072E+3)/3.15E+2 ;
		C( 13 , 14 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/3.15E+2 ;
		C( 14 , 0 ) =  2.0*(M_PI-alpha)/5.0 ;
		C( 14 , 1 ) =  M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
		C( 14 , 2 ) =  0 ;
		C( 14 , 3 ) =  0 ;
		C( 14 , 4 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
		C( 14 , 5 ) =  2.0*(M_PI-alpha)/7.0 ;
		C( 14 , 6 ) =  0 ;
		C( 14 , 7 ) =  5.0*M_PI*(sin(2*alpha)+sin(alpha))/1.28E+2 ;
		C( 14 , 8 ) =  3.0*M_PI*(-(pow(sin(2*alpha),3)-3*sin(2*alpha))/3.0-(pow(sin(alpha),3)-3*sin(alpha))/3.0)/1.28E+2 ;
		C( 14 , 9 ) =  0 ;
		C( 14 , 10 ) =  4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/6.3E+1 ;
		C( 14 , 11 ) =  0 ;
		C( 14 , 12 ) =  0 ;
		C( 14 , 13 ) =  1.6E+1*((sin(4*alpha)+8*sin(2*alpha)+12*alpha)/3.2E+1-(sin(8*alpha )+8*sin(4*alpha)+24*alpha-12*M_PI)/3.2E+1)/3.15E+2 ;
		C( 14 , 14 ) =  2.0*(M_PI-alpha)/9.0 ;

		return C ;
	}

	void fillTensor(Geom::Tensor3d& T)
	{
		std::vector<unsigned int> p ;
		p.resize(T.order(), 0) ;
		do
		{
			//		for (unsigned int i = 0 ; i < p.size() ; ++i)
			//			std::cout << p[i] << " " ;
			//		std::cout << std::endl ;
			if (T(p) == CONST_VAL)
			{
				std::vector<unsigned int> sorted_p = p ;
				std::sort(sorted_p.begin(), sorted_p.begin() + T.order()) ;
				//			std::cout << "sort: " ;
				//			for (unsigned int i = 0 ; i < p.size() ; ++i)
				//				std::cout << sorted_p[i] << " " ;
				//			std::cout << std::endl ;
				T(p) = T(sorted_p) ;
			}
		} while (Geom::Tensor3d::incremIndex(p)) ;
	}


	Geom::Tensor3d* tensorsFromCoefs(const std::vector<VEC3>& coefs)
	{
		const unsigned int& N = coefs.size() ;
		const unsigned int& degree = (sqrt(1+8*N) - 3) / REAL(2) ;
		Geom::Tensor3d *A = new Geom::Tensor3d[3] ;

		for (unsigned int col = 0 ; col < 3 ; ++col)
		{
			A[col] = Geom::Tensor3d(degree) ;
			A[col].setConst(CONST_VAL) ;
		}

		std::vector<unsigned int> index ;
		if (N > 0)
		{
			index.resize(degree,2) ;
			for (unsigned int col = 0 ; col < 3 ; ++col)
				A[col](index) = coefs[0][col] ; // constant term (2,2,2,2)
			if (N > 2)
			{
				//				index.resize(degree,2) ;
				index[0] = 1 ;
				for (unsigned int col = 0 ; col < 3 ; ++col)
					A[col](index) = coefs[1][col] / degree ; // v (1,2,2,2)
				index[0] = 0 ;
				for (unsigned int col = 0 ; col < 3 ; ++col)
					A[col](index) = coefs[2][col] / degree ; // u (0,2,2,2)
				if (N > 5)
				{
					//					index.resize(degree,2) ;
					index[0] = 0 ; index[1] = 1 ;
					for (unsigned int col = 0 ; col < 3 ; ++col)
						A[col](index) = coefs[3][col] / (degree * (degree - 1)); // uv (0,1,2,2)

					index[0] = 1 ;
					for (unsigned int col = 0 ; col < 3 ; ++col)
						A[col](index) = coefs[4][col] / ((degree * (degree - 1)) / 2.) ; // v² (1,1,2,2)

					index[0] = 0 ; index[1] = 0 ;
					for (unsigned int col = 0 ; col < 3 ; ++col)
						A[col](index) = coefs[5][col] / ((degree * (degree - 1)) / 2.) ; // u² (0,0,2,2)
					if (N > 9)
					{
						//						index.resize(degree,2) ;
						index[0] = 0 ; index[1] = 1 ; index[2] = 1 ;
						for (unsigned int col = 0 ; col < 3 ; ++col)
							A[col](index) = coefs[6][col] / ((degree * (degree - 1) * (degree - 2)) / 2.) ; // uv**2 (0,1,1,2)
						index[0] = 0 ; index[1] = 0 ; index[2] = 1 ;
						for (unsigned int col = 0 ; col < 3 ; ++col)
							A[col](index) = coefs[7][col] / ((degree * (degree - 1) * (degree - 2)) / 2.) ; // u**2v (0,0,1,2)
						index[0] = 1 ; index[1] = 1 ; index[2] = 1 ;
						for (unsigned int col = 0 ; col < 3 ; ++col)
							A[col](index) = coefs[8][col] / ((degree * (degree - 1) * (degree - 2)) / 6.) ; // v**3 (1,1,1,2)
						index[0] = 0 ; index[1] = 0 ; index[2] = 0 ;
						for (unsigned int col = 0 ; col < 3 ; ++col)
							A[col](index) = coefs[9][col] / ((degree * (degree - 1) * (degree - 2)) / 6.) ; // u**3 (0,0,0,2)
						if (N > 14)
						{
							assert(degree == 4) ;
							//							index.resize(degree,2)
							index[0] = 0 ; index[1] = 0 ; index[2] = 1 ; index[3] = 1 ;
							for (unsigned int col = 0 ; col < 3 ; ++col)
								A[col](index) = coefs[10][col] / 6 ; // u**2v**2 (0,0,1,1)
							index[0] = 0 ; index[1] = 0 ; index[2] = 0 ; index[3] = 1 ;
							for (unsigned int col = 0 ; col < 3 ; ++col)
								A[col](index) = coefs[11][col] / 4 ; // uv**3 (0,0,0,1)
							index[0] = 0 ; index[1] = 1 ; index[2] = 1 ; index[3] = 1 ;
							for (unsigned int col = 0 ; col < 3 ; ++col)
								A[col](index) = coefs[12][col] / 4 ; // u**3v (0,1,1,1)
							index[0] = 1 ; index[1] = 1 ; index[2] = 1 ; index[3] = 1 ;
							for (unsigned int col = 0 ; col < 3 ; ++col)
								A[col](index) = coefs[13][col] ; // v**4 (1,1,1,1)
							index[0] = 0 ; index[1] = 0 ; index[2] = 0 ; index[3] = 0 ;
							for (unsigned int col = 0 ; col < 3 ; ++col)
								A[col](index) = coefs[14][col] ; // u**4 (0,0,0,0)
						}
					}
				}
			}
		}

		for (unsigned int col = 0 ; col < 3 ; ++col)
			fillTensor(A[col]) ;

		return A ;
	}

	std::vector<VEC3> coefsFromTensors(Geom::Tensor3d* A)
					{
		const unsigned int& degree = A[0].order() ;
		std::vector<VEC3> coefs ;
		coefs.resize(((degree + 1) * (degree + 2)) / REAL(2)) ;

		std::vector<unsigned int> index ;
		index.resize(degree,2) ;
		for (unsigned int col = 0 ; col < 3 ; ++col)
			coefs[0][col] = A[col](index) ; // constant term (2,2,2,2)
		if (degree > 0)
		{
			index[0] = 1 ;
			for (unsigned int col = 0 ; col < 3 ; ++col)
				coefs[1][col] = A[col](index) * degree ; // v (1,2,2,2)
			index[0] = 0 ;
			for (unsigned int col = 0 ; col < 3 ; ++col)
				coefs[2][col] = A[col](index) * degree ; // u (0,2,2,2)
			if (degree > 1)
			{
				//					index.resize(degree,2) ;
				index[0] = 0 ; index[1] = 1 ;
				for (unsigned int col = 0 ; col < 3 ; ++col)
					coefs[3][col]  = A[col](index) * (degree * (degree - 1)); // uv (0,1,2,2)

				index[0] = 1 ;
				for (unsigned int col = 0 ; col < 3 ; ++col)
					coefs[4][col] = A[col](index) * ((degree * (degree - 1)) / 2.) ; // v² (1,1,2,2)

				index[0] = 0 ; index[1] = 0 ;
				for (unsigned int col = 0 ; col < 3 ; ++col)
					coefs[5][col] = A[col](index) * ((degree * (degree - 1)) / 2.) ; // u² (0,0,2,2)
				if (degree > 2)
				{
					//						index.resize(degree,2) ;
					index[0] = 0 ; index[1] = 1 ; index[2] = 1 ;
					for (unsigned int col = 0 ; col < 3 ; ++col)
						coefs[6][col] = A[col](index) * ((degree * (degree - 1) * (degree - 2)) / 2.) ; // uv**2 (0,1,1,2)
					index[0] = 0 ; index[1] = 0 ; index[2] = 1 ;
					for (unsigned int col = 0 ; col < 3 ; ++col)
						coefs[7][col] = A[col](index) * ((degree * (degree - 1) * (degree - 2)) / 2.) ; // u**2v (0,0,1,2)
					index[0] = 1