Ejemplo n.º 1
0
def drawnObject(points, mode='point'):
    """Return the geometric object resulting from draw2D points"""
    minor = None
    if '_' in mode:
        mode, minor = mode.split('_')
    closed = minor == 'closed'

    if mode == 'point':
        return points
    elif mode == 'polyline':
        if points.ncoords() < 2:
            return None
        closed = obj_params.get('closed', None)
        return PolyLine(points, closed=closed)
    elif mode == 'curve' and points.ncoords() > 1:
        curl = obj_params.get('curl', None)
        closed = obj_params.get('closed', None)
        return BezierSpline(points, curl=curl, closed=closed)
    elif mode == 'nurbs':
        degree = obj_params.get('degree', None)
        if points.ncoords() <= degree:
            return None
        closed = obj_params.get('closed', None)
        return NurbsCurve(points, degree=degree, closed=closed)
    elif mode == 'circle' and points.ncoords() % 3 == 0:
        R, C, N = triangleCircumCircle(points.reshape(-1, 3, 3))
        circles = [circle(r=r, c=c, n=n) for r, c, n in zip(R, C, N)]
        if len(circles) == 1:
            return circles[0]
        else:
            return circles
    else:
        return None
Ejemplo n.º 2
0
def drawnObject(points,mode='point'):
    """Return the geometric object resulting from draw2D points"""
    minor = None
    if '_' in mode:
        mode,minor = mode.split('_')
    closed = minor=='closed'
    
    if mode == 'point':
        return points
    elif mode == 'polyline':
        return PolyLine(points,closed=closed)
    elif mode == 'curve' and points.ncoords() > 1:
        curl = obj_params.get('curl',None)
        closed = obj_params.get('closed',None)
        return BezierSpline(points,curl=curl,closed=closed)
    elif mode == 'nurbs':
        degree = obj_params.get('degree',None)
        if points.ncoords() <= degree:
            return None
        closed = obj_params.get('closed',None)
        return NurbsCurve(points,degree=degree,closed=closed)
    elif mode == 'circle' and points.ncoords() % 3 == 0:
        R,C,N = triangleCircumCircle(points.reshape(-1,3,3))
        circles = [circle(r=r,c=c,n=n) for r,c,n in zip(R,C,N)]
        if len(circles) == 1:
            return circles[0]
        else:
            return circles
    else:
        return None
Ejemplo n.º 3
0
def askCurve():
    default = "Angle"
    res = askItems([("curve_type", default, "radio", ["Circle", "Angle"]), ("closed", False), ("circle_npts", 6)])

    if not res:
        exit()

    clear()
    globals().update(res)

    if curve_type == "Circle":
        circle = simple.circle(a1=360.0 / circle_npts)
        draw(circle, color="magenta")
        pts = circle[:, 0]

    elif curve_type == "Angle":
        F = Formex(simple.pattern("41"))
        draw(F, color="magenta")
        pts = F.coords.reshape(-1, 3)

    clear()
    drawNumbers(pts)
    print "Number of points: %s" % len(pts)
    print "POLY"
    PL = PolyLine(pts, closed=closed)
    d = PL.directions()
    dm = PL.avgDirections()
    # w = PL.doubles()+1
    # print PL.endOrDouble()
    curve = BezierSpline(pts, closed=closed)
    draw(curve.approx(100), color="red")
    zoomAll()
Ejemplo n.º 4
0
def run():
    clear()
    linewidth(2)
    flat()

    F = Formex([[[1.,0.,0.]],[[1.,1.,0.]]]).rosette(4,90.)
    draw(F)
    drawNumbers(F)
    zoomAll()
    setDrawOptions(bbox=None)
    showDoc()

    pts = F.coords.reshape(-1,3)

    draw(simple.circle(2,4),color=yellow,linewidth=4)

    for degree,c in zip(range(1,4),[black,red,green]):
        N = NurbsCurve(pts,degree=degree,closed=True)
        draw(N,color=c)
        drawThePoints(N,16,color=c)

    for w,c in zip([sqrt(2.),sqrt(2.)/2.,0.25,0.],[blue,cyan,magenta,white]):
        wts = array([ 1., w ] * 4).reshape(8,1)
        pts4 = Coords4(pts)
        pts4.deNormalize(wts)
        pts4 = Coords4(concatenate([pts4,pts4[:1]],axis=0))
        N = NurbsCurve(pts4,degree=2,closed=False,blended=False)
        draw(N,color=c)
        drawThePoints(N,16,color=c)
Ejemplo n.º 5
0
def askCurve():
    default = 'Angle'
    res = askItems([('curve_type',default,'radio',['Circle','Angle']),('closed',False),('circle_npts',6)])

    if not res:
        exit()

    clear()
    globals().update(res)

    if curve_type == 'Circle':
        circle = simple.circle(a1=360./circle_npts)
        draw(circle,color='magenta')
        pts = circle[:,0]


    elif curve_type == 'Angle':
        F = Formex(simple.pattern('41'))
        draw(F,color='magenta')
        pts = F.coords.reshape(-1,3)

    clear()
    drawNumbers(pts)
    print "Number of points: %s"%len(pts)
    print "POLY"
    PL = PolyLine(pts,closed=closed)
    d = PL.directions()
    dm = PL.avgDirections()
    #w = PL.doubles()+1
    #print PL.endOrDouble()
    curve = BezierSpline(pts,closed=closed)
    draw(curve.approx(100),color='red')
    zoomAll()
Ejemplo n.º 6
0
 def __init__(self,lw=2,mm=0.75,hm=0.85,mh=0.7,hh=0.6, sh=0.9):
     """Create an analog clock."""
     self.linewidth = lw
     self.circle = simple.circle()
     radius = Formex('l:2')
     self.mainmark = radius.divide([mm,1.0])
     self.hourmark = radius.divide([hm,1.0])
     self.mainhand = radius.divide([0.0,mh])
     self.hourhand = radius.divide([0.0,hh])
     if sh > 0.0:
         self.secshand = radius.divide([0.0,sh])
     else:
         self.secshand = None
     self.hands = []
     self.timer = None
Ejemplo n.º 7
0
 def __init__(self,lw=2,mm=0.75,hm=0.85,mh=0.7,hh=0.6, sh=0.9):
     """Create an analog clock."""
     self.linewidth = lw
     self.circle = simple.circle(a1=2.,a2=2.)
     radius = Formex(pattern('2'))
     self.mainmark = radius.divide([mm,1.0])
     self.hourmark = radius.divide([hm,1.0])
     self.mainhand = radius.divide([0.0,mh])
     self.hourhand = radius.divide([0.0,hh])
     if sh > 0.0:
         self.secshand = radius.divide([0.0,sh])
     else:
         self.secshand = None
     self.hands = []
     self.timer = None
Ejemplo n.º 8
0
def drawCircles(sections,ctr,diam):
    """Draw circles as approximation of Formices."""
    circle = simple.circle().rotate(-90,1)
    cross = Formex(simple.Pattern['plus']).rotate(-90,1)
    circles = []
    n = len(sections)
    for i in range(n):
        C = cross.translate(ctr[i])
        B = circle.scale(diam[i]/2).translate(ctr[i])
        S = sections[i]
        clear()
        draw(S,view='left',wait=False)
        draw(C,color='red',bbox=None,wait=False)
        draw(B,color='blue',bbox=None)
        circles.append(B)
    return circles
Ejemplo n.º 9
0
def drawCircles(sections,ctr,diam):
    """Draw circles as approximation of Formices."""
    circle = simple.circle().rotate(-90,1)
    cross = Formex(simple.Pattern['plus']).rotate(-90,1)
    circles = []
    n = len(sections)
    for i in range(n):
        C = cross.translate(ctr[i])
        B = circle.scale(diam[i]/2).translate(ctr[i])
        S = sections[i]
        clear()
        draw(S,view='left',wait=False)
        draw(C,color='red',bbox=None,wait=False)
        draw(B,color='blue',bbox=None)
        circles.append(B)
    return circles
Ejemplo n.º 10
0
def circle_stl():
    """Draw circles as approximation of the STL model."""
    global sections,ctr,diam,circles
    import simple
    circle = simple.circle().rotate(-90,1)
    cross = Formex(simple.Pattern['plus']).rotate(-90,1)
    circles = []
    n = len(sections)
    for i in range(n):
        C = cross.translate(ctr[i])
        B = circle.scale(diam[i]/2).translate(ctr[i])
        S = sections[i]
        print C.bbox()
        print B.bbox()
        print S.bbox()
        clear()
        draw(S,view='left',wait=False)
        draw(C,color='red',bbox=None,wait=False)
        draw(B,color='blue',bbox=None)
        circles.append(B)
Ejemplo n.º 11
0
def createGeometry():
    global F
    # Construct a triangle of an icosahedron oriented with a vertex in
    # the y-direction, and divide its edges in n parts
    n = 6

    # Add a few extra rows to close the gap after projection
    nplus = n+3

    clear()
    # Start with an equilateral triangle in the x-y-plane
    A = simple.triangle()
    A.setProp(1)
    draw(A)

    # Modular size
    a,b,c = A.sizes()
    GD.message("Cell width: %s; height: %s" % (a,b))

    # Create a mirrored triangle
    B = A.reflect(1)
    B.setProp(2)
    draw(B)

    # Replicate nplus times in 2 directions to create triangular pattern
    F = A.replic2(1,nplus,a,-b,0,1,bias=-a/2,taper=1)
    G = B.replic2(1,nplus-1,a,-b,0,1,bias=-a/2,taper=1)

    clear()
    F += G
    draw(F)

    # Get the top vertex and make it the origin
    P = F[0,-1]
    draw(Formex([P]),bbox=None)
    F = F.translate(-P)
    draw(F)

    # Now rotate around the x axis over an angle so that the projection on the
    # x-y plane is an isosceles triangle with top angle = 360/5 = 72 degrees.
    # The base angles thus are (180-72)/2 = 54 degrees.

    # Ratio of the height of the isosceles triangle over the icosaeder edge length.
    c = 0.5*tand(54.)
    angle = arccos(tand(54.)/sqrt(3.))
    GD.message("Rotation Ratio: %s; Angle: %s, %s" % (c,angle,angle/rad)) 
    F = F.rotate(angle/rad,0)
    clear()
    draw(F,colormap=['black','magenta','yellow','black'])

    # Project it on the circumscribing sphere
    # The sphere has radius ru
    golden_ratio = 0.5 * (1. + sqrt(5.))
    ru = 0.5 * a * sqrt(golden_ratio * sqrt(5.))
    GD.message("Radius of circumscribed sphere: %s" % ru)

    ru *= n
    C = [0.,0.,-ru]
    F = F.projectOnSphere(ru,center=C)
    draw(F)

    hx,hy,h = F.sizes()
    GD.message("Height of the dome: %s" % h)

    # The base circle goes through bottom corner of n-th row,
    # which will be the first point of the first triangle of the n-th row.
    # Draw the point to check it.
    
    i = (n-1)*n/2
    P = F[i][0]
    draw(Formex([P]),marksize=10,bbox=None)

    # Get the radius of the base circle from the point's coordinates
    x,y,z = P
    rb = sqrt(x*x+y*y)

    # Give the base points a z-coordinate 0
    F = F.translate([0.,0.,-z])
    clear()
    draw(F)
 
    # Draw the base circle
    H = simple.circle().scale(rb)
    draw(H)

    # Determine intersections with base plane
    P = [0.,0.,0.]
    N = [0.,0.,1.]

    newprops = [ 5,6,6,None,4,None,None ]
    F = F.cutAtPlane(P,N,newprops=newprops,side='+',atol=0.0001)
    #clear()
    draw(F)

    # Finally, create a rosette to make the circle complete
    # and rotate 90 degrees to orient it like in the paper
    clear()
    F = F.rosette(5,72.).rotate(90)

    def cutOut(F,c,r):
        """Remove all elements of F contained in a sphere (c,r)"""
        d = distanceFromPoint(F.f,c)
        return F.select((d < r).any(axis=-1) == False)

    # Cut out the door: remove all members having a point less than
    # edge-length a away from the base point
    p1 = [rb,0.,0.]
    F = cutOut(F,p1,1.1*a*n/6)      # a was a good size with n = 6

    # Scale to the real geometry
    scale = 7000. / F.sizes()[2]
    GD.message("Applying scale factor %s " % scale)
    print F.bbox()
    F = F.scale(scale)
    print F.bbox()

    clear()
    draw(F,alpha=0.4)
    export({'F':F})
Ejemplo n.º 12
0
 def circle_example():
     H = simple.circle(5.,5.)
     draw(H)
     return sectionChar(H)
Ejemplo n.º 13
0
    L = length(N)
    #print L
    S = L / (length(A)*length(B))
    ANG = arcsin(S.clip(min=-1.0,max=1.0))
    N = N/column_stack([L])
    if not rad:
        ANG *= 180./pi
    return (ANG,N)

# Test
linewidth(1)
drawtimeout = 1
for i in [3,4,5,6,8,12,20,60,180]:
    #print "%s points" % i
    clear()
    draw(circle(360./i,360./i),bbox=None)
    clear()
    draw(circle(360./i,2*360./i),bbox=None)
    clear()
    draw(circle(360./i,360./i,180.),bbox=None)


# Example of the use
clear()
n = 40
h = 0.5
line = Formex(pattern('1'*n)).scale(2./n).translate([-1.,0.,0.])
curve = line.bump(1,[0.,h,0.],lambda x: 1.-x**2)
curve.setProp(1)
draw(line)
draw(curve)
Ejemplo n.º 14
0
def draw_circles(circles, color=red):
    for r, c, n in circles:
        C = simple.circle(r=r, n=n, c=c)
        draw(C, color=color)
Ejemplo n.º 15
0

clear()
linewidth(2)
flat()

F = Formex([[[1.,0.,0.]],[[1.,1.,0.]]]).rosette(4,90.)
draw(F)
drawNumbers(F)
zoomAll()
setDrawOptions(bbox=None)
showDescription()

pts = F.coords.reshape(-1,3)

draw(simple.circle(2,4),color=yellow,linewidth=4)

for degree,c in zip(range(1,4),[black,red,green]):
    N = NurbsCurve(pts,degree=degree,closed=True)
    draw(N,color=c)
    drawThePoints(N,16,color=c)

for w,c in zip([sqrt(2.),sqrt(2.)/2.,0.25,0.],[blue,cyan,magenta,white]):
    wts = array([ 1., w ] * 4).reshape(8,1)
    pts4 = Coords4(pts)
    pts4.deNormalize(wts)
    pts4 = Coords4(concatenate([pts4,pts4[:1]],axis=0))
    N = NurbsCurve(pts4,degree=2,closed=False,blended=False)
    draw(N,color=c)
    drawThePoints(N,16,color=c)
Ejemplo n.º 16
0
def circle_example():
    return simple.circle(5.,5.)
Ejemplo n.º 17
0
def circle_example():
    return simple.circle(5., 5.)
Ejemplo n.º 18
0
# MESH PARAMETERS
el = 20 #number of elements along the length
etb = 2 #number of elements over half of the thickness of the body
ehb = 5 #number of elements over half of the height of the body
etf = 5 #number of elements over the thickness of the flange
ewf = 8 #number of elements over half of the width of the flange
er = 6#number of elements in the circular segment

nbody,ebody = mesh.gridRectangle(etb,ehb,tw/2.,h/2.-tf-r)
Body = Formex(nbody[ebody].reshape(-1,4,3)).translate([0,tw/4.,h/4.-tf/2.-r/2.])

c1a = line([0,0,h/2-tf-r],[0,0,h/2-tf+tw/2],er/2)
c1b = line([0,0,h/2-tf+tw/2],[0,tw/2+r,h/2-tf+tw/2],er/2)
c1 = c1a + c1b
c2 = circle(90./er,90./er,90.).scale(r).rotate(-90.,1).rotate(90.,0).translate([0,tw/2+r,h/2-tf-r])
nfilled,efilled = mesh.gridBetween2Curves(c1,c2,etb)
Filled = Formex(nfilled[efilled].reshape(-1,4,3))

nflange1,eflange1 = mesh.gridRectangle(er/2,etf-etb,tw/2.+r,tf-tw/2.)
Flange1 = Formex(nflange1[eflange1].reshape(-1,4,3)).translate([0,tw/4.+r/2.,h/2.-(tf-tw/2.)/2.])

nflange2,eflange2 = mesh.gridRectangle(ewf,etf-etb,b/2.-r-tw/2.,tf-tw/2.)
Flange2 = Formex(nflange2[eflange2].reshape(-1,4,3)).translate([0,tw/2.+r+(b/2.-r-tw/2.)/2.,h/2.-(tf-tw/2.)/2.])

nflange3,eflange3 = mesh.gridRectangle(ewf,etb,b/2.-r-tw/2.,tw/2.)
Flange3 = Formex(nflange3[eflange3].reshape(-1,4,3)).translate([0,tw/2.+r+(b/2.-r-tw/2.)/2.,h/2.-tf+tw/4.])

Quarter = Body + Filled + Flange1 + Flange2 + Flange3
Half = Quarter.rosette(2,180.,2)
Beam = Half.rosette(2,180.,1)
Ejemplo n.º 19
0
    Currently, only plex-2 Formices can be exported to DXF.
    """
    if F.nplex() != 2:
        raise ValueError,"Can only export plex-2 Formices to DXF"
    dxf = DxfExporter(filename)
    dxf.entities()
    for i in F:
        dxf.line(i)
    dxf.endSection()
    dxf.close()


def exportDxfText(filename,parts):
    """Export a set of dxf entities to a .dxftext file."""
    fil = open(filename,'w')
    for p in parts:
        fil.write(p.dxftext()+'\n')
    fil.close()


# An example

if __name__ == 'draw':
    #chdir(__file__)
    from simple import circle
    c = circle(360./20.,360./20.,360.)
    draw(c)
    exportDXF('circle1.dxf',c)

#End
Ejemplo n.º 20
0
def drawCircles(F):
    for r,C,n in zip(*triangleCircumCircle(F.f)):
        c = simple.circle().swapAxes(0,2).scale(r).rotate(rotMatrix(n)).trl(C)
        draw(c)
        zoomAll()   
Ejemplo n.º 21
0
def createGeometry():
    global F
    # Construct a triangle of an icosahedron oriented with a vertex in
    # the y-direction, and divide its edges in n parts
    n = 3

    # Add a few extra rows to close the gap after projection
    nplus = n + 3

    clear()
    smoothwire()
    view('front')
    # Start with an equilateral triangle in the x-y-plane
    A = simple.triangle()
    A.setProp(1)
    draw(A)

    # Modular size
    a, b, c = A.sizes()
    pf.message("Cell width: %s; height: %s" % (a, b))

    # Create a mirrored triangle
    B = A.reflect(1)
    B.setProp(2)
    draw(B)

    # Replicate nplus times in 2 directions to create triangular pattern
    F = A.replic2(1, nplus, a, -b, 0, 1, bias=-a / 2, taper=1)
    G = B.replic2(1, nplus - 1, a, -b, 0, 1, bias=-a / 2, taper=1)

    clear()
    F += G
    draw(F)

    # Get the top vertex and make it the origin
    P = F[0, -1]
    draw(Formex([P]), bbox='last')
    F = F.translate(-P)
    draw(F)

    # Now rotate around the x axis over an angle so that the projection on the
    # x-y plane is an isosceles triangle with top angle = 360/5 = 72 degrees.
    # The base angles thus are (180-72)/2 = 54 degrees.

    # Ratio of the height of the isosceles triangle over the icosaeder edge length.
    c = 0.5 * tand(54.)
    angle = arccosd(tand(54.) / sqrt(3.))
    pf.message("Rotation Ratio: %s; Angle: %s degrees" % (c, angle))
    F = F.rotate(angle, 0)
    clear()
    draw(F, colormap=['black', 'magenta', 'yellow', 'black'])

    # Project it on the circumscribing sphere
    # The sphere has radius ru
    golden_ratio = 0.5 * (1. + sqrt(5.))
    ru = 0.5 * a * sqrt(golden_ratio * sqrt(5.))
    pf.message("Radius of circumscribed sphere: %s" % ru)

    ru *= n
    C = [0., 0., -ru]
    F = F.projectOnSphere(ru, center=C)
    draw(F)

    hx, hy, h = F.sizes()
    pf.message("Height of the dome: %s" % h)

    # The base circle goes through bottom corner of n-th row,
    # which will be the first point of the first triangle of the n-th row.
    # Draw the point to check it.

    i = (n - 1) * n / 2
    P = F[i][0]
    draw(Formex([P]), marksize=10, bbox='last')

    # Get the radius of the base circle from the point's coordinates
    x, y, z = P
    rb = sqrt(x * x + y * y)

    # Give the base points a z-coordinate 0
    F = F.translate([0., 0., -z])
    clear()
    draw(F)

    # Draw the base circle
    H = simple.circle().scale(rb)
    draw(H)

    # Determine intersections with base plane
    P = [0., 0., 0.]
    N = [0., 0., 1.]

    newprops = [5, 6, 6, None, 4, None, None]
    F = F.cutWithPlane(P, N, side='+', newprops=newprops)  #,atol=0.0001)
    #clear()
    draw(F)

    # Finally, create a rosette to make the circle complete
    # and rotate 90 degrees to orient it like in the paper
    clear()
    F = F.rosette(5, 72.).rotate(90)

    def cutOut(F, c, r):
        """Remove all elements of F contained in a sphere (c,r)"""
        d = F.distanceFromPoint(c)
        return F.select((d < r).any(axis=-1) == False)

    # Cut out the door: remove all members having a point less than
    # edge-length a away from the base point
    p1 = [rb, 0., 0.]
    F = cutOut(F, p1, 1.1 * a * n / 6)  # a was a good size with n = 6

    # Scale to the real geometry
    scale = 7000. / F.sizes()[2]
    pf.message("Applying scale factor %s " % scale)
    print(F.bbox())
    F = F.scale(scale)
    print(F.bbox())

    clear()
    draw(F, alpha=0.4)
    export({'F': F})
Ejemplo n.º 22
0
def run():
    # GEOMETRICAL PARAMETERS FOR HE200B wide flange beam
    h = 200. #beam height
    b = 200. #flange width 
    tf = 15. #flange thickness
    tw = 9.  #body thickness
    l = 400. #beam length
    r = 18.  #filling radius

    # MESH PARAMETERS
    el = 20 #number of elements along the length
    etb = 2 #number of elements over half of the thickness of the body
    ehb = 5 #number of elements over half of the height of the body
    etf = 5 #number of elements over the thickness of the flange
    ewf = 8 #number of elements over half of the width of the flange
    er = 6  #number of elements in the circular segment

    Body = simple.rectangle(etb,ehb,tw/2.,h/2.-tf-r)
    Flange1 =  simple.rectangle(er/2,etf-etb,tw/2.+r,tf-tw/2.).translate([0.,h/2.-(tf-tw/2.),0.])
    Flange2 =  simple.rectangle(ewf,etf-etb,b/2.-r-tw/2.,tf-tw/2.).translate([tw/2.+r,h/2.-(tf-tw/2.),0.])
    Flange3 =  simple.rectangle(ewf,etb,b/2.-r-tw/2.,tw/2.).translate([tw/2.+r,h/2.-tf,0.])
    c1a = simple.line([0,h/2-tf-r,0],[0,h/2-tf+tw/2,0],er/2)
    c1b = simple.line([0,h/2-tf+tw/2,0],[tw/2+r,h/2-tf+tw/2,0],er/2)
    c1 = c1a + c1b
    c2 = simple.circle(90./er,0.,90.).reflect(0).scale(r).translate([tw/2+r,h/2-tf-r,0])
    Filled = simple.connectCurves(c2,c1,etb)
    Quarter = Body + Filled + Flange1 + Flange2 + Flange3
    Half = Quarter + Quarter.reflect(1).reverse()
    Full = Half + Half.reflect(0).reverse()
    Section = Full.toMesh()

    clear()
    draw(Section,color=red)
    #return

    #pause()

    method = ask("Choose extrude method:",['Cancel','Sweep','Connect','Extrude','ExtrudeQuadratic','Revolve','RevolveLoop'])

    import timer
    t = timer.Timer()
    if method == 'Sweep':
        L = simple.line([0,0,0],[0,0,l],el)
        x = concatenate([L.coords[:,0],L.coords[-1:,1]])
        path = curve.PolyLine(x)
        Beam = Section.sweep(path,normal=[0.,0.,1.],upvector=[0.,1.,0.])

    elif method == 'Connect':
        Section1 = Section.trl([0,0,l])
        Beam = Section.connect(Section1,el)

    elif method == 'Extrude':
        Beam = Section.extrude(el,step=l/el,dir=2)

    elif method == 'ExtrudeQuadratic':
        Section = Section.convert('quad9')
        Beam = Section.extrude(el,step=l/el,dir=2,degree=2)

    elif method == 'Revolve':
        Beam = Section.revolve(el,axis=1,angle=60.,around=[-l,0.,0.])

    elif method == 'RevolveLoop':
        Beam = Section.revolve(el,axis=1,angle=240.,around=[-l,0.,0.],loop=True)

    else:
        return

    print("Computing: %s seconds" % t.seconds())
    #print Beam.prop
    #print Beam.elems.shape

    t.reset()
    clear()
    #draw(Beam,color='red',linewidth=2)
    draw(Beam.getBorderMesh(),color='red',linewidth=2)
    print("Drawing: %s seconds" % t.seconds())
    export({'Beam':Beam})
Ejemplo n.º 23
0
def run():
    resetAll()
    delay(1)
    
    linewidth(1)
    for i in [3,4,5,6,8,12,20,60,180]:
        #print "%s points" % i
        clear()
        draw(circle(360./i,360./i),bbox=None)
        clear()
        draw(circle(360./i,2*360./i),bbox=None)
        clear()
        draw(circle(360./i,360./i,180.),bbox=None)


    # Example of the use
    clear()
    n = 40
    h = 0.5
    line = Formex('l:'+'1'*n).scale(2./n).translate([-1.,0.,0.])
    curve = line.bump(1,[0.,h,0.],lambda x: 1.-x**2)
    curve.setProp(1)
    draw(line)
    draw(curve)


    # Create circles in the middle of each segment, with normal along the segment
    # begin and end points of segment
    A = curve.coords[:,0,:]
    B = curve.coords[:,1,:]
    # midpoint and segment director
    C = 0.5*(B+A)
    D = B-A
    # vector initially normal to circle defined above
    nuc = array([0.,0.,1.])
    # rotation angles and vectors
    ang,rot = rotationAngle(nuc,D)
    # diameters varying linearly with the |x| coordinate
    diam = 0.1*h*(2.-abs(C[:,0]))
    # finally, here are the circles:
    circles = [ circle().scale(d).rotate(a,r).translate(c) for d,r,a,c in zip(diam,rot,ang,C) ]
    F = Formex.concatenate(circles).setProp(3) 
    draw(F)

    # And now something more fancy: connect 1 out of 15 points of the circles

    res = askItems([
        ('Connect circles',True),
        ('Create Triangles',True),
        ('Fly Through',True),
        ])

    if res:

        if res['Connect circles'] or res['Create Triangles']:
            conn = range(0,180,15)

        if res['Connect circles']:
            G = Formex.concatenate([ connect([c1.select(conn),c2.select(conn)]) for c1,c2 in zip(circles[:-1],circles[1:]) ])
            draw(G)

        if res['Create Triangles']:
            conn1 = concatenate([conn[1:],conn[:1]])
            G = Formex.concatenate([ connect([c1.select(conn),c2.select(conn),c2.select(conn1)]) for c1,c2 in zip(circles[:-1],circles[1:]) ])
            smooth()
            print(G.eltype)
            draw(G)

        if res['Fly Through']:
            flyAlong(curve,sleeptime=0.1)
            clear()
            flat()
            draw(line)
            draw(curve)
            draw(F)
Ejemplo n.º 24
0
def draw_circles(circles, color=red):
    for r, c, n in circles:
        C = simple.circle(r=r, n=n, c=c)
        draw(C, color=color)
Ejemplo n.º 25
0
# MESH PARAMETERS
el = 20 #number of elements along the length
etb = 2 #number of elements over half of the thickness of the body
ehb = 5 #number of elements over half of the height of the body
etf = 5 #number of elements over the thickness of the flange
ewf = 8 #number of elements over half of the width of the flange
er = 6  #number of elements in the circular segment

Body = simple.rectangle(etb,ehb,tw/2.,h/2.-tf-r)
Flange1 =  simple.rectangle(er/2,etf-etb,tw/2.+r,tf-tw/2.).translate([0.,h/2.-(tf-tw/2.),0.])
Flange2 =  simple.rectangle(ewf,etf-etb,b/2.-r-tw/2.,tf-tw/2.).translate([tw/2.+r,h/2.-(tf-tw/2.),0.])
Flange3 =  simple.rectangle(ewf,etb,b/2.-r-tw/2.,tw/2.).translate([tw/2.+r,h/2.-tf,0.])
c1a = simple.line([0,h/2-tf-r,0],[0,h/2-tf+tw/2,0],er/2)
c1b = simple.line([0,h/2-tf+tw/2,0],[tw/2+r,h/2-tf+tw/2,0],er/2)
c1 = c1a + c1b
c2 = simple.circle(90./er,0.,90.).reflect(0).scale(r).translate([tw/2+r,h/2-tf-r,0])
Filled = simple.connectCurves(c2,c1,etb)
Quarter = Body + Filled + Flange1 + Flange2 + Flange3
Half = Quarter + Quarter.reflect(1).reverse()
Full = Half + Half.reflect(0).reverse()
Section = Full.toMesh()

clear()
draw(Section,color=red)
#exit()

#pause()

method = ask("Choose extrude method:",['Cancel','Sweep','Connect','Extrude','ExtrudeQuadratic','Revolve','RevolveLoop'])

import timer
Ejemplo n.º 26
0
def run():
    # GEOMETRICAL PARAMETERS FOR HE200B wide flange beam
    h = 200.  #beam height
    b = 200.  #flange width
    tf = 15.  #flange thickness
    tw = 9.  #body thickness
    l = 400.  #beam length
    r = 18.  #filling radius

    # MESH PARAMETERS
    el = 20  #number of elements along the length
    etb = 2  #number of elements over half of the thickness of the body
    ehb = 5  #number of elements over half of the height of the body
    etf = 5  #number of elements over the thickness of the flange
    ewf = 8  #number of elements over half of the width of the flange
    er = 6  #number of elements in the circular segment

    Body = simple.rectangle(etb, ehb, tw / 2., h / 2. - tf - r)
    Flange1 = simple.rectangle(er / 2, etf - etb, tw / 2. + r,
                               tf - tw / 2.).translate(
                                   [0., h / 2. - (tf - tw / 2.), 0.])
    Flange2 = simple.rectangle(ewf, etf - etb, b / 2. - r - tw / 2.,
                               tf - tw / 2.).translate(
                                   [tw / 2. + r, h / 2. - (tf - tw / 2.), 0.])
    Flange3 = simple.rectangle(ewf, etb, b / 2. - r - tw / 2., tw /
                               2.).translate([tw / 2. + r, h / 2. - tf, 0.])
    c1a = simple.line([0, h / 2 - tf - r, 0], [0, h / 2 - tf + tw / 2, 0],
                      er / 2)
    c1b = simple.line([0, h / 2 - tf + tw / 2, 0],
                      [tw / 2 + r, h / 2 - tf + tw / 2, 0], er / 2)
    c1 = c1a + c1b
    c2 = simple.circle(90. / er, 0., 90.).reflect(0).scale(r).translate(
        [tw / 2 + r, h / 2 - tf - r, 0])
    Filled = simple.connectCurves(c2, c1, etb)
    Quarter = Body + Filled + Flange1 + Flange2 + Flange3
    Half = Quarter + Quarter.reflect(1).reverse()
    Full = Half + Half.reflect(0).reverse()
    Section = Full.toMesh()

    clear()
    draw(Section, color=red)
    #return

    #pause()

    method = ask("Choose extrude method:", [
        'Cancel', 'Sweep', 'Connect', 'Extrude', 'ExtrudeQuadratic', 'Revolve',
        'RevolveLoop'
    ])

    import timer
    t = timer.Timer()
    if method == 'Sweep':
        L = simple.line([0, 0, 0], [0, 0, l], el)
        x = concatenate([L.coords[:, 0], L.coords[-1:, 1]])
        path = curve.PolyLine(x)
        Beam = Section.sweep(path, normal=[0., 0., 1.], upvector=[0., 1., 0.])

    elif method == 'Connect':
        Section1 = Section.trl([0, 0, l])
        Beam = Section.connect(Section1, el)

    elif method == 'Extrude':
        Beam = Section.extrude(el, step=l / el, dir=2)

    elif method == 'ExtrudeQuadratic':
        Section = Section.convert('quad9')
        Beam = Section.extrude(el, step=l / el, dir=2, degree=2)

    elif method == 'Revolve':
        Beam = Section.revolve(el, axis=1, angle=60., around=[-l, 0., 0.])

    elif method == 'RevolveLoop':
        Beam = Section.revolve(el,
                               axis=1,
                               angle=240.,
                               around=[-l, 0., 0.],
                               loop=True)

    else:
        return

    print("Computing: %s seconds" % t.seconds())
    #print Beam.prop
    #print Beam.elems.shape

    t.reset()
    clear()
    #draw(Beam,color='red',linewidth=2)
    draw(Beam.getBorderMesh(), color='red', linewidth=2)
    print("Drawing: %s seconds" % t.seconds())
    export({'Beam': Beam})
Ejemplo n.º 27
0
wts = array([
    1.0,
    sq2,
    1.0,
    sq2,
    1.0,
    sq2,
    1.0,
    sq2,
    ]).reshape(-1,1)


P = PolyLine(pts,closed=closed)
#draw(P,color=magenta)

Q = simple.circle()
draw(Q,color=yellow)
#drawNumbers(Q,color=red)

N = {}
for order,color in zip(range(2,5),[black,green,red]):
    N[order] = NurbsActor(pts,closed=closed,order=order,color=color)
    drawActor(N[order])

print pts.shape
print wts.shape
order = 3
NO = NurbsActor(pts*wts,knots=knots,closed=closed,order=order,color=blue)
draw(pts*wts,color=magenta)
drawActor(NO)