예제 #1
0
def sector(r, t, nr, nt, h=0., diag=None):
    """Constructs a Formex which is a sector of a circle/cone.

    A sector with radius r and angle t is modeled by dividing the
    radius in nr parts and the angle in nt parts and then creating
    straight line segments.
    If a nonzero value of h is given, a conical surface results with its
    top at the origin and the base circle of the cone at z=h.
    The default is for all points to be in the (x,y) plane.


    By default, a plex-4 Formex results. The central quads will collapse
    into triangles.
    If diag='up' or diag = 'down', all quads are divided by an up directed
    diagonal and a plex-3 Formex results.
    """
    r = float(r)
    t = float(t)
    p = Formex(regularGrid([0., 0., 0.], [r, 0., 0.], [nr, 0, 0],swapaxes=True).reshape(-1, 3))
    if h != 0.:
        p = p.shear(2, 0, h / r)
    q = p.rotate(t / nt)
    if isinstance(diag, str):
        diag = diag[0]
    if diag == 'u':
        F = connect([p, p, q], bias=[0, 1, 1]) + \
            connect([p, q, q], bias=[1, 2, 1])
    elif diag == 'd':
        F = connect([q, p, q], bias=[0, 1, 1]) + \
            connect([p, p, q], bias=[1, 2, 1])
    else:
        F = connect([p, p, q, q], bias=[0, 1, 1, 0])

    F = Formex.concatenate([F.rotate(i * t / nt) for i in range(nt)])
    return F
예제 #2
0
def connectCurves(curve1, curve2, n):
    """Connect two curves to form a surface.

    curve1, curve2 are plex-2 Formices with the same number of elements.
    The two curves are connected by a surface of quadrilaterals, with n
    elements in the direction between the curves.
    """
    if curve1.nelems() != curve2.nelems():
        raise ValueError("Both curves should have same number of elements")
    # Create the interpolations
    curves = interpolate(curve1, curve2, n).split(curve1.nelems())
    quads = [connect([c1, c1, c2, c2], nodid=[0, 1, 1, 0])
             for c1, c2 in zip(curves[:-1], curves[1:])]
    return Formex.concatenate(quads)
예제 #3
0
def rect(p1=[0., 0., 0.], p2=[1., 0., 0.], nx=1, ny=1):
    """Return a Formex which is a the circumference of a rectangle.

    p1 and p2 are two opposite corner points of the rectangle.
    The edges of the rectangle are in planes parallel to the z-axis.
    There will always be two opposite edges that are parallel with the x-axis.
    The other two will only be parallel with the y-axis if both points
    have the same z-value, but in any case they will be parallel with the
    y-z plane.

    The edges parallel with the x-axis are divide in nx parts, the other
    ones in ny parts.
    """
    p1 = Coords(p1)
    p2 = Coords(p2)
    p12 = Coords([p2[0], p1[1], p1[2]])
    p21 = Coords([p1[0], p2[1], p2[2]])
    return Formex.concatenate([
        line(p1, p12, nx),
        line(p12, p2, ny),
        line(p2, p21, nx),
        line(p21, p1, ny)
    ])
예제 #4
0
    def __init__(self,val,pos,prefix='',**kargs):
        # Make sure we have strings
        val = [ str(i) for i in val ]
        pos = at.checkArray(pos,shape=(len(val),-1))
        if len(val) != pos.shape[0]:
            raise ValueError("val and pos should have same length")

        # concatenate all strings
        val = [ prefix+str(v) for v in val ]
        cs = at.cumsum([0,] + [ len(v) for v in val ])
        val = ''.join(val)
        nc = cs[1:] - cs[:-1]

        pos = [ at.multiplex(p,n,0) for p,n in zip(pos,nc) ]
        pos = np.concatenate(pos,axis=0)
        pos = at.multiplex(pos,4,1)

        # Create the grids for the strings
        F = Formex('4:0123')
        grid = Formex.concatenate([ F.replic(n) for n in nc ])

        # Create a text with the concatenation
        Text.__init__(self,val,pos=pos,grid=grid,**kargs)