Exemple #1
0
void PtsOfSquare(ElFifo<Pt2dr> & pts,Pt2dr p0,Pt2dr p1)
{
    pts.set_circ(true);
    pts.clear();
    Pt2dr H = p1 -p0;
    Pt2dr V = H * Pt2dr(0,1);


    pts.pushlast(p0);
    pts.pushlast(p1);
    pts.pushlast(p1+V);
    pts.pushlast(p1+V-H);

}
Exemple #2
0
void  ClipSeg
      (
           ActionSeg &             Act,
           ElFifo<Pt2dr> &   f,
           SegComp                 seg
      )
{
     f.set_circ(true);
     Act._events.clear();

     
     bool OrTrig = (surf_or_poly(f) >= 0);
     for (INT k=0; k<f.nb() ; k++)
     {
         Pt2dr p0 = seg.to_rep_loc(f[k]);
         Pt2dr p1 = seg.to_rep_loc(f[k+1]);

         if ((p0.y>0) != (p1.y>0))
         {
            bool entr = (p0.y>0);
            if (!OrTrig)
               entr = ! entr;
            REAL absc = p0.x-p0.y*((p1.x-p0.x)/(p1.y-p0.y))  ;  

            Act._events.add_ev(EventInterv(absc,entr));
         }
     }
     Act._intervs.init(Act._events);

     const ElFilo<Interval>  & intervs =   Act._intervs.intervs();


	 {
     for (INT k=0 ; k<intervs.nb() ; k++)
     {
         Pt2dr p0 (intervs[k]._v0,0.0);
         Pt2dr p1 (intervs[k]._v1,0.0);
         Act.action_seg
         (
              Seg2d
              (
                  seg.from_rep_loc(p0),
                  seg.from_rep_loc(p1)
              )
         );
     }
	 }
}
Exemple #3
0
void bench_dist_point_seg_droite()
/*
    On tire un segment vertical V et un point p, le calcul de d0 = D2(V,p)
    est trivial ;
   
    On tire une rotation affine r,  soit d1 la distance r(V), r(p),
    elle doit etre invariante par rotation. Ce processus donne
    des pointe te sgement quelconuq

   on verifie d1=d0
*/
{    INT f;
    for (f =0; f< 1000; f++)
    {
         ElFifo<Pt2dr> poly;
         poly.set_circ(NRrandom3() > 0.5);

         random_polyl(poly,(INT)(2+20*NRrandom3()));
         SegComp s = random_seg(true);
         SegComp::ModePrim  mode = ran_prim_seg();

         ElFifo<Pt2dr> inters;
         ElFifo<INT  > index;

         s.inter_polyline(mode,poly,index,inters);

         for (INT k=0;  k<index.nb(); k++)
         {
             INT ind = index[k];
             Pt2dr inter = inters[k];
             Pt2dr p0 = poly[ind];
             Pt2dr p1 = poly[ind+1];
             BENCH_ASSERT
             (
                   (s.square_dist(mode,inter)<epsilon)
                && (SegComp(p0,p1).square_dist_seg(inter) < epsilon)
             );
         }
         if ((mode==SegComp::droite) && poly.circ())
            BENCH_ASSERT((inters.nb()%2)==0);
    }
    
    for ( f = 0; f<10000 ; f++)
    {
         bool ok;
         SegComp::ModePrim m0 =  ran_prim_seg();
         SegComp::ModePrim m1 =  ran_prim_seg();
         SegComp s0 = random_seg(true);
         SegComp s1 = SegNotPar(s0);
         Pt2dr i = s0.inter(m0,s1,m1,ok);

         BENCH_ASSERT
         (
              (s0.square_dist_droite(i) < BIG_epsilon)
           && (s1.square_dist_droite(i) < BIG_epsilon)
         );
         if (    pt_loin_from_bande(s0,i)
              && pt_loin_from_bande(s1,i) 
            )
         {
            
            BENCH_ASSERT
            (
              ok == (        seg_prim_inside(s0,i,m0)
                          && seg_prim_inside(s1,i,m1)
                    )
            );
         }
             
    }

    for ( f = 0; f<10000 ; f++)
    {
        Pt2dr p1 = Pt2dr(0,NRrandom3()*1e3);
        Pt2dr p2 = Pt2dr(0,p1.y +10+1e3*NRrandom3());
        Pt2dr q  = Pt2dr((NRrandom3()-0.5)*1e4,(NRrandom3()-0.5)*1e4);

        SegComp::ModePrim  mode = ran_prim_seg();

        Pt2dr proj_q = Pt2dr(0,q.y);

         Pt2dr projP_q = proj_q;

        double d0 = ElSquare(q.x);

        double  dp0 = d0;
        if (proj_q.y>p2.y)
        {
            if (mode == SegComp::seg)
            {
               dp0 += ElSquare(proj_q.y-p2.y);
               projP_q.y = p2.y;
            }
        }
        else if (proj_q.y<p1.y)
        {
            if (mode != SegComp::droite)
            {
               dp0 += ElSquare(proj_q.y-p1.y);
               projP_q.y = p1.y;
            }
        }

        Pt2dr tr = Pt2dr((NRrandom3()-0.5)*1e5,(NRrandom3()-0.5)*1e5);
        REAL teta = NRrandom3() *100;
        Pt2dr  rot(cos(teta),sin(teta));
 
        p1 = tr + p1 * rot;
        p2 = tr + p2 * rot;
        q  = tr + q  * rot;
        proj_q  = tr + proj_q * rot;

        projP_q  = tr + projP_q * rot;

        SegComp s(p1,p2);
        REAL d1 = s.square_dist_droite(q);
        REAL dp1 = s.square_dist(mode,q);

        BENCH_ASSERT(std::abs(d0 -d1) < BIG_epsilon);
        BENCH_ASSERT(std::abs(dp0 -dp1) < BIG_epsilon);

        Pt2dr proj_q_2 = s.proj_ortho_droite(q);
        BENCH_ASSERT( euclid(proj_q-proj_q_2) < BIG_epsilon);


        BENCH_ASSERT(euclid(projP_q,s.proj_ortho(mode,q))<BIG_epsilon);
    }

    for ( f = 0; f<10000 ; f++)
    {
        REAL rho = 1+NRrandom3()*1e3;
        REAL teta = (NRrandom3()-0.5)*1.9999*PI;
        Pt2dr p1 = Pt2dr::FromPolar(rho,teta);
        REAL teta2 = angle(p1);
        Pt2dr p2 = Pt2dr::FromPolar(1+NRrandom3()*1e3,NRrandom3()*1e3);
        REAL teta3 = angle(p2,p1*p2);


        BENCH_ASSERT(std::abs(teta2-teta)<epsilon);
        BENCH_ASSERT(std::abs(teta3-teta)<epsilon);
        
    }

    for ( f =0; f< 2000; f++)
    {
         SegComp::ModePrim m0 =  ran_prim_seg();
         SegComp::ModePrim m1 =  ran_prim_seg();
         SegComp s0 = random_seg(true);
         SegComp s1 = SegNotPar(s0);


         Seg2d  proj = s0.proj_ortho(m0,s1,m1);

         BENCH_ASSERT
         (
             std::abs
             (
                 square_euclid(proj.p0()-proj.p1())
               -s0.square_dist(m0,s1,m1)
             ) < epsilon
         );

         BENCH_ASSERT
         (
               (s0.square_dist(m0,proj.p0())<epsilon)
            && (s1.square_dist(m1,proj.p1())<epsilon)
         );

         for (INT k=0; k< 8*(2+(INT)m0)*(2+(INT)m1) ; k++)
         {
             Pt2dr q0 = proj.p0() + s0.tangente()*((NRrandom3()-0.5) * (1<<(k%10))) ;
             Pt2dr q1 = proj.p1() + s1.tangente()*((NRrandom3()-0.5) * (1<<(k%10))) ;

             q0 = s0.proj_ortho(m0,q0);
             q1 = s1.proj_ortho(m1,q1);

             BENCH_ASSERT
             (
                 euclid(proj.p0(),proj.p1())
               < (euclid(q0,q1)+epsilon)
             );

         }
    }


    cout << "OK OK OK DIIIIIIST \n";
}