/* IN : ind_tr, XYZv, weight, defl, tri_pt4 OUT : Cii_lin weight = (sig1-sig2)/((sig1+sig2)*2*pi) */ #include #include "mex.h" #define NR_NEIGH_TRI 10 /* Max # of triangle neighbours */ void Cii_linear(double C[], double ind_tr[], int Ntri, double XYZv[], int Nvert, double weight, double defl, double tri_pt4[]) { double pi, dO, dO1, dO2, dO3 ; double si[3], r1[3], r2[3], r3[3], det, den ; double d1, d2, d3, sumOm, di2pi ; double r21[3], r32[3], r13[3], l21, l32, l13 ; double g1, g2 ,g3, Ome[3], z1[3], z2[3], z3[3] ; double tmp[3], n[3], nn, beta, ideuxA, epsi ; double a[3][3], b[3], deter, rc[3], r_b[3], R, Ome_ro ; /* r0 = si, for the calculuus of the ASA */ double psi1[NR_NEIGH_TRI], psi2[NR_NEIGH_TRI], phi12[NR_NEIGH_TRI] ; int i, j, u, v, w, nze, lze[NR_NEIGH_TRI] ; /* 10 neighbouring triangles max for the ASA */ printf("Nvert = %d\n",Nvert) ; printf("Ntri = %d\n",Ntri) ; printf("weight = %f , defl = %f \n",weight,defl) ; epsi = .000000000001 ; pi = 4.*atan(1.) ; for (i=0;iepsi) { /* if (dO!=0) { */ /* check that SA ~= 0 */ r21[0]=r2[0]-r1[0]; r21[1]=r2[1]-r1[1];r21[2]=r2[2]-r1[2]; r32[0]=r3[0]-r2[0]; r32[1]=r3[1]-r2[1];r32[2]=r3[2]-r2[2]; r13[0]=r1[0]-r3[0];r13[1]=r1[1]-r3[1]; r13[2]=r1[2]-r3[2]; l21=sqrt(r21[0]*r21[0]+ r21[1]*r21[1]+r21[2]*r21[2]) ; l32=sqrt(r32[0]*r32[0]+ r32[1]*r32[1]+r32[2]*r32[2]) ; l13=sqrt(r13[0]*r13[0]+ r13[1]*r13[1]+r13[2]*r13[2]) ; g1 = log( (l21*d2+r21[0]*r2[0]+ r21[1]*r2[1]+r21[2]*r2[2])/ (l21*d1+r21[0]*r1[0]+ r21[1]*r1[1]+r21[2]*r1[2]) ) / l21 ; g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n[0]+ z2[1]*n[1]+z2[2]*n[2])*dO -beta*(r13[0]*Ome[0]+ r13[1]*Ome[1]+r13[2]*Ome[2]) ) ; dO3=ideuxA*( (z3[0]*n[0]+ z3[1]*n[1]+z3[2]*n[2])*dO -beta*(r21[0]*Ome[0]+ r21[1]*Ome[1]+r21[2]*Ome[2]) ) ; /* printf("dO123 = %f %f %f\n" ,dO1,dO2,dO3) ;*/ } else { dO1=dO/3 ; dO2=dO/3 ; dO3=dO/3 ; /* dO=0 ; */ } C[i+u*Nvert] = C[i+u*Nvert] + dO1 * weight ; C[i+v*Nvert] = C[i+v*Nvert] + dO2 * weight ; C[i+w*Nvert] = C[i+w*Nvert] + dO3 * weight ; /* printf("C(i,[u v w]) = %f %f %f\n" ,C[i+u*Nvert],C[i+v*Nvert],C[i+w*Nvert]) ; /* Distribution of the SA on the 3 vert */ sumOm = sumOm + dO ; /* printf("sumOm = %f \n",sumOm) ;*/ /* Total SA */ } else { /* list and # of triangle for autosolid angle */ lze[nze] = j ; nze++ ; } } /*******************************/ /* Autosolid angle calculation */ di2pi = (2.*pi-sumOm) ; /* Missing SA */ /*printf("Missing angle = %f\n",di2pi) ;*/ Ome_ro = 0 ; for (j=0;j1) { mexErrMsgTxt("Only ONE output : Cii_lin") ; } mind=mxGetM(prhs[0]) ; nind=mxGetN(prhs[0]) ; if (!mxIsNumeric(prhs[0]) || mxIsComplex(prhs[0]) || mxIsSparse(prhs[0]) || (nind!=3)) { mexErrMsgTxt("ind_tr must be a matrix : Ntri x 3") ; } mXYZv=mxGetM(prhs[1]) ; nXYZv=mxGetN(prhs[1]) ; if (!mxIsNumeric(prhs[1]) || mxIsComplex(prhs[1]) || mxIsSparse(prhs[1]) || (nXYZv!=3) ) { mexErrMsgTxt("XYZv must be a matrix : Nvert x 3") ; } if (!mxIsNumeric(prhs[2]) || mxIsComplex(prhs[2]) || mxIsSparse(prhs[2]) || !mxIsDouble(prhs[2]) || mxGetN(prhs[2])*mxGetM(prhs[2])!=1 ) { mexErrMsgTxt("weight must be a scalar") ; } if (!mxIsNumeric(prhs[3]) || mxIsComplex(prhs[3]) || mxIsSparse(prhs[3]) || !mxIsDouble(prhs[3]) || mxGetN(prhs[3])*mxGetM(prhs[3])!=1 ) { mexErrMsgTxt("defl must be a scalar") ; } mtri_pt4=mxGetM(prhs[4]) ; ntri_pt4=mxGetN(prhs[4]) ; if (!mxIsNumeric(prhs[4]) || mxIsComplex(prhs[4]) || mxIsSparse(prhs[4]) || (ntri_pt4!=3) || (mtri_pt4!=mind)) { mexErrMsgTxt("tri_pt4 must be a matrix : Ntri x 3") ; } plhs[0]=mxCreateDoubleMatrix(mXYZv,mXYZv,mxREAL) ; Cii_l = mxGetPr(plhs[0]) ; ind_tr = mxGetPr(prhs[0]) ; XYZv = mxGetPr(prhs[1]) ; weight = mxGetScalar(prhs[2]) ; defl = mxGetScalar(prhs[3]) ; tri_pt4 = mxGetPr(prhs[4]) ; Cii_linear(Cii_l, ind_tr, mind, XYZv, mXYZv, weight, defl, tri_pt4) ; mxSetPr(plhs[0],Cii_l) ; }