voidfitline (consttcolgp _ array1of pnt2dthepoints,const STD 33603360 stringthefilename,
gp_Lin2dtheLine )
{
math _ vector ab (1,2,0.0 );
math _ vector ax (1,2,0.0 );
math _ matrix am (1,2,1,2 );
Standard_Real aSxi=0.0;
标准asyi=0.0;
Standard_Real aSxx=0.0;
标准比例_ real asxy=0.0;
STD : ofstreamadrawfile (the filename ); for (standard _ integeri=the points.lower ); i=thePoints.Upper (; I )
{ const gp _ pnt 2d apoint=the points.value (I;
asxy=apoint.x(*apoint.y );
aDrawFile 'vpoint p' i ' '
}
am (1,1 )=thePoints.Size );
am (1,2 )=aSxi;
am (2,1 )=aSxi;
am (2,2 )=aSxx;
ab(1)=aSyi;
ab(2)=aSxy;
OSD_Chronometer aChronometer;
aChronometer.Start (;
math_GaussAsolver(am; //math _ gaussleastsquareasolver (am; //math_SVDasolver(am;
asolver.solve(ab,aX ); if(Asolver.isdone ) )
{
Sandard_realaa=ax(1;
Sandard_realab=ax(2);
gp_pnt2dAP1(0.0,aA );
gp_pnt2dAP2(-aa/ab,0.0 );
theline.setlocation(AP1;
theline.setdirection(gp_VEC2d ) AP1,aP2 ).XY );
aDrawFile 'vaxis l '
AP1.x''AP1.y''0'
AP2.x''AP2.y''0':endl
STD :3360 cout '================STD :3360 cout '===3360 endl
ax.dump(STD:3360cout;
}
aChronometer.Stop (;
aChronometer.Show (;
}intmain () ) )。
{
gp_Lin2d aLine; //Test data 1
TCO lgp _ array1of pnt 2d apoints1(1,6 );
apoints1.setvalue(1,gp_pnt2d ) 36.9,181.0 );
apoints1.setvalue(2,gp_pnt2d ) 46.7,197.0 );
apoints1.setvalue(3,gp_pnt2d ) 63.7,235.0 );
apoints1.setvalue(4,gp_pnt2d ) 77.8,270.0 );
apoints1.setvalue(5,gp_pnt2d ) 84.0,283.0 );
apoints1.setvalue(6,gp_pnt2d ) 87.5,292.0 );
fitline(apoints1,' fit1.tcl ',aLine ); //Test data 2
TCO lgp _ array1of pnt 2d apoints2(0,7 );
apoints2.setvalue(0,gp_pnt2d ) 0.0,27.0 );
apoints2.setvalue(1,gp_pnt2d ) 1.0,26.8 );
apoints2.setvalue(2,gp_pnt2d ) 2.0,26.5 );
apoints2.setvalue(3,gp_pnt2d ) 3.0,26.3 );
apoints2.setvalue(4,gp_pnt2d ) 4.0,26.1 );
apoints2.setvalue(5,gp_pnt2d ) 5.0,25.7 );
apoints2.setvalue(6,gp_pnt2d ) 6.0,25.3 );
apoints2.setvalue(7,gp_pnt2d ) 7.0,24.8 );
fitline(apoints2,' fit2.tcl ',aLine ); 返回0;
}