Beispiel #1
0
void Convex::DelVertexDoubles(PointList *PL)
{
    PointList PP;
    Point P, L;
    Segment S;
    SegmentList SN;

    if ( PL->GetFirst(&P) )
    {
        do {
            PP.Add(P);
        } while (PL->GetNext(&P));
    };
    
    if ( PL->GetFirst(&L) )
    {
        do {
            if ( PP.GetFirst(&P) )
            {
                do {
                    S.Init(P, L); 
                    SN.Add(S);
                } while (PP.GetNext(&P));
            };  
        } while (PL->GetNext(&L));
    }; 

    if ( PL->GetFirst(&P) )
    {
        do {
            if ( SN.GetFirst(&S) )
            {
                do {
                    if (S.Into(P))
                        PL->FindAndRemoveAll(P);
                } while (SN.GetNext(&S));
            };  
        } while (PL->GetNext(&P));
    };
}
Beispiel #2
0
// добавка точки до опуклої оболонки
void Convex::AddPointToHull(FacetList* Polyhedron, PointList *listUnclaimedVertices)
{
    Facet   *pF, *pF2;
    Point   P;
    Point   DistP, DistCur;
    int     re;
    Segment S;
    SegmentList Horizont;

    Polyhedron->GetFirst(&pF);
    do {
        if ( pF->listVertices.GetFirst(&DistP))
        {
            FacetList VisibleFaces;

            // Знаходимо найбiльш вiддалену точку DistP вiд гранi pF
            DistCur = DistP;
            do {
                if ((pF->DistanceToPoint(DistP))<(pF->DistanceToPoint(DistCur)))
                    DistP.Init(DistCur);
            } while (pF->listVertices.GetNext(&DistCur));

            #ifdef CONVEX_DEBUG
                printf( "Search the furthest point to facet ");
                pF->PrintCoordinates(0);
                printf( ".  DisP= ");
                DistP.OutputPoint();
                printf( "\n");
            #endif            

            // Проходимось по всiх гранях i видимi з точки DistP додаємо до списку VisibleFaces,
            do {
                Polyhedron->GetFirst(&pF);
                re = 0;
                do {                                
                    if (pF->IsOnFacet(DistP)>eps)    
                    {
                        Facet *pF2 = new Facet;
                        *pF2 = (*pF);

                        #ifdef CONVEX_DEBUG
                            pF->PrintCoordinates(0);
                            printf( " added to list of visibles from DisP\n");
                        #endif            
                    
                        VisibleFaces.Add(pF2);
                        Polyhedron->FindAndRemoveAll( pF );
                        re = 1;
                    };                
                } while ( Polyhedron->GetNext(&pF) && !re );
            } while (re);
                    
            // обходимо всi видимi гранi i всi зовнiшнi точки з них вiдносимо до списку невикористаних
            if ( VisibleFaces.GetFirst(&pF) )
            {
                do {                                            
                    while ( pF->listVertices.Remove(&P))            
                    {
                        listUnclaimedVertices->Add( P );
                        P.OutputPoint();
                        printf( " added to list of Unclaimed points\n");
                    };

                } while ( VisibleFaces.GetNext(&pF) );
            };

            // з списку невикористаних прибираємо знайдену точку DistP
            listUnclaimedVertices->FindAndRemoveAll( DistP );

            // добавляємо в список граней новi, бічні грані конуса побудованого вiд знайденої точки до її горизонту
            FacetToSegmentsGorizon(&VisibleFaces, &Horizont);
            Horizont.GetFirst(&S);
            do {
                pF2 = new Facet;
                pF2->CreateOrientatedFace( S.A, S.B, DistP, insidePoint );
                Polyhedron->Add( pF2 );
            } while ( Horizont.GetNext(&S) );
            
            return; // одна точка (DistP) в оболонку добавлена
        };
    } while ( Polyhedron->GetNext(&pF) );

};