Vector Vector::AtIntersectionOfPlanes(Vector na, double da, Vector nb, double db, Vector nc, double dc, bool *parallel) { double det = det3(na.x, na.y, na.z, nb.x, nb.y, nb.z, nc.x, nc.y, nc.z); if(fabs(det) < 1e-10) { // arbitrary tolerance, not so good *parallel = true; return Vector::From(0, 0, 0); } *parallel = false; double detx = det3(da, na.y, na.z, db, nb.y, nb.z, dc, nc.y, nc.z); double dety = det3(na.x, da, na.z, nb.x, db, nb.z, nc.x, dc, nc.z); double detz = det3(na.x, na.y, da, nb.x, nb.y, db, nc.x, nc.y, dc ); return Vector::From(detx/det, dety/det, detz/det); }
/* ==================================== */ int32_t solsyst3( mat33 m, vec3 b, vec3 sol) /* ==================================== */ { mat33 m1; double d, d1, d2, d3; int32_t i, j; d = det3(m); if (((d >= 0) && (d < EPSILON)) || ((d <= 0) && (-d < EPSILON))) return 0; for (i = 0; i < 3; i++) m1[i][0] = b[i]; for (i = 0; i < 3; i++) for (j = 1; j < 3; j++) m1[i][j] = m[i][j]; d1 = det3(m1); for (i = 0; i < 3; i++) m1[i][1] = b[i]; for (i = 0; i < 3; i++) m1[i][0] = m[i][0]; d2 = det3(m1); for (i = 0; i < 3; i++) m1[i][2] = b[i]; for (i = 0; i < 3; i++) m1[i][1] = m[i][1]; d3 = det3(m1); sol[0] = d1 / d; sol[1] = d2 / d; sol[2] = d3 / d; return 1; } // solsyst3()
/* * compute the circle given 3 points */ static void compute_circle( point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, real *cx, real *cy, real *radius ) { mat3_t ma, mbx, mby, mc; real x0y0, x1y1, x2y2; real a, bx, by, c; /* calculate x0y0, .... */ x0y0 = pt0->x * pt0->x + pt0->y * pt0->y; x1y1 = pt1->x * pt1->x + pt1->y * pt1->y; x2y2 = pt2->x * pt2->x + pt2->y * pt2->y; /* setup A matrix */ ma[0][0] = pt0->x; ma[0][1] = pt0->y; ma[1][0] = pt1->x; ma[1][1] = pt1->y; ma[2][0] = pt2->x; ma[2][1] = pt2->y; ma[0][2] = ma[1][2] = ma[2][2] = 1.0; /* setup Bx matrix */ mbx[0][0] = x0y0; mbx[1][0] = x1y1; mbx[2][0] = x2y2; mbx[0][1] = pt0->y; mbx[1][1] = pt1->y; mbx[2][1] = pt2->y; mbx[0][2] = mbx[1][2] = mbx[2][2] = 1.0; /* setup By matrix */ mby[0][0] = x0y0; mby[1][0] = x1y1; mby[2][0] = x2y2; mby[0][1] = pt0->x; mby[1][1] = pt1->x; mby[2][1] = pt2->x; mby[0][2] = mby[1][2] = mby[2][2] = 1.0; /* setup C matrix */ mc[0][0] = x0y0; mc[1][0] = x1y1; mc[2][0] = x2y2; mc[0][1] = pt0->x; mc[1][1] = pt1->x; mc[2][1] = pt2->x; mc[0][2] = pt0->y; mc[1][2] = pt1->y; mc[2][2] = pt2->y; /* compute a, bx, by and c */ a = det3(&ma); bx = det3(&mbx); by = -det3(&mby); c = -det3(&mc); *cx = bx / (2.0 * a); *cy = by / (2.0 * a); *radius = sqrt(bx * bx + by * by - 4.0 * a * c) / (2.0 * dabs(a)); }
float SbMatrix::det4() const { return ( matrix[0][3] * det3(1, 2, 3, 0, 1, 2) + matrix[1][3] * det3(0, 2, 3, 0, 1, 2) + matrix[2][3] * det3(0, 1, 3, 0, 1, 2) + matrix[3][3] * det3(0, 1, 2, 0, 1, 2)); }
//! Returns the determinant of the matrix. Type det4() const { Type det = 0.0; det += m_data[0][0] * det3(1, 2, 3, 1, 2, 3); det -= m_data[1][0] * det3(0, 2, 3, 1, 2, 3); det += m_data[2][0] * det3(0, 1, 3, 1, 2, 3); det -= m_data[3][0] * det3(0, 1, 2, 1, 2, 3); return det; }
float det4( LWFMatrix4 m ) { LWFMatrix3 p; float a, b, c, d; initm3( p, m11, m21, m31, m12, m22, m32, m13, m23, m33 ); a = det3( p ); initm3( p, m10, m20, m30, m12, m22, m32, m13, m23, m33 ); b = det3( p ); initm3( p, m10, m20, m30, m11, m21, m31, m13, m23, m33 ); c = det3( p ); initm3( p, m10, m20, m30, m11, m21, m31, m12, m22, m32 ); d = det3( p ); return m00 * a - m01 * b + m02 * c - m03 * d; }
ElVisFloat det4(const Matrix4x4& m) { ElVisFloat det; det = mm(0, 0) * det3(mm(1, 1), mm(1, 2), mm(1, 3), mm(2, 1), mm(2, 2), mm(2, 3), mm(3, 1), mm(3, 2), mm(3, 3)); det -= mm(0, 1) * det3(mm(1, 0), mm(1, 2), mm(1, 3), mm(2, 0), mm(2, 2), mm(2, 3), mm(3, 0), mm(3, 2), mm(3, 3)); det += mm(0, 2) * det3(mm(1, 0), mm(1, 1), mm(1, 3), mm(2, 0), mm(2, 1), mm(2, 3), mm(3, 0), mm(3, 1), mm(3, 3)); det -= mm(0, 3) * det3(mm(1, 0), mm(1, 1), mm(1, 2), mm(2, 0), mm(2, 1), mm(2, 2), mm(3, 0), mm(3, 1), mm(3, 2)); return det; }
int mat3inv( mat3typ x ) { int i, j; realtyp deter; mat3typ ax; if ( h**o ) { setupmat3x( x ); if ( !( deter = x00*x11-x01*x10 ) ) return 0; x[0][0] = x00 / deter; x[0][1] = -x01 / deter; x[0][2] = (x01*x12-x02*x11) / deter; x[1][0] = -x10 / deter; x[1][1] = x11 / deter; x[1][2] = (x10*x02-x12*x00) / deter; return 1; } mat3cpy( ax, x ); deter = det3( ax ); if ( !deter ) return 0; for ( i = 0; i < 3; i++ ) for ( j = 0; j < 3; j++ ) x[i][j] = cofac3( 3, ax, j, i ) / deter; return 1; }
bool inverse3(float matrix[3][3], float inverseMatrix[3][3]) { // Check determinant, if 0 abort inversion: not possible float det = det3(matrix); if(det == 0) { printf("Inversion not possible\n"); return false; } // Clear the minor matrix just in case.. for(int i = 0; i < DIM; i++) for(int j = 0; j < DIM; j++) inverseMatrix[i][j] = 0; // First calculate Matrix of Minors, with cofactor then transpose minor3(matrix, inverseMatrix); transposeMatrix(inverseMatrix); // Apply inverse determinant to adjoint matrix for(int i = 0; i < DIM; i++) for(int j = 0; j < DIM; j++) inverseMatrix[i][j] = inverseMatrix[i][j] / det; return true; }
GLboolean gluInverse4_4m(GLUmat4 *result, const GLUmat4 *m) { const double det = gluDeterminant4_4m(m); double inv_det; unsigned c; unsigned r; if (det == 0.0) return GL_FALSE; inv_det = 1.0 / det; for (c = 0; c < 4; c++) { for (r = 0; r < 4; r++) { /* The usual equation is -1**(i+j) where i and j are * the row and column of the matrix on the range * [1, rows] and [1, cols]. Note that r and c are on * the range [0, rows - 1] and [0, cols - 1]. */ const double sign = ((c ^ r) & 1) ? -1.0 : 1.0; const double d = det3(m, c, r); result->col[r].values[c] = sign * inv_det * d; } } return GL_TRUE; }
void Procrustes(float *Q, float *Qavg, int n, float *P, float *Pavg, float *TLM) { float Ht[9]; // H=P*Q' Ht=Q*P' (' means transpose in my notation) float Ut[9], V[9], I[9]; float T[3]; // 3x1 translation vector float R[9]; // 3x3 rotation matrix float S[3]; // 3x1 vector of singular values Pavg[0] = (float)removeVectorMean(P, n); Pavg[1] = (float)removeVectorMean(P+n, n); Pavg[2] = (float)removeVectorMean(P+2*n, n); Qavg[0] = (float)removeVectorMean(Q, n); Qavg[1] = (float)removeVectorMean(Q+n, n); Qavg[2] = (float)removeVectorMean(Q+2*n, n); mat_mat_trans(Q,3,n,P,3,Ht); svd(Ht, 3, 3, Ut, V, S); multi(V,3,3,Ut,3,3,R); // Eq. (13) Arun et al. 1987 // if(opt_v) printf("det(R) = %f\n", det3(R)); if( det3(R) < 0.0 ) { // if(opt_v) printf("Negative determinant (reflection) detected\n"); V[2] *= -1.0; V[5] *= -1.0; V[8] *= -1.0; multi(V,3,3,Ut,3,3,R); // Eq. (13) Arun et al. 1987 // if(opt_v) printf("Corrected det(R) = %f\n", det3(R)); } multi(R,3,3,Pavg,3,1,T); for(int i=0; i<3; i++) T[i] = Qavg[i]-T[i]; // Eq. (10) Arun et al. 1987 // if(opt_v) printMatrix(T,3,1,"Translation:",NULL); set_to_I(TLM,4); TLM[0] = R[0]; TLM[1] = R[1]; TLM[2] = R[2]; TLM[3] = T[0]; TLM[4] = R[3]; TLM[5] = R[4]; TLM[6] = R[5]; TLM[7] = T[1]; TLM[8] = R[6]; TLM[9] = R[7]; TLM[10] = R[8]; TLM[11] = T[2]; return; }
double Matrix::determinant() { double det; det = x[0][0] * det3(x[1][1], x[1][2], x[1][3], x[2][1], x[2][2], x[2][3], x[3][1], x[3][2], x[3][3]); det -= x[0][1] * det3(x[1][0], x[1][2], x[1][3], x[2][0], x[2][2], x[2][3], x[3][0], x[3][2], x[3][3]); det += x[0][2] * det3(x[1][0], x[1][1], x[1][3], x[2][0], x[2][1], x[2][3], x[3][0], x[3][1], x[3][3]); det -= x[0][3] * det3(x[1][0], x[1][1], x[1][2], x[2][0], x[2][1], x[2][2], x[3][0], x[3][1], x[3][2]); return det; }
void inverse3( LWFMatrix3 m, LWFMatrix3 inv ) { float det; det = det3( m ); if ( fabs( det ) < EPSILON_F ) return; adjoint3( m, inv ); scalem3( inv, 1.0f / det ); }
float tmat::det() const { float d = m[0][0] * det3(m[1][1], m[1][2], m[1][3], m[2][1], m[2][2], m[2][3], m[3][1], m[3][2], m[3][3]); d -= m[0][1] * det3(m[1][0], m[1][2], m[1][3], m[2][0], m[2][2], m[2][3], m[3][0], m[3][2], m[3][3]); d += m[0][2] * det3(m[1][0], m[1][1], m[1][3], m[2][0], m[2][1], m[2][3], m[3][0], m[3][1], m[3][3]); d -= m[0][3] * det3(m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2], m[3][0], m[3][1], m[3][2]); return d; }
float Matrix::det() { float det, result = 0, i = 1.0; float Msub3[9]; int n; for ( n = 0; n < 4; n++, i *= -1.0 ) { submat( Msub3, 0, n ); det = det3( Msub3 ); result += m[n] * det * i; } return( result ); }
//Рассчитать определитель double Matrix::det() const { if (!isSquare()) throw Matrix::NOT_SQUARE; if (width == 2) return det2(); else if (width == 3) return det3(); else return detN(); }
precision Matrix::determinant(){ precision det; det = x[0][0] * det3(x[1][1], x[1][2], x[1][3], x[2][1], x[2][2], x[2][3], x[3][1], x[3][2], x[3][3]); det -= x[0][1] * det3(x[1][0], x[1][2], x[1][3], x[2][0], x[2][2], x[2][3], x[3][0], x[3][2], x[3][3]); det += x[0][2] * det3(x[1][0], x[1][1], x[1][3], x[2][0], x[2][1], x[2][3], x[3][0], x[3][1], x[3][3]); det -= x[0][3] * det3(x[1][0], x[1][1], x[1][2], x[2][0], x[2][1], x[2][2], x[3][0], x[3][1], x[3][2]); return det; }
/* ==================================== */ int32_t invmat3( mat33 ma, mat33 mr) /* ==================================== */ { double det = det3( ma ); if ( fabs( det ) < EPSILON ) return 0; mr[0][0] = ( ma[1][1]*ma[2][2] - ma[1][2]*ma[2][1] ) / det; mr[0][1] = -( ma[0][1]*ma[2][2] - ma[2][1]*ma[0][2] ) / det; mr[0][2] = ( ma[0][1]*ma[1][2] - ma[1][1]*ma[0][2] ) / det; mr[1][0] = -( ma[1][0]*ma[2][2] - ma[1][2]*ma[2][0] ) / det; mr[1][1] = ( ma[0][0]*ma[2][2] - ma[2][0]*ma[0][2] ) / det; mr[1][2] = -( ma[0][0]*ma[1][2] - ma[1][0]*ma[0][2] ) / det; mr[2][0] = ( ma[1][0]*ma[2][1] - ma[2][0]*ma[1][1] ) / det; mr[2][1] = -( ma[0][0]*ma[2][1] - ma[2][0]*ma[0][1] ) / det; mr[2][2] = ( ma[0][0]*ma[1][1] - ma[0][1]*ma[1][0] ) / det; return 1; } // invmat3()
// Return 1 if the point (x5,y5) lies in the quadrilateral with vertices at (x1,y1), (x2,y2), (x3,y3) // and (x4,y4), otherwise return 0. int checkPointInQuadrilateral(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4, float x5, float y5) { // Point (x5,y5) lies in the quadrilateral with vertices at (x1,y1), (x2,y2), (x3,y3) and (x4,y4) // if the orders (xi,yi,1), (x(i+1),y(i+1),1), (x5,y5) all appear clockwise or all counter-clockwise. if ( ( (det3(x1, y1, 1.0, x2, y2, 1.0, x5, y5, 1.0) >= 0) && (det3(x2, y2, 1.0, x3, y3, 1.0, x5, y5, 1.0) >= 0) && (det3(x3, y3, 1.0, x4, y4, 1.0, x5, y5, 1.0) >= 0) && (det3(x4, y4, 1.0, x1, y1, 1.0, x5, y5, 1.0) >= 0) ) || ( (det3(x1, y1, 1.0, x2, y2, 1.0, x5, y5, 1.0) <= 0) && (det3(x2, y2, 1.0, x3, y3, 1.0, x5, y5, 1.0) <= 0) && (det3(x3, y3, 1.0, x4, y4, 1.0, x5, y5, 1.0) <= 0) && (det3(x4, y4, 1.0, x1, y1, 1.0, x5, y5, 1.0) <= 0) ) ) return 1; else return 0; }
Matrix Matrix::inv(bool& success) { Matrix Mout; float mdet = det(); if ( fabs( mdet ) < 0.00000000000005 ) { cout << "Error matrix inverting! " << mdet << endl; return Mout; } float mtemp[9]; int i, j, sign; for ( i = 0; i < 4; i++ ) { for ( j = 0; j < 4; j++ ) { sign = 1 - ( (i +j) % 2 ) * 2; submat( mtemp, i, j ); Mout[i+j*4] = ( det3( mtemp ) * sign ) / mdet; } } return Mout; }
GLfloat gluDeterminant4_4m(const GLUmat4 *m) { double det = 0.0; unsigned c; for (c = 0; c < 4; c++) { if (m->col[c].values[3] != 0.0) { /* The usual equation is -1**(i+j) where i and j are * the row and column of the matrix on the range * [1, rows] and [1, cols]. Note that r and c are on * the range [0, rows - 1] and [0, cols - 1]. */ const double sign = ((c ^ 3) & 1) ? -1.0 : 1.0; const double d = det3(m, c, 3); det += sign * m->col[c].values[3] * d; } } return det; }
void FaceObject::posterior(combine_mode mode) { switch(mode){ double maxAct; case mean_shift: case mpi_search: case maximum: // not currently used break; case face_only: eyes.xLeft = x + (xSize*0.7077f); eyes.yLeft = y + (xSize*0.3099f); eyes.leftScale = scale; eyes.xRight = x + (xSize*0.3149f); eyes.yRight = y + (xSize*0.3136f); eyes.rightScale = scale; break; case wt_max: case none: maxAct = -1000000; if(leftEyes.size()){ eyes.leftEye = true; vector< EyeObject >::iterator it = leftEyes.begin(); for(; it != leftEyes.end(); ++it){ if(maxAct < it->activation){ maxAct = it->activation; eyes.xLeft = it->x; eyes.yLeft = it->y; eyes.leftScale = it->scale; } } } maxAct = -1000000; if(rightEyes.size()){ eyes.rightEye = true; vector< EyeObject >::iterator it = rightEyes.begin(); for(; it != rightEyes.end(); ++it){ if(maxAct < it->activation){ maxAct = it->activation; eyes.xRight = it->x; eyes.yRight = it->y; eyes.rightScale = it->scale; } } } break; case wt_avg: case average: float xWt; float yWt; float scaleWt; float totalAct; vector< vector< float > > meanSub; vector< vector< float > > wtMeanSub; vector< vector< float > > invMtx; vector< vector< float > > covMtx; vector< EyeObject > *EyesPtr = 0; //cout << "leftEyes size = " << leftEyes.size() << endl; for(int cur_eye = 0; cur_eye < 2; cur_eye++){ bool run = false; if(leftEyes.size() && cur_eye == 0){ EyesPtr = &leftEyes; run = true; } else if(rightEyes.size() && cur_eye == 1){ EyesPtr = &rightEyes; run = true; } else cur_eye++; if (run){ vector< EyeObject > Eyes = *EyesPtr; float expo; bool outlier = true; float mean3d[3]; float determ; while(outlier){ totalAct = 0.0f; xWt = 0.0f; yWt = 0.0f; scaleWt = 0.0f; for (unsigned int i = 0; i < Eyes.size(); i++){ expo = exp(Eyes[i].activation); xWt += (expo * Eyes[i].x); yWt += (expo * Eyes[i].y); scaleWt += (expo * Eyes[i].scale); totalAct += expo; } mean3d[0] = xWt/totalAct; mean3d[1] = yWt/totalAct; mean3d[2] = scaleWt/totalAct; for(unsigned int pos = 0; pos < Eyes.size(); ++pos){ vector< float > v; vector< float > wt; expo = exp(Eyes[pos].activation); v.push_back(Eyes[pos].x - mean3d[0]); wt.push_back(v[0] * expo); v.push_back(Eyes[pos].y - mean3d[1]); wt.push_back(v[1] * expo); v.push_back(Eyes[pos].scale - mean3d[2]); wt.push_back(v[2] * expo); meanSub.push_back(v); wtMeanSub.push_back(wt); } float divTotAct = 1.0f/totalAct; if(mtxMult_2T(meanSub, wtMeanSub, covMtx, divTotAct) != 9){ meanSub.clear(); wtMeanSub.clear(); invMtx.clear(); covMtx.clear(); break; } if((determ = det3(covMtx))){ TransCof3(covMtx, invMtx, determ); } else { //later implement psudo inverse page 192 meanSub.clear(); wtMeanSub.clear(); invMtx.clear(); covMtx.clear(); break; //exit while loop } outlier = findOutliers(meanSub, invMtx, Eyes); meanSub.clear(); wtMeanSub.clear(); invMtx.clear(); covMtx.clear(); }//while loop if(mean3d[0] > x && mean3d[0] < (x+xSize) && mean3d[1] > y && mean3d[1] < (y+ySize)){ if(cur_eye == 0){ eyes.xLeft = mean3d[0]; eyes.yLeft = mean3d[1]; eyes.leftScale = mean3d[2]; eyes.leftEye = true; } if(cur_eye == 1){ eyes.xRight = mean3d[0]; eyes.yRight = mean3d[1]; eyes.rightScale = mean3d[2]; eyes.rightEye = true; } } } } break; }; }
void Matrix::invert() { double det = determinant(); Matrix inverse; inverse.x[0][0] = det3(x[1][1], x[1][2], x[1][3], x[2][1], x[2][2], x[2][3], x[3][1], x[3][2], x[3][3]) / det; inverse.x[0][1] = -det3(x[0][1], x[0][2], x[0][3], x[2][1], x[2][2], x[2][3], x[3][1], x[3][2], x[3][3]) / det; inverse.x[0][2] = det3(x[0][1], x[0][2], x[0][3], x[1][1], x[1][2], x[1][3], x[3][1], x[3][2], x[3][3]) / det; inverse.x[0][3] = -det3(x[0][1], x[0][2], x[0][3], x[1][1], x[1][2], x[1][3], x[2][1], x[2][2], x[2][3]) / det; inverse.x[1][0] = -det3(x[1][0], x[1][2], x[1][3], x[2][0], x[2][2], x[2][3], x[3][0], x[3][2], x[3][3]) / det; inverse.x[1][1] = det3(x[0][0], x[0][2], x[0][3], x[2][0], x[2][2], x[2][3], x[3][0], x[3][2], x[3][3]) / det; inverse.x[1][2] = -det3(x[0][0], x[0][2], x[0][3], x[1][0], x[1][2], x[1][3], x[3][0], x[3][2], x[3][3]) / det; inverse.x[1][3] = det3(x[0][0], x[0][2], x[0][3], x[1][0], x[1][2], x[1][3], x[2][0], x[2][2], x[2][3]) / det; inverse.x[2][0] = det3(x[1][0], x[1][1], x[1][3], x[2][0], x[2][1], x[2][3], x[3][0], x[3][1], x[3][3]) / det; inverse.x[2][1] = -det3(x[0][0], x[0][1], x[0][3], x[2][0], x[2][1], x[2][3], x[3][0], x[3][1], x[3][3]) / det; inverse.x[2][2] = det3(x[0][0], x[0][1], x[0][3], x[1][0], x[1][1], x[1][3], x[3][0], x[3][1], x[3][3]) / det; inverse.x[2][3] = -det3(x[0][0], x[0][1], x[0][3], x[1][0], x[1][1], x[1][3], x[2][0], x[2][1], x[2][3]) / det; inverse.x[3][0] = -det3(x[1][0], x[1][1], x[1][2], x[2][0], x[2][1], x[2][2], x[3][0], x[3][1], x[3][2]) / det; inverse.x[3][1] = det3(x[0][0], x[0][1], x[0][2], x[2][0], x[2][1], x[2][2], x[3][0], x[3][1], x[3][2]) / det; inverse.x[3][2] = -det3(x[0][0], x[0][1], x[0][2], x[1][0], x[1][1], x[1][2], x[3][0], x[3][1], x[3][2]) / det; inverse.x[3][3] = det3(x[0][0], x[0][1], x[0][2], x[1][0], x[1][1], x[1][2], x[2][0], x[2][1], x[2][2]) / det; *this = inverse; }
/* Returns the inverse of mat, assuming it is nonsingular*/ tmat inverse(const tmat &mat) { tmat inv; float d = mat.det(); // row 1 inv.m[0][0] = det3(mat.m[1][1], mat.m[1][2], mat.m[1][3], mat.m[2][1], mat.m[2][2], mat.m[2][3], mat.m[3][1], mat.m[3][2], mat.m[3][3]) / d; inv.m[0][1] = -det3(mat.m[0][1], mat.m[0][2], mat.m[0][3], mat.m[2][1], mat.m[2][2], mat.m[2][3], mat.m[3][1], mat.m[3][2], mat.m[3][3]) / d; inv.m[0][2] = det3(mat.m[0][1], mat.m[0][2], mat.m[0][3], mat.m[1][1], mat.m[1][2], mat.m[1][3], mat.m[3][1], mat.m[3][2], mat.m[3][3]) / d; inv.m[0][3] = -det3(mat.m[0][1], mat.m[0][2], mat.m[0][3], mat.m[1][1], mat.m[1][2], mat.m[1][3], mat.m[2][1], mat.m[2][2], mat.m[2][3]) / d; // row 2 inv.m[1][0] = -det3(mat.m[1][0], mat.m[1][2], mat.m[1][3], mat.m[2][0], mat.m[2][2], mat.m[2][3], mat.m[3][0], mat.m[3][2], mat.m[3][3]) / d; inv.m[1][1] = det3(mat.m[0][0], mat.m[0][2], mat.m[0][3], mat.m[2][0], mat.m[2][2], mat.m[2][3], mat.m[3][0], mat.m[3][2], mat.m[3][3]) / d; inv.m[1][2] = -det3(mat.m[0][0], mat.m[0][2], mat.m[0][3], mat.m[1][0], mat.m[1][2], mat.m[1][3], mat.m[3][0], mat.m[3][2], mat.m[3][3]) / d; inv.m[1][3] = det3(mat.m[0][0], mat.m[0][2], mat.m[0][3], mat.m[1][0], mat.m[1][2], mat.m[1][3], mat.m[2][0], mat.m[2][2], mat.m[2][3]) / d; // row 3 inv.m[2][0] = det3(mat.m[1][0], mat.m[1][1], mat.m[1][3], mat.m[2][0], mat.m[2][1], mat.m[2][3], mat.m[3][0], mat.m[3][1], mat.m[3][3]) / d; inv.m[2][1] = -det3(mat.m[0][0], mat.m[0][1], mat.m[0][3], mat.m[2][0], mat.m[2][1], mat.m[2][3], mat.m[3][0], mat.m[3][1], mat.m[3][3]) / d; inv.m[2][2] = det3(mat.m[0][0], mat.m[0][1], mat.m[0][3], mat.m[1][0], mat.m[1][1], mat.m[1][3], mat.m[3][0], mat.m[3][1], mat.m[3][3]) / d; inv.m[2][3] = -det3(mat.m[0][0], mat.m[0][1], mat.m[0][3], mat.m[1][0], mat.m[1][1], mat.m[1][3], mat.m[2][0], mat.m[2][1], mat.m[2][3]) / d; // row 4 inv.m[3][0] = -det3(mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[2][0], mat.m[2][1], mat.m[2][2], mat.m[3][0], mat.m[3][1], mat.m[3][2]) / d; inv.m[3][1] = det3(mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[2][0], mat.m[2][1], mat.m[2][2], mat.m[3][0], mat.m[3][1], mat.m[3][2]) / d; inv.m[3][2] = -det3(mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[3][0], mat.m[3][1], mat.m[3][2]) / d; inv.m[3][3] = det3(mat.m[0][0], mat.m[0][1], mat.m[0][2], mat.m[1][0], mat.m[1][1], mat.m[1][2], mat.m[2][0], mat.m[2][1], mat.m[2][2]) / d; return inv; }
/* compute the curvatures using the derivatives * * curvatures are saved into an array: crv_result * in order of: Gauss, Mean, Max, Min */ double krv(vector v00, vector Deriv[3][3], real* crv_result) { double x,y,z,d; double xu,yu,zu,du, xv,yv,zv,dv; double xuu,yuu,zuu,duu, xvv,yvv,zvv,dvv; double xuv,yuv,zuv,duv; double kes, m1, m2, m3; double L, M, N; double E, G, F; double K, H, Max, Min; // results double disc; double special_curvature; x = v00[0]; y = v00[1]; z = v00[2]; d = v00[3]; xu = Deriv[1][0][0]; yu = Deriv[1][0][1]; zu = Deriv[1][0][2]; du = Deriv[1][0][3]; xuu = Deriv[2][0][0]; yuu = Deriv[2][0][1]; zuu = Deriv[2][0][2]; duu = Deriv[2][0][3]; xv = Deriv[0][1][0]; yv = Deriv[0][1][1]; zv = Deriv[0][1][2]; dv = Deriv[0][1][3]; xvv = Deriv[0][2][0]; yvv = Deriv[0][2][1]; zvv = Deriv[0][2][2]; dvv = Deriv[0][2][3]; xuv = Deriv[1][1][0]; yuv = Deriv[1][1][1]; zuv = Deriv[1][1][2]; duv = Deriv[1][1][3]; L=det4(xuu,yuu,zuu,duu, xu,yu,zu,du, xv,yv,zv,dv, x,y,z,d); N=det4(xvv,yvv,zvv,dvv, xu,yu,zu,du, xv,yv,zv,dv, x,y,z,d); M=det4(xuv,yuv,zuv,duv, xu,yu,zu,du, xv,yv,zv,dv, x,y,z,d); E = (xu*d-x*du)*(xu*d-x*du) + (yu*d-y*du)*(yu*d-y*du) + (zu*d-z*du)*(zu*d-z*du); G = (xv*d-x*dv)*(xv*d-x*dv) + (yv*d-y*dv)*(yv*d-y*dv) + (zv*d-z*dv)*(zv*d-z*dv); F = (xu*d-x*du)*(xv*d-x*dv) + (yu*d-y*du)*(yv*d-y*dv) + (zu*d-z*du)*(zv*d-z*dv); m1=det3(y,z,d,yu,zu,du,yv,zv,dv); m2=det3(x,z,d,xu,zu,du,xv,zv,dv); m3=det3(x,y,d,xu,yu,du,xv,yv,dv); kes=m1*m1+m2*m2+m3*m3; if(0) {//fabs(kes) < tol*tol) { // temp for Jorg & Kestas & me class A K = H = Max = Min = 0; } else { K = d*d*d*d*(L*N-M*M)/(kes*kes); // Gaussian curvature H = d*(L*G-2*M*F+N*E) / sqrt(kes*kes*kes) /2; // Mean curvature disc = H*H - K; if (disc < 0) { if (disc < -tol) printf("[krv] disc %f H %f \n",disc, H); Max = Min = H; } else { disc = sqrt(disc); Max = H + disc; Min = H - disc; } } if(0) { // scale the result by log? K = scalebylog(K); H = scalebylog(H); Max = scalebylog(Max); Min = scalebylog(Min); } crv_result[0] = K; // Gaussian curvature crv_result[1] = H; // Mean curvature crv_result[2] = Max; // max curvature crv_result[3] = Min; // min curvature // a special special_curvature = ratio_a*K + ratio_b*H*H; // printf("special_curvature : %f\n", special_curvature); if( freshObject ) min_crv_value[4] = max_crv_value[4] = special_curvature; else { if(special_curvature<min_crv_value[4]) min_crv_value[4] = special_curvature; if(special_curvature>max_crv_value[4]) max_crv_value[4] = special_curvature; } // set the maximum or minimum value of all four curvatures minmax(crv_result, GAUSS_CRV, 4); return K; }
inline void Matrix::invert(){ Matrix inverse; precision det = determinant(); inverse.x[0][0] = det3(x[1][1], x[1][2], x[1][3], x[2][1], x[2][2], x[2][3], x[3][1], x[3][2], x[3][3]) / det; inverse.x[0][1] = -det3(x[0][1], x[0][2], x[0][3], x[2][1], x[2][2], x[2][3], x[3][1], x[3][2], x[3][3]) / det; inverse.x[0][2] = det3(x[0][1], x[0][2], x[0][3], x[1][1], x[1][2], x[1][3], x[3][1], x[3][2], x[3][3]) / det; inverse.x[0][3] = -det3(x[0][1], x[0][2], x[0][3], x[1][1], x[1][2], x[1][3], x[2][1], x[2][2], x[2][3]) / det; inverse.x[1][0] = -det3(x[1][0], x[1][2], x[1][3], x[2][0], x[2][2], x[2][3], x[3][0], x[3][2], x[3][3]) / det; inverse.x[1][1] = det3(x[0][0], x[0][2], x[0][3], x[2][0], x[2][2], x[2][3], x[3][0], x[3][2], x[3][3]) / det; inverse.x[1][2] = -det3(x[0][0], x[0][2], x[0][3], x[1][0], x[1][2], x[1][3], x[3][0], x[3][2], x[3][3]) / det; inverse.x[1][3] = det3(x[0][0], x[0][2], x[0][3], x[1][0], x[1][2], x[1][3], x[2][0], x[2][2], x[2][3]) / det; inverse.x[2][0] = det3(x[1][0], x[1][1], x[1][3], x[2][0], x[2][1], x[2][3], x[3][0], x[3][1], x[3][3]) / det; inverse.x[2][1] = -det3(x[0][0], x[0][1], x[0][3], x[2][0], x[2][1], x[2][3], x[3][0], x[3][1], x[3][3]) / det; inverse.x[2][2] = det3(x[0][0], x[0][1], x[0][3], x[1][0], x[1][1], x[1][3], x[3][0], x[3][1], x[3][3]) / det; inverse.x[2][3] = -det3(x[0][0], x[0][1], x[0][3], x[1][0], x[1][1], x[1][3], x[2][0], x[2][1], x[2][3]) / det; inverse.x[1][0] = -det3(x[1][0], x[1][1], x[1][2], x[2][0], x[2][1], x[2][2], x[3][0], x[3][1], x[3][2]) / det; inverse.x[1][1] = det3(x[0][0], x[0][1], x[0][2], x[2][0], x[2][1], x[2][2], x[3][0], x[3][1], x[3][2]) / det; inverse.x[1][2] = -det3(x[0][0], x[0][1], x[0][2], x[1][0], x[1][1], x[1][2], x[3][0], x[3][1], x[3][2]) / det; inverse.x[1][3] = det3(x[0][0], x[0][1], x[0][2], x[1][0], x[1][1], x[1][2], x[2][0], x[2][1], x[2][2]) / det; *this = inverse; }
Int_t r3b_sim_and_rclass(){ // Load the Main Simulation macro gROOT->LoadMacro("r3ball.C"); //------------------------------------------------- // Monte Carlo type | fMC (TString) //------------------------------------------------- // Geant3: "TGeant3" // Geant4: "TGeant4" // Fluka : "TFluka" TString fMC ="TGeant3"; //------------------------------------------------- // Primaries generation // Event Generator Type | fGene (TString) //------------------------------------------------- // Box generator: "box" // Ascii generator: "ascii" // R3B spec. generator: "r3b" TString fGene="box"; //------------------------------------------------- // Secondaries generation (G4 only) // R3B Spec. PhysicList | fUserPList (Bool_t) // ---------------------------------------------- // VMC Standard kFALSE // R3B Special kTRUE; Bool_t fUserPList= kTRUE; // Target type TString target1="LeadTarget"; TString target2="Para"; TString target3="Para45"; TString target4="LiH"; //------------------------------------------------- //- Geometrical Setup Definition //- Non Sensitiv | fDetName (String) //------------------------------------------------- // Target: TARGET // Magnet: ALADIN // //------------------------------------------------- //- Sensitiv | fDetName //------------------------------------------------- // Calorimeter: CALIFA // CRYSTALBALL // // Tof: TOF // MTOF // // Tracker: DCH // TRACKER // GFI // // Neutron Detector // Plastic LAND // RPC // RPCFLAND // RPCMLAND TObjString det1("TARGET"); TObjString det2("ALADIN"); TObjString det3("CALIFA"); TObjString det4("CRYSTALBALL"); TObjString det5("TOF"); TObjString det6("MTOF"); TObjString det7("DCH"); TObjString det8("TRACKER"); TObjString det9("GFI"); TObjString det10("LAND"); TObjString det11("RPCMLAND"); TObjString det12("RPCFLAND"); TObjString det13("SCINTNEULAND"); TObjArray fDetList; // fDetList.Add(&det1); fDetList.Add(&det2); // fDetList.Add(&det4); // fDetList.Add(&det5); // fDetList.Add(&det6); // fDetList.Add(&det7); // fDetList.Add(&det8); // fDetList.Add(&det9); fDetList.Add(&det10); // fDetList.Add(&det11); //------------------------------------------------- //- N# of Sim. Events | nEvents (Int_t) //------------------------------------------------- Int_t nEvents = 1; //------------------------------------------------- //- EventDisplay | fEventDisplay (Bool_t) //------------------------------------------------- // connected: kTRUE // not connected: kFALSE Bool_t fEventDisplay=kTRUE; // Magnet Field definition Bool_t fR3BMagnet = kTRUE; // Main Sim function call r3ball( nEvents, fDetList, target1, fEventDisplay, fMC, fGene, fUserPList, fR3BMagnet ); //------------------- Read Data from LMD-ROOT file ------------------------------------- // the ROOT files (simulated and experimental) are the same but, for testing purpose, show how to use two quantities for comparison R3BLandData* LandData1 = new R3BLandData("s318_172.root", "h309"); // file input and tree name R3BLandData* LandData2 = new R3BLandData("s318_172.root", "h309"); // file input and tree name // Define diferent options for TCanvas TCanvas* c = new TCanvas("Compare quantities from ROOT files","ROOT Canvas"); c->Divide(2,1); // Divide a canvas in two ...or more int entries1 = LandData1->GetEntries(); // entries number of first TTree int entries2 = LandData2->GetEntries(); // entries number of first TTree TLeaf* leaf1; // TLeaf* leaf11; // define one leaf... TLeaf* leaf2; // TLeaf* leaf22; // define another leaf cout<<"Entries number in first TTree = "<<entries1<<endl; cout<<"Entries number in second TTree = "<<entries2<<endl; // Reprezentation of 1D histogram from ROOT files for (int i=0; i < entries1; i++) { leaf1 = LandData1->GetLeaf("Nte",i); // Accessing TLeaf informations // leaf11 = LandData1->GetLeaf("Nhe",i); // Accessing TLeaf informations LandData1->FillHisto1D(leaf1); // Fill 1D histogram ... automatical bin width // LandData1->FillHisto2D(leaf1,leaf11); // Fill 2D histogram ... automatical bin width } c->cd(1); LandData1->Draw1D(); // Plotting 1D histogram ... automatical bin width // LandData1->Draw2D(); // Plotting 2D histogram ... automatical bin width for (int i=0; i < entries2; i++) { leaf2 = LandData2->GetLeaf("Nhe",i); // Accessing TLeaf informations // leaf22 = LandData2->GetLeaf("Nte",i); // Accessing TLeaf informations LandData2->FillHisto1D(leaf2); // Fill 1D histogram ... automatical bin width // LandData2->FillHisto2D(leaf2,leaf22); // Fill 2D histogram ... automatical bin width } c->cd(2); LandData2->Draw1D(); // Plotting 1D histogram ... automatical bin width // LandData2->Draw2D(); // Plotting 2D histogram ... automatical bin width // ... or you can plot on the same histogram by comment the precedent two line and comment out the next line // LandData2->Draw1Dsame(); // Plotting 1D histogram ... automatical bin width // ... The same things for 2D histograming //####### for diferent TLeaf analysis ############### /* Int_t len = leaf1->GetLen(); for(Int_t j=0; j<len ; j++) { leaf1->GetValue(j); // TLeaf Value for different analysis } */ }
Matrix4x4 inverse(const Matrix4x4& m) { Matrix4x4 inverse; ElVisFloat det = det4(m); inverse[0] = det3(mm(1, 1), mm(1, 2), mm(1, 3), mm(2, 1), mm(2, 2), mm(2, 3), mm(3, 1), mm(3, 2), mm(3, 3)) / det; inverse[1] = -det3(mm(0, 1), mm(0, 2), mm(0, 3), mm(2, 1), mm(2, 2), mm(2, 3), mm(3, 1), mm(3, 2), mm(3, 3)) / det; inverse[2] = det3(mm(0, 1), mm(0, 2), mm(0, 3), mm(1, 1), mm(1, 2), mm(1, 3), mm(3, 1), mm(3, 2), mm(3, 3)) / det; inverse[3] = -det3(mm(0, 1), mm(0, 2), mm(0, 3), mm(1, 1), mm(1, 2), mm(1, 3), mm(2, 1), mm(2, 2), mm(2, 3)) / det; inverse[4] = -det3(mm(1, 0), mm(1, 2), mm(1, 3), mm(2, 0), mm(2, 2), mm(2, 3), mm(3, 0), mm(3, 2), mm(3, 3)) / det; inverse[5] = det3(mm(0, 0), mm(0, 2), mm(0, 3), mm(2, 0), mm(2, 2), mm(2, 3), mm(3, 0), mm(3, 2), mm(3, 3)) / det; inverse[6] = -det3(mm(0, 0), mm(0, 2), mm(0, 3), mm(1, 0), mm(1, 2), mm(1, 3), mm(3, 0), mm(3, 2), mm(3, 3)) / det; inverse[7] = det3(mm(0, 0), mm(0, 2), mm(0, 3), mm(1, 0), mm(1, 2), mm(1, 3), mm(2, 0), mm(2, 2), mm(2, 3)) / det; inverse[8] = det3(mm(1, 0), mm(1, 1), mm(1, 3), mm(2, 0), mm(2, 1), mm(2, 3), mm(3, 0), mm(3, 1), mm(3, 3)) / det; inverse[9] = -det3(mm(0, 0), mm(0, 1), mm(0, 3), mm(2, 0), mm(2, 1), mm(2, 3), mm(3, 0), mm(3, 1), mm(3, 3)) / det; inverse[10] = det3(mm(0, 0), mm(0, 1), mm(0, 3), mm(1, 0), mm(1, 1), mm(1, 3), mm(3, 0), mm(3, 1), mm(3, 3)) / det; inverse[11] = -det3(mm(0, 0), mm(0, 1), mm(0, 3), mm(1, 0), mm(1, 1), mm(1, 3), mm(2, 0), mm(2, 1), mm(2, 3)) / det; inverse[12] = -det3(mm(1, 0), mm(1, 1), mm(1, 2), mm(2, 0), mm(2, 1), mm(2, 2), mm(3, 0), mm(3, 1), mm(3, 2)) / det; inverse[13] = det3(mm(0, 0), mm(0, 1), mm(0, 2), mm(2, 0), mm(2, 1), mm(2, 2), mm(3, 0), mm(3, 1), mm(3, 2)) / det; inverse[14] = -det3(mm(0, 0), mm(0, 1), mm(0, 2), mm(1, 0), mm(1, 1), mm(1, 2), mm(3, 0), mm(3, 1), mm(3, 2)) / det; inverse[15] = det3(mm(0, 0), mm(0, 1), mm(0, 2), mm(1, 0), mm(1, 1), mm(1, 2), mm(2, 0), mm(2, 1), mm(2, 2)) / det; return inverse; }
/* * test if a point is inside a circle given by 3 points, 1 if inside, 0 if outside */ static int in_circle( point2d_t *pt0, point2d_t *pt1, point2d_t *pt2, point2d_t *p ) { mat3_t ma, mbx, mby, mc; real x0y0, x1y1, x2y2; real a, bx, by, c, res; /* calculate x0y0, .... */ x0y0 = pt0->x * pt0->x + pt0->y * pt0->y; x1y1 = pt1->x * pt1->x + pt1->y * pt1->y; x2y2 = pt2->x * pt2->x + pt2->y * pt2->y; /* setup A matrix */ ma[0][0] = pt0->x; ma[0][1] = pt0->y; ma[1][0] = pt1->x; ma[1][1] = pt1->y; ma[2][0] = pt2->x; ma[2][1] = pt2->y; ma[0][2] = ma[1][2] = ma[2][2] = 1.0; /* setup Bx matrix */ mbx[0][0] = x0y0; mbx[1][0] = x1y1; mbx[2][0] = x2y2; mbx[0][1] = pt0->y; mbx[1][1] = pt1->y; mbx[2][1] = pt2->y; mbx[0][2] = mbx[1][2] = mbx[2][2] = 1.0; /* setup By matrix */ mby[0][0] = x0y0; mby[1][0] = x1y1; mby[2][0] = x2y2; mby[0][1] = pt0->x; mby[1][1] = pt1->x; mby[2][1] = pt2->x; mby[0][2] = mby[1][2] = mby[2][2] = 1.0; /* setup C matrix */ mc[0][0] = x0y0; mc[1][0] = x1y1; mc[2][0] = x2y2; mc[0][1] = pt0->x; mc[1][1] = pt1->x; mc[2][1] = pt2->x; mc[0][2] = pt0->y; mc[1][2] = pt1->y; mc[2][2] = pt2->y; /* compute a, bx, by and c */ a = det3(&ma); bx = det3(&mbx); by = -det3(&mby); c = -det3(&mc); res = a * (p->x * p->x + p->y * p->y ) - bx * p->x - by * p->y + c; if( res < 0.0 ) return INSIDE; else if( res > 0.0 ) return OUTSIDE; return ON_CIRCLE; }
Matrix4 Matrix4::inverse() const { Matrix4 m; double determinant = det(); if (determinant == 0.0) throw cvgException("[Matrix4] The matrix inverse does not exist"); double inv_det = 1.0 / determinant; // Calculate determinant matrix already transposed to save speed m.value[0][0] = det3(value[1][1], value[1][2], value[1][3], value[2][1], value[2][2], value[2][3], value[3][1], value[3][2], value[3][3]) * inv_det; m.value[1][0] = -det3(value[1][0], value[1][2], value[1][3], value[2][0], value[2][2], value[2][3], value[3][0], value[3][2], value[3][3]) * inv_det; m.value[2][0] = det3(value[1][0], value[1][1], value[1][3], value[2][0], value[2][1], value[2][3], value[3][0], value[3][1], value[3][3]) * inv_det; m.value[3][0] = -det3(value[1][0], value[1][1], value[1][2], value[2][0], value[2][1], value[2][2], value[3][0], value[3][1], value[3][2]) * inv_det; m.value[0][1] = -det3(value[0][1], value[0][2], value[0][3], value[2][1], value[2][2], value[2][3], value[3][1], value[3][2], value[3][3]) * inv_det; m.value[1][1] = det3(value[0][0], value[0][2], value[0][3], value[2][0], value[2][2], value[2][3], value[3][0], value[3][2], value[3][3]) * inv_det; m.value[2][1] = -det3(value[0][0], value[0][1], value[0][3], value[2][0], value[2][1], value[2][3], value[3][0], value[3][1], value[3][3]) * inv_det; m.value[3][1] = det3(value[0][0], value[0][1], value[0][2], value[2][0], value[2][1], value[2][2], value[3][0], value[3][1], value[3][2]) * inv_det; m.value[0][2] = det3(value[0][1], value[0][2], value[0][3], value[1][1], value[1][2], value[1][3], value[3][1], value[3][2], value[3][3]) * inv_det; m.value[1][2] = -det3(value[0][0], value[0][2], value[0][3], value[1][0], value[1][2], value[1][3], value[3][0], value[3][2], value[3][3]) * inv_det; m.value[2][2] = det3(value[0][0], value[0][1], value[0][3], value[1][0], value[1][1], value[1][3], value[3][0], value[3][1], value[3][3]) * inv_det; m.value[3][2] = -det3(value[0][0], value[0][1], value[0][2], value[1][0], value[1][1], value[1][2], value[3][0], value[3][1], value[3][2]) * inv_det; m.value[0][3] = -det3(value[0][1], value[0][2], value[0][3], value[1][1], value[1][2], value[1][3], value[2][1], value[2][2], value[2][3]) * inv_det; m.value[1][3] = det3(value[0][0], value[0][2], value[0][3], value[1][0], value[1][2], value[1][3], value[2][0], value[2][2], value[2][3]) * inv_det; m.value[2][3] = -det3(value[0][0], value[0][1], value[0][3], value[1][0], value[1][1], value[1][3], value[2][0], value[2][1], value[2][3]) * inv_det; m.value[3][3] = det3(value[0][0], value[0][1], value[0][2], value[1][0], value[1][1], value[1][2], value[2][0], value[2][1], value[2][2]) * inv_det; return m; }