21 std::cout <<
"Invalid Triangle. Expected 3 vertices.\n";
27 Matrix3 J( verts[1 * 3 + 0] - verts[0 * 3 + 0], verts[2 * 3 + 0] - verts[0 * 3 + 0], 0.0,
28 verts[1 * 3 + 1] - verts[0 * 3 + 1], verts[2 * 3 + 1] - verts[0 * 3 + 1], 0.0,
29 verts[1 * 3 + 2] - verts[0 * 3 + 2], verts[2 * 3 + 2] - verts[0 * 3 + 2], 1.0 );
33 if( !work ) work =
new double[20];
38 work[19] = ( work[18] < 1e-12 ? std::numeric_limits< double >::max() : 1.0 / work[18] );
50 assert( params && field && num_tuples > 0 );
52 double p1 = 0.5 * ( 1.0 + params[0] ), p2 = 0.5 * ( 1.0 + params[1] ), p0 = 1.0 - p1 - p2;
54 for(
int j = 0; j < num_tuples; j++ )
55 result[j] = p0 * field[0 * num_tuples + j] + p1 * field[1 * num_tuples + j] + p2 * field[2 * num_tuples + j];
68 assert( field && num_tuples > 0 );
69 std::fill( result, result + num_tuples, 0.0 );
70 for(
int i = 0; i < nverts; ++i )
72 for(
int j = 0; j < num_tuples; j++ )
73 result[j] += field[i * num_tuples + j];
75 double tmp = work[18] / 6.0;
76 for(
int i = 0; i < num_tuples; i++ )
86 std::copy( work, work + 9, result );
97 const double iter_tol,
98 const double inside_tol,
103 assert( posn && verts );
104 return evaluate_reverse( eval, jacob, ins, posn, verts, nverts, ndim, iter_tol, inside_tol, work, params,
110 return ( params[0] >= -1.0 - tol && params[1] >= -1.0 - tol && params[0] + params[1] <= 1.0 + tol );
120 const double iter_tol,
121 const double inside_tol,
129 const double error_tol_sqr = iter_tol * iter_tol;
135 double resl = std::numeric_limits< double >::max();
138 for(
unsigned int i = 0; i < 3; i++ )
140 rval = ( *eval )( tmp_params[i].
array(), verts, ndim, 3, work, tmp_pos.
array() );
143 if( tmp_resl < resl )
145 *cvparams = tmp_params[i];
154 rval = ( *jacob )( cvparams->
array(), verts, nverts, ndim, work, J[0] );
157 assert( det > std::numeric_limits< double >::epsilon() );
163 while( res % res > error_tol_sqr )
165 if( ++iters > 25 )
return MB_FAILURE;
168 *cvparams -= Ji * res;
171 rval = ( *eval )( params, verts, ndim, 3, work, new_pos.
array() );
173 res = new_pos - *cvposn;
176 if( inside ) *inside = ( *inside_f )( params, ndim, inside_tol );
201 if( nverts != 3 )
MB_SET_ERR( MB_FAILURE,
"Incorrect vertex count for passed triangle :: expected value = 3 " );
202 if( ientDim != 1 )
MB_SET_ERR( MB_FAILURE,
"Requesting normal for unsupported dimension :: expected value = 1 " );
203 if( facet > 3 || facet < 0 )
MB_SET_ERR( MB_FAILURE,
"Incorrect local edge id :: expected value = one of 0-2" );
211 for(
int i = 0; i < 3; i++ )
213 edge[i] = verts[3 * id1 + i] - verts[3 * id0 + i];
216 double x0[3], x1[3], fnrm[3];
217 for(
int i = 0; i < 3; i++ )
219 x0[i] = verts[3 * 1 + i] - verts[3 * 0 + i];
220 x1[i] = verts[3 * 2 + i] - verts[3 * 0 + i];
222 fnrm[0] = x0[1] * x1[2] - x1[1] * x0[2];
223 fnrm[1] = x1[0] * x0[2] - x0[0] * x1[2];
224 fnrm[2] = x0[0] * x1[1] - x1[0] * x0[1];
228 double a =
edge[1] * fnrm[2] - fnrm[1] *
edge[2];
229 double b =
edge[2] * fnrm[0] - fnrm[2] *
edge[0];
230 double c =
edge[0] * fnrm[1] - fnrm[0] *
edge[1];
231 double nrm = sqrt( a * a + b * b + c * c );
233 if( nrm > std::numeric_limits< double >::epsilon() )