qem.hpp 46.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*******************************************************************************
 * 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                                        *
 *                                                                              *
 *******************************************************************************/

namespace CGoGN {

namespace Utils {

template <typename REAL>
Quadric<REAL>::Quadric()
{
	A.zero() ;
}
34 35

template <typename REAL>
Sylvain Thery's avatar
Sylvain Thery committed
36
Quadric<REAL>::Quadric(int)
37 38 39
{
	A.zero() ;
}
40 41

template <typename REAL>
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
42
Quadric<REAL>::Quadric(const VEC3& p1, const VEC3& p2, const VEC3& p3)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
{
	// compute the equation of the plane of the 3 points
	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) ;
}

template <typename REAL>
void
Quadric<REAL>::zero()
{
	A.zero() ;
}

template <typename REAL>
void
Quadric<REAL>::operator= (const Quadric<REAL>& q)
{
	A = q.A ;
}

template <typename REAL>
Quadric<REAL>&
Quadric<REAL>::operator+= (const Quadric<REAL>& q)
{
	A += q.A ;
	return *this ;
}

template <typename REAL>
Quadric<REAL>&
Quadric<REAL>::operator -= (const Quadric<REAL>& q)
{
	A -= q.A ;
	return *this ;
}

template <typename REAL>
Quadric<REAL>&
84
Quadric<REAL>::operator *= (const REAL& v)
85 86 87 88 89 90 91
{
	A *= v ;
	return *this ;
}

template <typename REAL>
Quadric<REAL>&
92
Quadric<REAL>::operator /= (const REAL& v)
93 94 95 96 97 98 99 100 101 102 103 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
{
	A /= v ;
	return *this ;
}

template <typename REAL>
REAL
Quadric<REAL>::operator() (const VEC4& v) const
{
	return evaluate(v) ;
}

template <typename REAL>
REAL
Quadric<REAL>::operator() (const VEC3& v) const
{
	VEC4 hv(v[0], v[1], v[2], 1.0f) ;
	return evaluate(hv) ;
}

template <typename REAL>
bool
Quadric<REAL>::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 ;
}

template <typename REAL>
REAL
Quadric<REAL>::evaluate(const VEC4& v) const
{
	// Double computation is crucial for stability
133 134 135
	Geom::Vector<4, double> vd(v);
	Geom::Vector<4, double> Av = A * vd ;
	return REAL(vd * Av) ;
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
}

template <typename REAL>
bool
Quadric<REAL>::optimize(VEC4& v) const
{
	if (std::isnan(A(0,0)))
		return false ;

	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 ;
153 154 155
//	VEC4 right(0,0,0,1) ;
	Geom::Vector<4, double> right(0,0,0,1) ;
	v = VEC4(Ainv * right) ;
156 157 158 159 160 161 162 163 164 165 166 167 168

	return true;
}

template <typename REAL, unsigned int N>
QuadricNd<REAL,N>::QuadricNd()
{
	A.zero() ;
	b.zero() ;
	c = 0 ;
}

template <typename REAL, unsigned int N>
Sylvain Thery's avatar
Sylvain Thery committed
169
QuadricNd<REAL,N>::QuadricNd(int)
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
{
	A.zero() ;
	b.zero() ;
	c = 0 ;
}

template <typename REAL, unsigned int N>
QuadricNd<REAL,N>::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() ;
	Geom::Vector<N,double> e2 = (p3 - p1) - (e1*(p3-p1))*e1 ; 	e2.normalize() ;

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

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

	c = p1*p1 - pow((p1*e1),2) - pow((p1*e2),2) ;
}

template <typename REAL, unsigned int N>
void
QuadricNd<REAL,N>::zero()
{
	A.zero() ;
	b.zero() ;
	c = 0 ;
}

template <typename REAL, unsigned int N>
void
QuadricNd<REAL,N>::operator= (const QuadricNd<REAL,N>& q)
{
	A = q.A ;
	b = q.b ;
	c = q.c ;
}

template <typename REAL, unsigned int N>
QuadricNd<REAL,N>&
QuadricNd<REAL,N>::operator+= (const QuadricNd<REAL,N>& q)
{
	A += q.A ;
	b += q.b ;
	c += q.c ;
	return *this ;
}

template <typename REAL, unsigned int N>
QuadricNd<REAL,N>&
QuadricNd<REAL,N>::operator -= (const QuadricNd<REAL,N>& q)
{
	A -= q.A ;
	b -= q.b ;
	c -= q.c ;
	return *this ;
}

template <typename REAL, unsigned int N>
QuadricNd<REAL,N>&
QuadricNd<REAL,N>::operator *= (REAL v)
{
	A *= v ;
	b *= v ;
	c *= v ;
	return *this ;
}

template <typename REAL, unsigned int N>
QuadricNd<REAL,N>&
QuadricNd<REAL,N>::operator /= (REAL v)
{
	A /= v ;
	b /= v ;
	c /= v ;
	return *this ;
}

template <typename REAL, unsigned int N>
REAL
QuadricNd<REAL,N>::operator() (const VECNp& v) const
{
	VECN hv ;
	for (unsigned int i = 0 ; i < N ; ++i)
		hv[i] = v[i] ;

	return evaluate(v) ;
}

template <typename REAL, unsigned int N>
REAL
QuadricNd<REAL,N>::operator() (const VECN& v) const
{
	return evaluate(v) ;
}

template <typename REAL, unsigned int N>
bool
QuadricNd<REAL,N>::findOptimizedVec(VECN& v)
{
	return optimize(v) ;
}

template <typename REAL, unsigned int N>
REAL
QuadricNd<REAL,N>::evaluate(const VECN& v) const
{
	Geom::Vector<N, double> v_d = v ;
	return v_d*A*v_d + 2.*(b*v_d) + c ;
}

template <typename REAL, unsigned int N>
bool
QuadricNd<REAL,N>::optimize(VECN& v) const
{
	if (std::isnan(A(0,0)))
		return false ;

	Geom::Matrix<N,N,double> Ainv ;
	double det = A.invert(Ainv) ;

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

	v.zero() ;
	v -= Ainv * b ;

	return true ;
}

template <typename REAL>
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
305 306
QuadricHF<REAL>::QuadricHF():
m_noAlphaRot(false)
307 308 309
{}

template <typename REAL>
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
310 311
QuadricHF<REAL>::QuadricHF(int i):
m_noAlphaRot(false)
312 313 314 315 316 317 318 319 320 321 322 323
{
	m_A.resize(i,i) ;
	for (unsigned int c = 0 ; c < 3 ; ++c)
	{
		m_b[c].resize(i) ;
		m_c[c] = 0 ;
	}
}

template <typename REAL>
QuadricHF<REAL>::QuadricHF(const std::vector<VEC3>& v, const REAL& gamma, const REAL& alpha)
{
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
324 325 326
	Geom::Tensor3d *T = tensorsFromCoefs(v) ;
	*this = QuadricHF(T, gamma, alpha) ;
	delete[] T ;
327 328 329
}

template <typename REAL>
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
330 331
QuadricHF<REAL>::QuadricHF(const Geom::Tensor3d* T, const REAL& gamma, const REAL& alpha):
m_noAlphaRot(fabs(alpha) < 1e-13)
332 333 334 335
{
	const unsigned int nbcoefs = ((T[0].order() + 1) * (T[0].order() + 2)) / 2. ;

	// 2D rotation
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
336
	const Geom::Matrix33d R = buildRotateMatrix(gamma) ;
337 338 339
	Geom::Tensor3d* Trot = new Geom::Tensor3d[3] ;
	for (unsigned int c = 0 ; c < 3 ; ++c)
		Trot[c] = rotate(T[c],R) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
340
	m_coefs = coefsFromTensors(Trot) ;
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
341
	delete[] Trot ;
342 343 344 345 346 347 348 349 350 351 352 353

	// 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 c = 0 ; c < 3 ; ++c)
	{
		Eigen::VectorXd v ;	v.resize(nbcoefs) ;
		for (unsigned int i = 0 ; i < nbcoefs ; ++i) // copy into vector
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
354
			v[i] = m_coefs[i][c] ;
355 356 357 358 359 360 361 362

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

template <typename REAL>
QuadricHF<REAL>::~QuadricHF()
363
{}
364 365 366 367 368 369 370 371 372 373 374

template <typename REAL>
void
QuadricHF<REAL>::zero()
{
	m_A.setZero() ;
	for (unsigned int c = 0 ; c < 3 ; ++c)
	{
		m_b[c].setZero() ;
		m_c[c] = 0 ;
	}
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
375 376
	m_coefs.clear() ;
	m_noAlphaRot = false ;
377 378 379 380 381 382 383 384 385 386 387 388
}

template <typename REAL>
QuadricHF<REAL>&
QuadricHF<REAL>::operator= (const QuadricHF<REAL>& q)
{
	m_A = q.m_A ;
	for (unsigned int c = 0 ; c < 3 ; ++c)
	{
		m_b[c] = q.m_b[c] ;
		m_c[c] = q.m_c[c] ;
	}
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
389 390
	m_coefs = q.m_coefs ;
	m_noAlphaRot = q.m_noAlphaRot ;
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408

	return *this ;
}

template <typename REAL>
QuadricHF<REAL>&
QuadricHF<REAL>::operator+= (const QuadricHF<REAL>& q)
{
	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()))
		return *this ;

	m_A += q.m_A ;
	for (unsigned int c = 0 ; c < 3 ; ++c)
	{
		m_b[c] += q.m_b[c] ;
		m_c[c] += q.m_c[c] ;
	}
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
409 410 411 412 413
	m_coefs.resize(m_coefs.size()) ;
	for (unsigned int i = 0 ; i < m_coefs.size() ; ++i)
		m_coefs[i] += q.m_coefs[i] ;

	m_noAlphaRot &= q.m_noAlphaRot ;
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432

	return *this ;
}

template <typename REAL>
QuadricHF<REAL>&
QuadricHF<REAL>::operator -= (const QuadricHF<REAL>& q)
{
	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()))
		return *this ;

	m_A -= q.m_A ;
	for (unsigned int c = 0 ; c < 3 ; ++c)
	{
		m_b[c] -= q.m_b[c] ;
		m_c[c] -= q.m_c[c] ;
	}

Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
433 434 435 436 437 438
	m_coefs.resize(m_coefs.size()) ;
	for (unsigned int i = 0 ; i < m_coefs.size() ; ++i)
		m_coefs[i] -= q.m_coefs[i] ;

	m_noAlphaRot &= q.m_noAlphaRot ;

439 440 441 442 443 444 445
	return *this ;
}

template <typename REAL>
QuadricHF<REAL>&
QuadricHF<REAL>::operator *= (const REAL& v)
{
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
446
	std::cout << "Warning: QuadricHF<REAL>::operator *= should not be used !" << std::endl ;
447 448 449 450 451 452 453 454 455 456 457 458 459 460
	m_A *= v ;
	for (unsigned int c = 0 ; c < 3 ; ++c)
	{
		m_b[c] *= v ;
		m_c[c] *= v ;
	}

	return *this ;
}

template <typename REAL>
QuadricHF<REAL>&
QuadricHF<REAL>::operator /= (const REAL& v)
{
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
461
	std::cout << "Warning: QuadricHF<REAL>::operator /= should not be used !" << std::endl ;
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
	const REAL& inv = 1. / v ;

	(*this) *= inv ;

	return *this ;
}

template <typename REAL>
REAL
QuadricHF<REAL>::operator() (const std::vector<VEC3>& coefs) const
{
	return evaluate(coefs) ;
}

template <typename REAL>
bool
QuadricHF<REAL>::findOptimizedCoefs(std::vector<VEC3>& coefs)
{
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
	coefs.resize(m_b[0].size()) ;

	if (fabs(m_A.determinant()) < 1e-10 )
	{
		coefs = m_coefs ;
		return m_noAlphaRot ; // if true inversion failed (normal!) and m_coefs forms a valid solution
	}
	Eigen::MatrixXd Ainv = m_A.inverse() ;

	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] ;
	}

	return true ;
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
}

template <typename REAL>
REAL
QuadricHF<REAL>::evaluate(const std::vector<VEC3>& coefs) const
{
	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. ;
}

520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
template <typename REAL>
typename QuadricHF<REAL>::VEC3
QuadricHF<REAL>::evalR3(const std::vector<VEC3>& coefs) const
{
	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 ;
}

540 541
template <typename REAL>
Geom::Matrix33d
Kenneth Vanhoey's avatar
Kenneth Vanhoey committed
542
QuadricHF<REAL>::buildRotateMatrix(const REAL& gamma)
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
{
	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 ;
}

template <typename REAL>
Geom::Tensor3d
QuadricHF<REAL>::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 ;
}

579 580 581 582 583 584 585 586 587 588
template <typename REAL>
void
QuadricHF<REAL>::fillSymmetricMatrix(Eigen::MatrixXd& M)
{
	assert(M.cols() == M.rows() || !"QuadricHF<REAL>::fillSymmetricMatrix: matrix to fill should be a square matrix") ;
	for (unsigned int c = 0 ; c < M.cols() ; ++c)
		for (unsigned int l = 0 ; l < c ; ++l)
			M( l, c) = M (c, l) ;
}

589 590 591
template <typename REAL>
Eigen::MatrixXd
QuadricHF<REAL>::buildIntegralMatrix_A(const REAL& alpha, unsigned int size)
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
{
	Eigen::MatrixXd res = buildLowerLeftIntegralMatrix_A(alpha,size) ;
	fillSymmetricMatrix(res) ;

	return res ;
}

template <typename REAL>
Eigen::MatrixXd
QuadricHF<REAL>::buildIntegralMatrix_C(const REAL& alpha, unsigned int size)
{
	Eigen::MatrixXd res = buildLowerLeftIntegralMatrix_C(alpha,size) ;
	fillSymmetricMatrix(res) ;

	return res ;
}


template <typename REAL>
Eigen::MatrixXd
QuadricHF<REAL>::buildLowerLeftIntegralMatrix_A(const REAL& alpha, unsigned int size)
613 614 615
{
	Eigen::MatrixXd A(size,size) ;

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
	A( 0 , 0 ) = 2*(M_PI-alpha) ;

	A( 1 , 0 ) = M_PI*sin(alpha)/2.0 ;
	A( 1 , 1 ) = -(sin(2*alpha)+2*alpha-2*M_PI)/3.0 ;

	A( 2 , 0 ) = 0 ;
	A( 2 , 1 ) = 0 ;
	A( 2 , 2 ) = 2.0*(M_PI-alpha)/3.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( 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( 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 ;
642 643 644 645

	if (size < 7)
		return A ;

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
	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( 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( 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( 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 ;
683 684 685 686

	if (size < 11)
		return A ;

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
	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( 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( 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( 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( 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 ;
756 757 758 759 760 761 762 763 764 765

	return A ;
}

template <typename REAL>
Eigen::MatrixXd
QuadricHF<REAL>::buildIntegralMatrix_B(const REAL& alpha, unsigned int size)
{
	Eigen::MatrixXd B(size,size) ;

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
	 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( 0 , 6 ) = 0 ;
	 B( 0 , 7 ) = M_PI*(sin(2*alpha)+sin(alpha))/8.0 ;
	 B( 0 , 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)/8.0 ;
	 B( 0 , 9 ) = 0 ;

	 B( 1 , 6 ) = 0 ;
	 B( 1 , 7 ) = 4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/1.5E+1 ;
	 B( 1 , 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.5E+1 ;
	 B( 1 , 9 ) = 0 ;

	 B( 2 , 6 ) = 4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
	 B( 2 , 7 ) = 0 ;
	 B( 2 , 8 ) = 0 ;
	 B( 2 , 9 ) = 2.0*(M_PI-alpha)/5.0 ;

	 B( 3 , 6 ) = M_PI*((sin(5*alpha)+3*sin(3*alpha)+6*sin(alpha))/1.2E+1+sin(2*alpha )/3.0)/1.6E+1 ;
	 B( 3 , 7 ) = 0 ;
	 B( 3 , 8 ) = 0 ;
	 B( 3 , 9 ) = M_PI*sin(alpha)/1.6E+1 ;

	 B( 4 , 6 ) = 0 ;
	 B( 4 , 7 ) = M_PI*((sin(4*alpha)+6*sin(2*alpha))/1.2E+1+sin(alpha)/3.0)/1.6E+1 ;
	 B( 4 , 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.6E+1 ;
	 B( 4 , 9 ) = 0 ;

	 B( 5 , 6 ) = 0 ;
	 B( 5 , 7 ) = M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
	 B( 5 , 8 ) = 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 ;
	 B( 5 , 9 ) = 0 ;

	 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 ;

885
	 if (size < 11)
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
		 return B ;

	 B( 0 , 10 ) = 4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/1.5E+1 ;
	 B( 0 , 11 ) = 0 ;
	 B( 0 , 12 ) = 0 ;
	 B( 0 , 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)/1.5E+1 ;
	 B( 0 , 14 ) = 2.0*(M_PI-alpha)/5.0 ;

	 B( 1 , 10 ) = M_PI*((sin(5*alpha)+3*sin(3*alpha)+6*sin(alpha))/1.2E+1+sin(2*alpha )/3.0)/1.6E+1 ;
	 B( 1 , 11 ) = 0 ;
	 B( 1 , 12 ) = 0 ;
	 B( 1 , 13 ) = 5.0*M_PI*((3*sin(9*alpha)+5*sin(7*alpha)+20*sin(5*alpha)+60*sin(3*alpha)+90*sin(alpha))/2.4E+2+(sin(4*alpha)+10*sin(2*alpha))/3.0E+1)/1.6E+1 ;
	 B( 1 , 14 ) = M_PI*sin(alpha)/1.6E+1 ;

	 B( 2 , 10 ) = 0 ;
	 B( 2 , 11 ) = 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 ;
	 B( 2 , 12 ) = M_PI*(sin(2*alpha)+sin(alpha))/1.6E+1 ;
	 B( 2 , 13 ) = 0 ;
	 B( 2 , 14 ) = 0 ;

	 B( 3 , 10 ) = 0 ;
	 B( 3 , 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)/1.05E+2 ;
	 B( 3 , 12 ) = 4.0*(sin(alpha)/4.0-(sin(3*alpha)+(2*alpha-2*M_PI)*cos(alpha) )/4.0)/3.5E+1 ;
	 B( 3 , 13 ) = 0 ;
	 B( 3 , 14 ) = 0 ;

	 B( 4 , 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 )/1.05E+2 ;
	 B( 4 , 11 ) = 0 ;
	 B( 4 , 12 ) = 0 ;
	 B( 4 , 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.5E+1 ;
	 B( 4 , 14 ) = -(sin(2*alpha)+2*alpha-2*M_PI)/3.5E+1 ;

	 B( 5 , 10 ) = 4.0*((sin(2*alpha)+2*alpha)/4.0-(sin(4*alpha)+4*alpha-2*M_PI) /4.0)/3.5E+1 ;
	 B( 5 , 11 ) = 0 ;
	 B( 5 , 12 ) = 0 ;
	 B( 5 , 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)/1.05E+2 ;
	 B( 5 , 14 ) = 2.0*(M_PI-alpha)/7.0 ;

	 B( 6 , 10 ) = 0 ;
	 B( 6 , 11 ) = 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( 6 , 12 ) = 3.0*M_PI*((sin(4*alpha)+6*sin(2*alpha))/1.2E+1+sin(alpha)/3.0 )/1.28E+2 ;
	 B( 6 , 13 ) = 0 ;
	 B( 6 , 14 ) = 0 ;

	 B( 7 , 10 ) = 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( 7 , 11 ) = 0 ;
	 B( 7 , 12 ) = 0 ;
	 B( 7 , 13 ) = 5.0*M_PI*((3*sin(9*alpha)+5*sin(7*alpha)+20*sin(5*alpha)+60*sin(3*alpha)+90*sin(alpha))/2.4E+2+(sin(4*alpha)+10*sin(2*alpha))/3.0E+1)/1.28E+2 ;
	 B( 7 , 14 ) = 5.0*M_PI*sin(alpha)/1.28E+2 ;

	 B( 8 , 10 ) = 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( 8 , 11 ) = 0 ;
	 B( 8 , 12 ) = 0 ;
	 B( 8 , 13 ) = 3.5E+1*M_PI*((5*sin(11*alpha)+21*sin(9*alpha)+63*sin(7*alpha)+175*sin(5*alpha)+490*sin(3*alpha)+490*sin(alpha))/2.24E+3+(3*sin(4*alpha)+14*sin(2*alpha))/7.0E+1)/1.28E+2 ;
	 B( 8 , 14 ) = -M_PI*(pow(sin(alpha),3)-3*sin(alpha))/1.28E+2 ;

	 B( 9 , 10 ) = 0 ;
	 B( 9 , 11 ) = 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( 9 , 12 ) = 5.0*M_PI*(sin(2*alpha)+sin(alpha))/1.28E+2 ;
	 B( 9 , 13 ) = 0 ;
	 B( 9 , 14 ) = 0 ;

	 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 ;
1027 1028 1029 1030 1031 1032

	return B ;
}

template <typename REAL>
Eigen::MatrixXd
1033
QuadricHF<REAL>::buildLowerLeftIntegralMatrix_C(const REAL& alpha, unsigned int size)
1034 1035 1036
{
	Eigen::MatrixXd C(size,size) ;

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
	C( 0 , 0 ) = 2*(M_PI-alpha) ;

	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( 2 , 0 ) = 0 ;
	C( 2 , 1 ) = 0 ;
	C( 2 , 2 ) = 2.0*(M_PI-alpha)/3.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( 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( 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 ;
1063 1064 1065 1066

	if (size < 7)
		return C ;

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
	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( 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( 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( 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 ;
1104 1105 1106 1107

	if (size < 11)
		return C ;

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
	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( 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( 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( 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( 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 ;
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191

	return C ;
}

template <typename REAL>
Geom::Tensor3d*
QuadricHF<REAL>::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) ;
1192
		//A[col].setConst(CONST_VAL) ;
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
	}

	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)
1265
		A[col].completeSymmetricTensor() ;
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349

	return A ;
}

template <typename REAL>
std::vector<typename QuadricHF<REAL>::VEC3>
QuadricHF<REAL>::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 ; index[1] = 1 ; index[2] = 1 ;
				for (unsigned int col = 0 ; col < 3 ; ++col)
					coefs[8][col] = A[col](index) * ((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)
					coefs[9][col] = A[col](index) * ((degree * (degree - 1) * (degree - 2)) / 6.) ; // u**3 (0,0,0,2)
				if (degree > 3)
				{
					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)
						coefs[10][col] = A[col](index) * 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)
						coefs[11][col] = A[col](index) * 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)
						coefs[12][col] = A[col](index) * 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)
						coefs[13][col] = A[col](index) ; // 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)
						coefs[14][col] = A[col](index) ; // u**4 (0,0,0,0)
				}
			}
		}
	}

	return coefs ;
}

} // Utils

} // CGOGN