Exemplo n.º 1
0
def create_visualise_bounding_button():
    button_area = shapes.Rectangle(0, 0, 30, 30)
    button = rendering.Button(button_area)
    icon_shapes = [
        shapes.Circle((8, 10), 7),
        shapes.LineSegment((5, 28), (28, 18))
    ]
    for shape in icon_shapes:
        if shape.has_area():
            shape_graphic = rendering.SimpleMonoColouredGraphic(
                shape, colours.BLUE)
        else:
            shape_graphic = rendering.SimpleOutlineGraphic(shape, colours.BLUE)
        button.add_canvas(shape_graphic)
        button.add_canvas(
            rendering.SimpleOutlineGraphic(shape.to_bounding_rectangle(),
                                           colours.RED))

    return button
Exemplo n.º 2
0
def main():
    bates_srm = BatesSRM()

    shapecoll = shapes.ShapeCollection()
    circ = shapes.Circle((0, 0), R_inner)
    shapecoll.addShape(circ)

    bates_grain_ls = LevelSetSRM(shapecoll)

    theta = np.arange(0, 4) * np.pi / 4.
    lines_c = []

    lines = [
        shapes.LineSegment(
            [finocyl_spoke_len * np.cos(t), finocyl_spoke_len * np.sin(t)],
            [-finocyl_spoke_len * np.cos(t), -finocyl_spoke_len * np.sin(t)],
            width=finocyl_spoke_width) for t in theta
    ]
    [shapecoll.addShape(l) for l in lines]
    finocyl_grain_ls = LevelSetSRM(shapecoll)

    sustainer_assembly = SRM_Assembly({bates_grain_ls: 5})

    booster_assembly = SRM_Assembly({finocyl_grain_ls: 2, bates_grain_ls: 5})

    Pb, Tb, Ab, xb, tb = runAndTimeSRM(booster_assembly, "Booster", True)

    np.savetxt("results/Pb.txt", Pb)
    np.savetxt("results/Tb.txt", Tb)
    np.savetxt("results/Ab.txt", Ab)
    np.savetxt("results/xb.txt", xb)

    Psus, Tsus, Asus, xsus, tsus = runAndTimeSRM(sustainer_assembly,
                                                 "Sustainer", True)
    np.savetxt("results/Psus.txt", Psus)
    np.savetxt("results/Tsus.txt", Tsus)
    np.savetxt("results/Asus.txt", Asus)
    np.savetxt("results/xsus.txt", xsus)
Exemplo n.º 3
0
def ruler(start, end, ticks=4, sub_ticks=4, absolute=False, snap=False, **kwds):
    """
    Draw a ruler in 3-D, with major and minor ticks.

    INPUT:

    - ``start`` - the beginning of the ruler, as a list,
      tuple, or vector.

    - ``end`` - the end of the ruler, as a list, tuple,
      or vector.

    - ``ticks`` - (default: 4) the number of major ticks
      shown on the ruler.

    - ``sub_ticks`` - (default: 4) the number of shown
      subdivisions between each major tick.

    - ``absolute`` - (default: ``False``) if ``True``, makes a huge ruler
      in the direction of an axis.

    - ``snap`` - (default: ``False``) if ``True``, snaps to an implied
      grid.

    Type ``line3d.options`` for a dictionary of the default
    options for lines, which are also available.

    EXAMPLES:

    A ruler::

        sage: from sage.plot.plot3d.shapes2 import ruler
        sage: R = ruler([1,2,3],vector([2,3,4])); R

    A ruler with some options::

        sage: R = ruler([1,2,3],vector([2,3,4]),ticks=6, sub_ticks=2, color='red'); R

    The keyword ``snap`` makes the ticks not necessarily coincide
    with the ruler::

        sage: ruler([1,2,3],vector([1,2,4]),snap=True)

    The keyword ``absolute`` makes a huge ruler in one of the axis
    directions::

        sage: ruler([1,2,3],vector([1,2,4]),absolute=True)

    TESTS::

        sage: ruler([1,2,3],vector([1,3,4]),absolute=True)
        Traceback (most recent call last):
        ...
        ValueError: Absolute rulers only valid for axis-aligned paths
    """
    start = vector(RDF, start)
    end   = vector(RDF, end)
    dir = end - start
    dist = math.sqrt(dir.dot_product(dir))
    dir /= dist

    one_tick = dist/ticks * 1.414
    unit = 10 ** math.floor(math.log(dist/ticks, 10))
    if unit * 5 < one_tick:
        unit *= 5
    elif unit * 2 < one_tick:
        unit *= 2

    if dir[0]:
        tick = dir.cross_product(vector(RDF, (0,0,-dist/30)))
    elif dir[1]:
        tick = dir.cross_product(vector(RDF, (0,0,dist/30)))
    else:
        tick = vector(RDF, (dist/30,0,0))

    if snap:
        for i in range(3):
            start[i] = unit * math.floor(start[i]/unit + 1e-5)
            end[i] = unit * math.ceil(end[i]/unit - 1e-5)

    if absolute:
        if dir[0]*dir[1] or dir[1]*dir[2] or dir[0]*dir[2]:
            raise ValueError, "Absolute rulers only valid for axis-aligned paths"
        m = max(dir[0], dir[1], dir[2])
        if dir[0] == m:
            off = start[0]
        elif dir[1] == m:
            off = start[1]
        else:
            off = start[2]
        first_tick = unit * math.ceil(off/unit - 1e-5) - off
    else:
        off = 0
        first_tick = 0

    ruler = shapes.LineSegment(start, end, **kwds)
    for k in range(1, int(sub_ticks * first_tick/unit)):
        P = start + dir*(k*unit/sub_ticks)
        ruler += shapes.LineSegment(P, P + tick/2, **kwds)
    for d in srange(first_tick, dist + unit/(sub_ticks+1), unit):
        P = start + dir*d
        ruler += shapes.LineSegment(P, P + tick, **kwds)
        ruler += shapes.Text(str(d+off), **kwds).translate(P - tick)
        if dist - d < unit:
            sub_ticks = int(sub_ticks * (dist - d)/unit)
        for k in range(1, sub_ticks):
            P += dir * (unit/sub_ticks)
            ruler += shapes.LineSegment(P, P + tick/2, **kwds)
    return ruler