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 34 35 36 37 38 39 40 41 42 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
|
void calnormal()
{
long numcal;
float indexNC0,indexNC1;
float error;
float aa0 = 0, ab0 = 0, ac0 = 0, ad0 = 0;
float bb0 = 0, bc0 = 0, bd0 = 0;
float cc0 = 0, cd0 = 0;
float dd0 = 0;
float aa, ab, ac, ad;
float bb, bc, bd;
float cc, cd;
float dd;
for(int i=0;i<noofvert;i++)
{
numcal = vlist[i].returnsizef();
for(int j=0;j<numcal;j=j+2)
{
indexNC0 = vlist[i].returnindexf(j);
u.ax = vlist[i].returnx() - vlist[indexNC0].returnx();
u.ay = vlist[i].returny() - vlist[indexNC0].returny();
u.az = vlist[i].returnz() - vlist[indexNC0].returnz();
if(j == 0){v0 = u;}
indexNC1 = vlist[i].returnindexf(j+1);
v.ax = vlist[i].returnx() - vlist[indexNC1].returnx();
v.ay = vlist[i].returny() - vlist[indexNC1].returny();
v.az = vlist[i].returnz() - vlist[indexNC1].returnz();
normal.ax = u.ay * v.az - u.az * v.ay;
normal.ay = u.az * v.ax - u.ax * v.az;
normal.az = u.ax * v.ay - u.ay * v.ax;
normal.D = - vlist[i].returnx() * normal.ax - vlist[i].returny() * normal.ay - vlist[i].returnz() * normal.az;
aa = normal.ax * normal.ax;
ab = normal.ax * normal.ay;
ac = normal.ax * normal.az;
ad = normal.ax * normal.D;
bb = normal.ay * normal.ay;
bc = normal.ay * normal.az;
bd = normal.ay * normal.D;
cc = normal.az * normal.az;
cd = normal.az * normal.D;
dd = normal.D * normal.D;
aa0 = aa0 + aa;
ab0 = ab0 + ab; bb0 = bb0 + bb;
ac0 = ac0 + ac; bc0 = bc0 + bc; cc0 = cc0 + cc;
ad0 = ad0 + ad; bd0 = bd0 + bd; cd0 = cd0 + cd; dd0 = dd0 + dd;
}
float error1,error2,error3;
error1 = cd0 * vlist[i].returnz();
error2 = dd0 ;
error3 = error2 + error1;
cout << error1 << " " << error2 << " " << error3 << endl;
cout << endl;
}
cout << endl;
}
|