Seg2d APP_seg_mean_square(SomApproxPoly * s1, SomApproxPoly *s2) { RMat_Inertie m = s1->inert_dif(s2); Seg2d s = seg_mean_square(m); SegComp sc(s.p0(),s.p1()); return Seg2d(sc.proj_ortho_droite(s1->_pt),sc.proj_ortho_droite(s2->_pt)); }
void bench_seg_mean_square() { for (int i = 0; i<100 ; i++) { INT nx = (INT) (10 +NRrandom3()*20); INT ny = nx -5; Pt2dr tr = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4); Pt2dr rot = Pt2dr::FromPolar(1.0,NRrandom3() *100); RMat_Inertie m; for (int x= -nx; x <= nx ; x++) for (int y= -ny; y <= ny ; y++) { Pt2dr Z = tr+rot*Pt2dr(x,y); m.add_pt_en_place(Z.x,Z.y); } Seg2d s = seg_mean_square(m,100.0); Pt2dr cdg = s.p0(); Pt2dr all = (s.p1()-s.p0())/ 100.0; BENCH_ASSERT ( (euclid(cdg-tr) < BIG_epsilon) && (std::abs(all^rot) < BIG_epsilon) ); // BENCH_ASSERT(Abs(d0 -d1) < BIG_epsilon); } }