


***Name: "Spindel mit Fllstben"	! Must be defined railing type name
***Code: 10002								! Must be defined identification code
                                            ! It must be also the subroutine label in GDL section

!Notes:

!B Bool       [] both option available [0] only 0 available [1] only 1 available
!I Integer    [0,15] value range 0=<p=<15, [] means unlimited value range [0] means param. not available
!D Double     [0.32,99] value range [] means unlimited value range [0] means param. not available
!M Material   [0] means param. not available
!P Pen        [0] means param. not available
!F Fill       [0] means param. not available
!T Text       [0] means param. not available
!S Font type  [0] means param. not available

***STD***         ! Must be defined standard parameters section delimiter.
                  ! Section may be empty, but parameter names and types not able to change

RailingOffset:     D [-1.0,1.0]=0.04 ! railing offset to edge of stair value: positive value means inside
RailingUpPos:      D [0.3, 10.0]=0.9   ! railing top position above step level
RailingDnPos:      D [0.0, 10.0]=0.1     ! railing bottom position above step level
ColumnOffset:      D [-0.8,0.8]=0    ! column offset to railing line value: positive value means inside
ColumnOffsetUp:    D [0,0.5]=0       ! column horizontal overhang up
ColumnOffsetDn:    D [0,0.5]=0       ! column horizontal overhang down
FirstColumnOffset: D [0,3]=0.1       ! first column offset along the railing
CnPlacementType:   I [1,3]=1         ! no Column, closest to, on every Tread, pieces: 0,1,2,3
ClosestToDistance: D [0.02,3.2]=0.80  ! distance of columns to each other
SnapToCorners:     B [0,1]=1            ! 1=columns  at segment ends

***ADD***         ! Must be defined additional parameters section delimiter (section may be empty)

res:"Hohe Aufl.gen" B [0,1]=0
r1:"Sttzenradius" D [0.01,0.1]=0.025        ! radius of column
cyl:"Zylindr. Stangen" B [0,1]=1        ! cylindric pieces
r2:"Vert.Stangenradi" D [0.01,0.1]=0.0075   ! radius of vertical tubes
wh:"Abst.v.Stangen" D [0.1,1]=0.1             ! width of holes of vertical pieces
mat_r:"Gelndermat." M []=10     ! railing material
mat_c:"Trep.krpermat." M []=47      ! column material


***GDL***         ! Must be defined section delimiter for railing GDL subroutine



!================================================ GDL OF RAILING
!================================================================


10002:                          ! railing code

if res =0 then resol 8 else resol 36

wr=4*r1      		      	! width of rail section
hr=0.66*wr         		! height of rail section
wl=1.2*r1            		! width of longitudinal tube
hl=wl*0.5		        ! height of rail section
wp=2*r2		  		! vertical piece width (if rectangular)
dp=wp				! vertical piece depth
mat_f=mat_c			! field tube material





dist=wh+2*r2           ! distance between vertical pieces axises


IF current_side=0 then


    !********************************* left side railing
    !***************************************************
voct=segm_l[current_segment][8]             ! vertical oversize of columns at the top
vocb=segm_l[current_segment][9]             ! vertical oversize of columns at the bottom





    !************************** railing

    h1=segm_l[current_segment][12]             ! height of railing
    h2=segm_l[current_segment][11]             ! height of bottom tube axis
    h3=h1-0.12

    nr=segm_l[current_segment][2]   !number of railing coordinates
    n=segm_l[current_segment][6]    !number of columns

    fqw1=segm_l[current_segment][3]  !first point index of current segment
    fqwn=segm_l[current_segment][3]+segm_l[current_segment][2]-1  !last point index of current segment



    !********************* rail

    material mat_r

    !plus one point for tube direction at the beginning & in the end

    x1=rail_l [fqw1][1]-(rail_l [fqw1+1][1]-rail_l [fqw1][1])
    y1=rail_l [fqw1][2]-(rail_l [fqw1+1][2]-rail_l [fqw1][2])
    z1=rail_l [fqw1][3]-(rail_l [fqw1+1][3]-rail_l [fqw1][3])

    xn=rail_l [fqwn][1]+(rail_l [fqwn][1]-rail_l [fqwn-1][1])
    yn=rail_l [fqwn][2]+(rail_l [fqwn][2]-rail_l [fqwn-1][2])
    zn=rail_l [fqwn][3]+(rail_l [fqwn][3]-rail_l [fqwn-1][3])


    ff=wr/0.08       ! railing section resizing factors
    fff=hr/0.035


    for i=fqw1 to fqwn
        put rail_l [i][1], rail_l [i][2], rail_l [i][3], 0
    next i


    tube 22, nr+2, 1+2+16+32,
        0.0,            -0.015625*fff,     1,
       -0.031225*ff,    -0.015625*fff,     1,
       -0.035491*ff,    -0.011532*fff,     1,
       -0.038878*ff,    -0.00588*fff,      1,
       -0.04*ff,         0.0,              1,
       -0.038878*ff,     0.00588*fff,      1,
       -0.035491*ff,     0.011532*fff,     1,
       -0.031225*ff,     0.015625*fff,     1,
       -0.022446*ff,     0.017761*fff,     1,
       -0.013524*ff,     0.019192*fff,     1,
       -0.004518*ff,     0.01991*fff,      1,
        0.004518*ff,     0.01991*fff,      1,
        0.013524*ff,     0.019192*fff,     1,
        0.022446*ff,     0.017761*fff,     1,
        0.031225*ff,     0.015625*fff,     1,
        0.035491*ff,     0.011532*fff,     1,
        0.038878*ff,     0.00588*fff,      1,
        0.04*ff,         0.0,              1,
        0.038878*ff,    -0.00588*fff,      1,
        0.035491*ff,    -0.011532*fff,     1,
        0.031225*ff,    -0.015625*fff,     1,
        0.0,            -0.015625*fff,     1,

        x1, y1, z1, 0,
        get (nsp),
        xn, yn, zn, 0



    !*********************** columns

    material mat_c

    for i=segm_l[current_segment][7] to segm_l[current_segment][7]+n-1

        c1=column_l[i][4]                       ! column point index

        hc1=rail_l[c1][3]-column_l[i][3]+voct+vocb   ! height of column

        addx column_l[i][1]
        addy column_l[i][2]
        addz column_l[i][3]-vocb

        cylind hc1, r1


        del 3

    next i



    !*********************** longitudinal tubes

    material mat_f

        if n<2 then

            c1=fqw1                   ! first rail point from railing coordinates
            c2=fqwn                  ! last rail point from railing coordinates

            for kk=1 to 2

                for i=c1 to c2
                    put rail_l [i][1], rail_l [i][2], rail_l [i][3]-h1+h2, 0
                next i

                tube 5, c2-c1+1+2, 0,
                    -wl/2, -hl/2, 1,
                    -wl/2,  hl/2, 1,
                     wl/2,  hl/2, 1,
                     wl/2, -hl/2, 1,
                    -wl/2, -hl/2, 1,

                    x1, y1, z1, 0,
                    get (nsp),
                    xn, yn, zn, 0

                 addz h3-h2

            next kk

            del 2

        else

            xvxv=segm_l[current_segment][7]
            xvxvx=segm_l[current_segment][7]+n-1

            c1=column_l[xvxv][4]   ! first column point from railing coordinates
            c2=column_l[xvxvx][4]  ! last column point from railing coordinates

            for kk=1 to 2

                for i=c1 to c2
                    put rail_l [i][1], rail_l [i][2], rail_l [i][3]-h1+h2, 0
                next i

                tube 5, c2-c1+1+2, 0,
                    -wl/2, -hl/2, 1,
                    -wl/2,  hl/2, 1,
                     wl/2,  hl/2, 1,
                     wl/2, -hl/2, 1,
                    -wl/2, -hl/2, 1,

                    rail_l[c1][1]-(rail_l[c1+1][1]-rail_l[c1][1]), rail_l[c1][2]-(rail_l[c1+1][2]-rail_l[c1][2]), rail_l[c1][3]-(rail_l[c1+1][3]-rail_l[c1][3]), 0,
                    get (nsp),
                    rail_l[c2][1]+(rail_l[c2][1]-rail_l[c2-1][1]), rail_l[c2][2]+(rail_l[c2][2]-rail_l[c2-1][2]), rail_l[c2][3]+(rail_l[c2][3]-rail_l[c2-1][3]), 0

                 addz h3-h2

            next kk

            del 2

        endif




    !*********************** vertical pieces


    for j=segm_l[current_segment][7] to segm_l[current_segment][7]+n-2

    if n=1 then goto 1000210    !only one column in the segment

        c11=column_l[j][4]   ! first column point from railing coordinates
        c21=column_l[j+1][4]   ! next column index

        qq=0
        xx00=0
        ds=0

        for ii=c11 to c21-1

            x1=(rail_l[ii+1][1]-rail_l[ii][1])
            y1=(rail_l[ii+1][2]-rail_l[ii][2])

            d1=sqr(x1^2+y1^2)
            ds=ds+d1              ! distance between two column axises

        next ii

        ds=ds-r1*2+2*r2                      ! effective distance
        if ds=0 then goto 1000210
        nx=int(ds/dist)                      ! number of holes
        if nx+1-(ds/dist)<0.5 then nx=nx+1   ! "closest to"
        if nx=0 then goto 1000210
        dve=ds/nx                            ! real distance of vertical elements
        nve=nx-1                             ! number of vertical elements

        if nve<1 then goto 1000210

        dx1=(rail_l[c11+1][1]-rail_l[c11][1])
        dy1=(rail_l[c11+1][2]-rail_l[c11][2])
        dz1=(rail_l[c11+1][3]-rail_l[c11][3])

        ddd=sqr(dx1^2+dy1^2)   ! distance until point next to column
        aaz1=atn(dz1/(ddd+0.00001))      ! angle of vertical displacement

        if dx1=0 then
            if dy1>0 then
                a1=90
            else
                a1=270
            endif
        else
            if dx1>0 then
                if dy1>0 then
                    a1=atn(dy1/dx1)
                else
                    a1=360+atn(dy1/dx1)
                endif
            else
                a1=180+atn(dy1/dx1)
            endif
        endif


        addx rail_l[c11][1]
        addy rail_l[c11][2]
        addz rail_l[c11][3]-h1+h2


        if ddd<r1 then

            rotz a1
            addx ddd
            xx00=dve-ddd
            goto 1000299

        endif


        rotz a1
        addx r1-r2                       ! place of the 0th (virtual) piece
        addz (r1-r2)*tan(aaz1)

        1000211:
        addx dve
        addz dve*tan(aaz1)
        qq=qq+1

        if  dve*qq<=ddd-(r1-r2) then
            gosub 1000220
            goto 1000211
        else
            xx00=dve*qq+r1-r2-ddd
            addx -xx00
            addz -xx00*tan(aaz1)
        endif

        1000299:

        if c11+1=c21 then goto 1000210


        for ii=c11+1 to c21-2              ! between two columns

            qqq=0

            dx1=(rail_l[ii][1]-rail_l[ii-1][1])
            dy1=(rail_l[ii][2]-rail_l[ii-1][2])

            dx2=(rail_l[ii+1][1]-rail_l[ii][1])
            dy2=(rail_l[ii+1][2]-rail_l[ii][2])
            dz2=(rail_l[ii+1][3]-rail_l[ii][3])

            ddd=sqr(dx2^2+dy2^2)          ! distance between two subsegments
            aaz2=atn(dz2/(ddd+0.00001))


            if dx1=0 then
                if dy1>0 then
                    a1=90
                else
                    a1=270
                endif
            else
                if dx1>0 then
                    if dy1>0 then
                        a1=atn(dy1/dx1)
                    else
                        a1=360+atn(dy1/dx1)
                    endif
                else
                    a1=180+atn(dy1/dx1)
                endif
            endif


            if dx2=0 then
                if dy2>0 then
                    a2=90
                else
                    a2=270
                endif
            else
                if dx2>0 then
                    if dy2>0 then
                        a2=atn(dy2/dx2)
                    else
                        a2=360+atn(dy2/dx2)
                    endif
                else
                    a2=180+atn(dy2/dx2)
                endif
            endif


            if a2>a1 then
                aa=a2-a1
            else
                aa=360+a2-a1
            endif


            rotz aa

            if xx00<=ddd then
                addx xx00
                addz xx00*tan(aaz2)
                gosub 1000220

                1000212:
                addx dve
                addz dve*tan(aaz2)
                qqq=qqq+1

                if xx00+qqq*dve<=ddd then
                    gosub 1000220
                    goto 1000212
                else
                    xx00=dve*qqq+xx00-ddd
                    addx -xx00
                    addz -xx00*tan(aaz2)
                endif
            else
                 xx00=xx00-ddd
                 addx ddd
                 addz ddd*tan(aaz2)
            endif

        next ii


        qqqq=0

        dx1=(rail_l[c21-1][1]-rail_l[c21-2][1])
        dy1=(rail_l[c21-1][2]-rail_l[c21-2][2])

        dx2=(rail_l[c21][1]-rail_l[c21-1][1])
        dy2=(rail_l[c21][2]-rail_l[c21-1][2])
        dz2=(rail_l[c21][3]-rail_l[c21-1][3])

        ddd=sqr(dx2^2+dy2^2)          ! distance between two subsegments
        aaz2=atn(dz2/(ddd+0.00001))

        if ddd<r1 then goto 1000210

        if dx1=0 then
            if dy1>0 then
                a1=90
            else
                a1=270
            endif
        else
            if dx1>0 then
                if dy1>0 then
                    a1=atn(dy1/dx1)
                else
                    a1=360+atn(dy1/dx1)
                endif
            else
                a1=180+atn(dy1/dx1)
            endif
        endif


        if dx2=0 then
            if dy2>0 then
                a2=90
            else
                a2=270
            endif
        else
            if dx2>0 then
                if dy2>0 then
                    a2=atn(dy2/dx2)
                else
                    a2=360+atn(dy2/dx2)
                endif
            else
                a2=180+atn(dy2/dx2)
            endif
        endif


        if a2>a1 then
            aa=a2-a1
        else
            aa=360+a2-a1
        endif


        rotz aa


        if xx00<ddd-r1 then
            addx xx00
            addz xx00*tan(aaz2)
            gosub 1000220

            1000222:
            addx dve
            addz dve*tan(aaz2)
            qqqq=qqqq+1

            if xx00+qqqq*dve<ddd-r1 then
                gosub 1000220
                goto 1000222
            endif
        endif


        1000210:

        del top


    next j


ELSE


    !********************************* right side railing
    !***************************************************

voct=segm_r[current_segment][8]             ! vertical oversize of columns at the top
vocb=segm_r[current_segment][9]             ! vertical oversize of columns at the bottom



     !************************** railing

    h1=segm_r[current_segment][12]             ! height of railing
    h2=segm_r[current_segment][11]             ! height of bottom tube axis
    h3=h1-0.12

    nr=segm_r[current_segment][2]   !number of railing coordinates
    n=segm_r[current_segment][6]    !number of columns

    fqw1=segm_r[current_segment][3]  !first point index of current segment
    fqwn=segm_r[current_segment][3]+segm_r[current_segment][2]-1  !last point index of current segment



    !********************* rail

    material mat_r

    !plus one point for tube direction at the beginning & in the end

    x1=rail_r [fqw1][1]-(rail_r [fqw1+1][1]-rail_r [fqw1][1])
    y1=rail_r [fqw1][2]-(rail_r [fqw1+1][2]-rail_r [fqw1][2])
    z1=rail_r [fqw1][3]-(rail_r [fqw1+1][3]-rail_r [fqw1][3])

    xn=rail_r [fqwn][1]+(rail_r [fqwn][1]-rail_r [fqwn-1][1])
    yn=rail_r [fqwn][2]+(rail_r [fqwn][2]-rail_r [fqwn-1][2])
    zn=rail_r [fqwn][3]+(rail_r [fqwn][3]-rail_r [fqwn-1][3])


    ff=wr/0.08       ! railing section resizing factors
    fff=hr/0.035


    for i=fqw1 to fqwn
        put rail_r [i][1], rail_r [i][2], rail_r [i][3], 0
    next i


    tube 22, nr+2, 1+2+16+32,
        0.0,            -0.015625*fff,     1,
       -0.031225*ff,    -0.015625*fff,     1,
       -0.035491*ff,    -0.011532*fff,     1,
       -0.038878*ff,    -0.00588*fff,      1,
       -0.04*ff,         0.0,              1,
       -0.038878*ff,     0.00588*fff,      1,
       -0.035491*ff,     0.011532*fff,     1,
       -0.031225*ff,     0.015625*fff,     1,
       -0.022446*ff,     0.017761*fff,     1,
       -0.013524*ff,     0.019192*fff,     1,
       -0.004518*ff,     0.01991*fff,      1,
        0.004518*ff,     0.01991*fff,      1,
        0.013524*ff,     0.019192*fff,     1,
        0.022446*ff,     0.017761*fff,     1,
        0.031225*ff,     0.015625*fff,     1,
        0.035491*ff,     0.011532*fff,     1,
        0.038878*ff,     0.00588*fff,      1,
        0.04*ff,         0.0,              1,
        0.038878*ff,    -0.00588*fff,      1,
        0.035491*ff,    -0.011532*fff,     1,
        0.031225*ff,    -0.015625*fff,     1,
        0.0,            -0.015625*fff,     1,

        x1, y1, z1, 0,
        get (nsp),
        xn, yn, zn, 0



    !*********************** columns

    material mat_c

    for i=segm_r[current_segment][7] to segm_r[current_segment][7]+n-1

        c1=column_r[i][4]                       ! column point index

        hc1=rail_r[c1][3]-column_r[i][3]+voct+vocb   ! height of column

        addx column_r[i][1]
        addy column_r[i][2]
        addz column_r[i][3]-vocb

        cylind hc1, r1


        del 3

    next i



    !*********************** longitudinal tubes

    material mat_f


    if n<2 then

        c1=fqw1                   ! first rail point from railing coordinates
        c2=fqwn                  ! last rail point from railing coordinates

            for kk=1 to 2

                for i=c1 to c2
                    put rail_r [i][1], rail_r [i][2], rail_r [i][3]-h1+h2, 0
                next i

                tube 5, c2-c1+1+2, 0,
                    -wl/2, -hl/2, 1,
                    -wl/2,  hl/2, 1,
                     wl/2,  hl/2, 1,
                     wl/2, -hl/2, 1,
                    -wl/2, -hl/2, 1,

                    x1, y1, z1, 0,
                    get (nsp),
                    xn, yn, zn, 0

                 addz h3-h2

            next kk

            del 2

    else

        xvxv=segm_r[current_segment][7]
        xvxvx=segm_r[current_segment][7]+n-1

        c1=column_r[xvxv][4]   ! first column point from railing coordinates
        c2=column_r[xvxvx][4]  ! last column point from railing coordinates

        for kk=1 to 2

            for i=c1 to c2
                put rail_r [i][1], rail_r [i][2], rail_r [i][3]-h1+h2, 0
            next i

            tube 5, c2-c1+1+2, 0,
                -wl/2, -hl/2, 1,
                -wl/2,  hl/2, 1,
                 wl/2,  hl/2, 1,
                 wl/2, -hl/2, 1,
                -wl/2, -hl/2, 1,

                rail_r[c1][1]-(rail_r[c1+1][1]-rail_r[c1][1]), rail_r[c1][2]-(rail_r[c1+1][2]-rail_r[c1][2]), rail_r[c1][3]-(rail_r[c1+1][3]-rail_r[c1][3]), 0,
                get (nsp),
                rail_r[c2][1]+(rail_r[c2][1]-rail_r[c2-1][1]), rail_r[c2][2]+(rail_r[c2][2]-rail_r[c2-1][2]), rail_r[c2][3]+(rail_r[c2][3]-rail_r[c2-1][3]), 0

             addz h3-h2

        next kk

        del 2

    endif




    !*********************** vertical pieces

    for j=segm_r[current_segment][7] to segm_r[current_segment][7]+n-2

    if n=1 then goto 1000230    !only one column in the segment

        c11=column_r[j][4]     ! first column index
        c21=column_r[j+1][4]   ! next column index

        qq=0
        xx00=0
        ds=0

        for ii=c11 to c21-1

            x1=(rail_r[ii+1][1]-rail_r[ii][1])
            y1=(rail_r[ii+1][2]-rail_r[ii][2])

            d1=sqr(x1^2+y1^2)
            ds=ds+d1              ! distance between two column axises

        next ii

        ds=ds-r1*2+2*r2                      ! effective distance
        if ds=0 then goto 1000230
        nx=int(ds/dist)                      ! number of holes
        if nx+1-(ds/dist)<0.5 then nx=nx+1   ! "closest to"
        if nx=0 then goto 1000230
        dve=ds/nx                            ! real distance of vertical elements
        nve=nx-1                             ! number of vertical elements

        if nve<1 then goto 1000230

        dx1=(rail_r[c11+1][1]-rail_r[c11][1])
        dy1=(rail_r[c11+1][2]-rail_r[c11][2])
        dz1=(rail_r[c11+1][3]-rail_r[c11][3])

        ddd=sqr(dx1^2+dy1^2)   ! distance until point next to column
        aaz1=atn(dz1/(ddd+0.00001))      ! angle of vertical displacement

        if dx1=0 then
            if dy1>0 then
                a1=90
            else
                a1=270
            endif
        else
            if dx1>0 then
                if dy1>0 then
                    a1=atn(dy1/dx1)
                else
                    a1=360+atn(dy1/dx1)
                endif
            else
                a1=180+atn(dy1/dx1)
            endif
        endif


        addx rail_r[c11][1]
        addy rail_r[c11][2]
        addz rail_r[c11][3]-h1+h2


        if ddd<r1 then

            rotz a1
            addx ddd
            xx00=dve-ddd
            goto 1000298

        endif


        rotz a1
        addx r1-r2                       ! place of the 0th (virtual) piece
        addz (r1-r2)*tan(aaz1)

        1000231:
        addx dve
        addz dve*tan(aaz1)
        qq=qq+1

        if  dve*qq<=ddd-(r1-r2) then
            gosub 1000220
            goto 1000231
        else
            xx00=dve*qq+r1-r2-ddd
            addx -xx00
            addz -xx00*tan(aaz1)
        endif

        1000298:

        if c11+1=c21 then goto 1000230


        for ii=c11+1 to c21-2              ! between two columns

            qqq=0

            dx1=(rail_r[ii][1]-rail_r[ii-1][1])
            dy1=(rail_r[ii][2]-rail_r[ii-1][2])

            dx2=(rail_r[ii+1][1]-rail_r[ii][1])
            dy2=(rail_r[ii+1][2]-rail_r[ii][2])
            dz2=(rail_r[ii+1][3]-rail_r[ii][3])

            ddd=sqr(dx2^2+dy2^2)          ! distance between two subsegments
            aaz2=atn(dz2/(ddd+0.00001))


            if dx1=0 then
                if dy1>0 then
                    a1=90
                else
                    a1=270
                endif
            else
                if dx1>0 then
                    if dy1>0 then
                        a1=atn(dy1/dx1)
                    else
                        a1=360+atn(dy1/dx1)
                    endif
                else
                    a1=180+atn(dy1/dx1)
                endif
            endif


            if dx2=0 then
                if dy2>0 then
                    a2=90
                else
                    a2=270
                endif
            else
                if dx2>0 then
                    if dy2>0 then
                        a2=atn(dy2/dx2)
                    else
                        a2=360+atn(dy2/dx2)
                    endif
                else
                    a2=180+atn(dy2/dx2)
                endif
            endif


            if a2>a1 then
                aa=a2-a1
            else
                aa=360+a2-a1
            endif


            rotz aa

            if xx00<=ddd then
                addx xx00
                addz xx00*tan(aaz2)
                gosub 1000220

                1000232:
                addx dve
                addz dve*tan(aaz2)
                qqq=qqq+1

                if xx00+qqq*dve<=ddd then
                    gosub 1000220
                    goto 1000232
                else
                    xx00=dve*qqq+xx00-ddd
                    addx -xx00
                    addz -xx00*tan(aaz2)
                endif
            else
                 xx00=xx00-ddd
                 addx ddd
                 addz ddd*tan(aaz2)
            endif

        next ii



        qqqq=0

        dx1=(rail_r[c21-1][1]-rail_r[c21-2][1])
        dy1=(rail_r[c21-1][2]-rail_r[c21-2][2])

        dx2=(rail_r[c21][1]-rail_r[c21-1][1])
        dy2=(rail_r[c21][2]-rail_r[c21-1][2])
        dz2=(rail_r[c21][3]-rail_r[c21-1][3])

        ddd=sqr(dx2^2+dy2^2)          ! distance between two subsegments
        aaz2=atn(dz2/(ddd+0.00001))

        if ddd<r1 then goto 1000230

        if dx1=0 then
            if dy1>0 then
                a1=90
            else
                a1=270
            endif
        else
            if dx1>0 then
                if dy1>0 then
                    a1=atn(dy1/dx1)
                else
                    a1=360+atn(dy1/dx1)
                endif
            else
                a1=180+atn(dy1/dx1)
            endif
        endif


        if dx2=0 then
            if dy2>0 then
                a2=90
            else
                a2=270
            endif
        else
            if dx2>0 then
                if dy2>0 then
                    a2=atn(dy2/dx2)
                else
                    a2=360+atn(dy2/dx2)
                endif
            else
                a2=180+atn(dy2/dx2)
            endif
        endif


        if a2>a1 then
            aa=a2-a1
        else
            aa=360+a2-a1
        endif


        rotz aa


        if xx00<ddd-r1 then
            addx xx00
            addz xx00*tan(aaz2)
            gosub 1000220

            1000242:
            addx dve
            addz dve*tan(aaz2)
            qqqq=qqqq+1

            if xx00+qqqq*dve<ddd-r1 then
                gosub 1000220
                goto 1000242
            endif
        endif


        1000230:

        del top


    next j



ENDIF


goto 1000288


!******** vertical pieces


1000220:

if cyl=1 then

    cylind h3-h2, r2

else

    prism 4, h3-h2,
        -wp/2, -dp/2,
        -wp/2,  dp/2,
         wp/2,  dp/2,
         wp/2, -dp/2

endif


return


1000288:


del top


RETURN
