2 Antworten

Schnurstracks:

void sierpinski ( double ax, double ay
                , double bx, double by
                , double cx, double cy
                , double epsilon )
{
    if ( bx-ax < epsilon && by-ay < epsilon )
    {
        draw_line(ax,ay, bx,by);
        draw_line(bx,by, cx,cy);
        draw_line(cx,cy, ax,ay);
    }
    else
    {
        double abx=(ax+bx)/2, aby=(ay+by)/2;
        double bcx=(bx+cx)/2, bcy=(by+cy)/2;
        double acx=(ax+cx)/2, acy=(ay+cy)/2;

        sierpinsky( ax,ay, abx,aby, acx,acy, epsilon );
        sierpinsky( abx,aby, bx,by, bcx,bcy, epsilon );
        sierpinsky( acx,acy, bcx,bcy, cx,cy, epsilon );
    }
}

Wenn das Dreieck gleichseitig mit waagrechter Grundfläche ist, reichen drei Koordinaten als Parameter aus. Die übrigen drei können daraus berechnet werden:

void sierpinski ( double ax, double ay, double bx, double epsilon )
{
    double by=ay, cx=(ax+bx)/2, cy=ay+(bx-ax)*sqrt(.75);
    ...
}

ralphdieter  01.01.2020, 17:07
sierpinsk y( ... )

und das gleich dreimal! Wie peimlich ;-)

0
Alexx1002 
Beitragsersteller
 01.01.2020, 15:29

Oha voll gut, dankeschön :)

0

Eine einfache Rekursion, für die eine geeignete Vorschrift gefunden werden muß.

Alternativ kann man es auch über ein Lindemayersystem mit Stringexpansion(-ersetzung) machen.