Example #1
0
def run():
    n = 12
    h = 5.
    A = simple.sector(1., 360., 1, n, diag='u')
    B = simple.cylinder(2., h, n, 4, diag='u').reverse()
    C = A.reverse() + B + A.trl(2, h)
    S = TriSurface(C)
    export({'surface': S})

    clear()
    smoothwire()
    view('iso')
    draw(S, color=red, bkcolor=black)
Example #2
0
def run():
    n=12
    h=5.
    A = simple.sector(1.,360.,1,n,diag='u')
    B = simple.cylinder(2.,h,n,4,diag='u').reverse()
    C = A.reverse()+B+A.trl(2,h)
    S = TriSurface(C)
    export({'surface':S})

    clear()
    smoothwire()
    view('iso')
    draw(S,color=red,bkcolor=black)
Example #3
0
def run():
    reset()
    clear()
    smooth()
    transparent()
    view('right')

    # Create some geometry
    S = sphere()
    T = sector(1.0,360.,6,36,h=1.0,diag='u').toSurface().scale(1.5).reverse()
    C = cylinder(1.2,1.5,24,4,diag='u').toSurface().trl([0.5,0.5,0.5]).reverse()

    # Draw the geometry with given colors/opacity
    # Settings colors and opacity in this way makes the model
    # directly ready to export as WebGL
    S.color = red
    S.alpha = 0.7
    S.caption = 'A sphere'
    S.control = ['visible','opacity','color']
    S.setNormals('avg')

    T.color = blue
    T.caption = 'A cone'
    T.alpha = 1.0
    T.control = ['visible','opacity','color']
    #S.setNormals('auto')

    C.color = 'yellow'
    C.caption = 'A cylinder'
    C.alpha = 0.8
    C.control = ['visible','opacity','color']
    #S.setNormals('auto')

    export({'sphere':S,'cone':T,'cylinder':C})

    draw([S,T,C])
    zoomAll()
    rotRight(30.)

    camera = pf.canvas.camera
    print("Camera focus: %s; eye: %s" % (camera.focus, camera.eye))

    if checkWorkdir():
        # Export everything to webgl
        W = WebGL()
        W.addScene()
        W.export('Scene1','Two spheres and a cone',createdby=True)
Example #4
0
def run():
    global F, G
    clear()
    smooth()
    view('iso')
    F = cylinder(L=8., D=2., nt=36, nl=20, diag='u').centered()
    F = TriSurface(F).setProp(3).close(method='planar').fixNormals()
    G = F.rotate(90., 0).trl(0, 1.).setProp(1)
    export({'F': F, 'G': G})
    draw([F, G])

    res = askItems([
        _I('op',
           text='Operation',
           choices=[
               '+ (Union)',
               '- (Difference)',
               '* Intersection',
               'Intersection Curve',
           ],
           itemtype='vradio'),
        _I('verbose', False, text='Show stats'),
    ])

    if not res:
        return
    op = res['op'][0]
    verbose = res['verbose']
    if op in '+-*':
        I = F.boolean(G, op, verbose=verbose)
    else:
        I = F.intersection(G, verbose=verbose)
    clear()
    draw(I)

    if op in '+-*':
        return

    else:
        if ack('Create a surface inside the curve ?'):
            I = I.toMesh()
            e = connectedLineElems(I.elems)
            I = Mesh(I.coords, connectedLineElems(I.elems)[0])
            clear()
            draw(I, color=red, linewidth=3)
            S = fillBorder(I, method='planar')
            draw(S)
def createCylinder():
    res = askItems([I('name','__auto__'),
                    I('base diameter',1.),
                    I('top diameter',1.),
                    I('height',1.),
                    I('angle',360.),
                    I('div_along_length',6),
                    I('div_along_circ',12),
                    I('bias',0.),
                    I('diagonals',choices=['up','down']),
                    ])
    if res:
        name = res['name']
        F = simple.cylinder(L=res['height'],D=res['base diameter'],D1=res['top diameter'],angle=res['angle'],nt=res['div_along_circ'],nl=res['div_along_length'],bias=res['bias'],diag=res['diagonals'][0])
        export({name:TriSurface(F)})
        selection.set([name])
        selection.draw()
Example #6
0
def run():
    global F,G
    clear()
    smooth()
    view('iso')
    F = cylinder(L=8.,D=2.,nt=36,nl=20,diag='u').centered()
    F = TriSurface(F).setProp(3).close(method='planar').fixNormals()
    G = F.rotate(90.,0).trl(0,1.).setProp(1)
    export({'F':F,'G':G})
    draw([F,G])

    res = askItems(
        [ _I('op',text='Operation',choices=[
            '+ (Union)',
            '- (Difference)',
            '* Intersection',
            'Intersection Curve',
            ],itemtype='vradio'),
          _I('verbose',False,text='Show stats'),
        ])
    
    if not res:
        return
    op = res['op'][0]
    verbose = res['verbose']
    if op in '+-*':
        I = F.boolean(G,op,verbose=verbose)
    else:
        I = F.intersection(G,verbose=verbose)
    clear()
    draw(I)

    if op in '+-*':
        return

    else:
        if ack('Create a surface inside the curve ?'):
            I = I.toMesh()
            e = connectedLineElems(I.elems)
            I = Mesh(I.coords,connectedLineElems(I.elems)[0])
            clear()
            draw(I,color=red,linewidth=3)
            S = fillBorder(I,method='planar')
            draw(S)
def createCylinder():
    _data_ = __name__+'_createCylinder_data'
    res = {
        'name':'__auto__',
        'object type':'Formex',
        'base diameter':1.,
        'top diameter':1.,
        'height':2.,
        'angle':360.,
        'div_along_length':6,
        'div_along_circ':12,
        'bias':0.,
        'diagonals':'up',
        }
    if pf.PF.has_key(_data_):
        res.update(pf.PF[_data_])
    res = askItems(store=res, items=[
        _I('name'),
        _I('object type',choices=['Formex','Mesh','TriSurface']),
        _I('base diameter'),
        _I('top diameter'),
        _I('height'),
        _I('angle'),
        _I('div_along_length'),
        _I('div_along_circ'),
        _I('bias'),
        _I('diagonals',choices=['none','up','down']),
        ])

    if res:
        pf.PF[_data_] = res
        name = res['name']
        if name == '__auto__':
            name = autoName(res['object type']).next()

        F = simple.cylinder(L=res['height'],D=res['base diameter'],D1=res['top diameter'],
                            angle=res['angle'],nt=res['div_along_circ'],nl=res['div_along_length'],
                            bias=res['bias'],diag=res['diagonals'][0])

        F = convertFormex(F,res['object type'])
        export({name:F})
        selection.set([name])
        selection.draw()
Example #8
0
def createCylinder():
    _data_ = _name_ + 'createCylinder_data'
    dia = Dialog(items=[
        _I('name', '__auto__'),
        _I('object type', choices=['Formex', 'Mesh', 'TriSurface']),
        _I('base diameter', 1.),
        _I('top diameter', 1.),
        _I('height', 2.),
        _I('angle', 360.),
        _I('div_along_length', 6),
        _I('div_along_circ', 12),
        _I('bias', 0.),
        _I('diag', 'up', choices=['none', 'up', 'down', 'x-both']),
    ], )
    if _data_ in pf.PF:
        dia.updateData(pf.PF[_data_])
    res = dia.getResults()
    if res:
        pf.PF[_data_] = res
        name = res['name']
        if name == '__auto__':
            name = autoName(res['object type']).next()

        F = simple.cylinder(L=res['height'],
                            D=res['base diameter'],
                            D1=res['top diameter'],
                            angle=res['angle'],
                            nt=res['div_along_circ'],
                            nl=res['div_along_length'],
                            bias=res['bias'],
                            diag=res['diag'][0])

        F = convertFormex(F, res['object type'])
        export({name: F})
        selection.set([name])
        if res['object type'] == 'TriSurface':
            surface_menu.selection.set([name])
        selection.draw()
"""Cylinder

level = 'beginner'
topics = ['geometry', 'surface', 'cylinder']
techniques = ['import']

.. Description

Cylinder
--------
This example illustrates the use of simple.sector() and simple.cylinder()
to create a parametric cylindrical surface.

"""
import simple
from plugins.trisurface import TriSurface

n=12
h=5.
A = simple.sector(1.,360.,1,n,diag='u')
B = simple.cylinder(2.,h,n,4,diag='u').reverse()
C = A.reverse()+B+A.trl(2,h)
S = TriSurface(C)
export({'surface':S})

smoothwire()
view('iso')
draw(S,color=red)

# End