C     Last change:  T    23 Jan 100    1:46 am
*************************************************************************
C                       PROGRAMME POUR LA GENERATION                    C
C                           DU FLOCON DE VON KOCH                       C
*************************************************************************
 

C       DECLARATIONS
        real x1,x2,x3,y1,y2,y3,beta,gamma,delta
        INTEGER n

C
C              x3
C              /\
C             /  \
C            /    \
C       x1/____\x2
C
C       Rentrée des données
C
        write (*,*) 'Nombre d''iterations desire'
        read (*,*) n
        WRITE (*,*) 'Coordonnee des points du segment de base'
        write (*,*) '----------------------------------------'
        write (*,*) ' '
        write (*,*) 'Rentrez x1<x2'
        write (*,*) 'x1: '
        read (*,*) x1
        write (*,*) 'x2: '
        read (*,*) x2
        write (*,*) 'y1: '
        read (*,*) y1
        write (*,*) 'y2: '
        read (*,*) y2

C       Calcul du 3° point du triangle

        long=SQRT((x1-x2)**2+(y1-y2)**2)
        gamma=-x1+(y2**2+x2**2-x1**2-y1**2)/(2*(x2-x1))
        beta=(y2-y1)/(x2-x1)
        delta=(gamma*beta+y1)**2-(y1**2+gamma**2-(long)**2)*(b
     &eta**2+1)
        y3=((gamma*beta+y1)+SQRT(delta))/(beta**2+1)
        x3=(gamma+x1)-beta*y1

C       C'est parti pour le calcul des excroissances et l'écriture des résultats
C       dans les fichiers x.txt et y.txt

        open (1,FILE='x.txt')
        open (2,FILE='y.txt')
                call flocon(n,x2,x1,y2,y1)
                call flocon(n,x1,x3,y1,y3)
                call flocon(n,x3,x2,y3,y2)
        close (1)
        close (2)
        end

C*************************************************************************C
C FONCTION RECURSIVE POUR LA GENERATION DU FLOCON                   C
C*************************************************************************C

        recursive subroutine flocon(n,xa,xb,ya,yb)
         real xa,xb,xc,xd,xe,ya,yb,yc,yd,ye,beta,gamm
     &a,delta
         real long
        INTEGER n

C                         E
C                         /\
C                        /  \
C                       /    \
C           A_____/      \_____B
C                    C       D

                long=SQRT((xa-xb)**2+(ya-yb)**2)
                xc=xa+(xb-xa)/3
                yc=ya+(yb-ya)/3
                xd=xa+2*(xb-xa)/3
                yd=ya+2*(yb-ya)/3
                gamma=-xc+(yd**2+xd**2-xc**2-yc**2)/(2*(xd-xc))
                beta=(yd-yc)/(xd-xc)
                delta=(gamma*beta+yc)**2-(yc**2+gamma**2-(long/3)**2)*(b
     &eta**2+1)

C       test pour faire toujours une excroissance sur l'extérieur

                if (xb.gt.xa) then
                ye=((gamma*beta+yc)+SQRT(delta))/(beta**2+1)
                else
                ye=((gamma*beta+yc)-SQRT(delta))/(beta**2+1)
                END if

                xe=(gamma+xc)-beta*ye
                if (n.eq.0) then
                        write (1,*) xa
                        write (1,*) xb
                        write (2,*) ya
                        write (2,*) yb
                else
                        call flocon(n-1,xa,xc,ya,yc)
                        call flocon(n-1,xc,xe,yc,ye)
                        call flocon(n-1,xe,xd,ye,yd)
                        call flocon(n-1,xd,xb,yd,yb)
                end if

        end

BACK