Ejemplo n.º 1
0
 def draw(self, offset):
     """Fundamental draw method.
     """
     # The big rectangle.
     l = 0.5 * self.LENGTH
     w = 0.5 * self.WIDTH
     Rectangle(self.CENTER, self.LENGTH, self.WIDTH).draw(offset)
     # The two center lines.
     plt.hlines(0, -l, l)
     plt.vlines(0, -w, w)
     # Small centering holes.
     r = 1.5
     Hole(self.CENTER.vmove(w), r).draw(offset)
     Hole(self.CENTER.vmove(-w), r).draw(offset)
     Hole(self.CENTER.hmove(l), r).draw(offset)
     Hole(self.CENTER.hmove(-l), r).draw(offset)
     # Bigger centering holes.
     r = 3.
     Hole(self.CENTER.vmove(w - self.BORDER), r).draw(offset)
     Hole(self.CENTER.vmove(-w + self.BORDER), r).draw(offset)
     Hole(self.CENTER.hmove(l - self.BORDER), r).draw(offset)
     Hole(self.CENTER.hmove(-l + self.BORDER), r).draw(offset)
     # And, finally, the branding :-)
     x = -l + self.BORDER + offset.x
     y = w - 2. * self.BORDER + offset.y
     plt.text(x, y, GITHUB_URL)
Ejemplo n.º 2
0
def vruler(x, ymin, ymax, step=10., line_width=0.15):
    """
    """
    fmt = dict(lw=mm_to_points(line_width))
    plt.vlines(x, ymin, ymax, **fmt)
    y = np.arange(ymin, ymax + 0.5 * step, step)
    plt.hlines(y, x, x + 2., **fmt)
    fmt = dict(size='small', ha='left', va='center')
    for _y in y:
        text = '{:.0f}'.format(_y)
        if text == '0':
            text += ' mm'
        plt.text(x + 3, _y, text, **fmt)
Ejemplo n.º 3
0
def hruler(y, xmin, xmax, step=10., line_width=0.15):
    """
    """
    fmt = dict(lw=mm_to_points(line_width))
    plt.hlines(y, xmin, xmax, **fmt)
    x = np.arange(xmin, xmax + 0.5 * step, step)
    plt.vlines(x, y, y - 2., **fmt)
    fmt = dict(size='small', ha='center', va='top')
    for _x in x:
        text = '{:.0f}'.format(_x)
        if text == '0':
            text += ' mm'
        plt.text(_x, y - 3., text, **fmt)
Ejemplo n.º 4
0
def test_draw(offset):
    """
    """
    blueprint(f'EJ #1{offset}', 'A3', orientation='Portrait')
    #body = Body()
    #body.draw(offset)

    x = np.array([
        0., 15., 50., 125., 200., 230., 250., 280., 300., 325., 350., 370.,
        385., 400., 405., 395., 384., 380.5, 379., 383., 393., 375., 354.,
        340., 320., 305., 298.7, 315., 334.7, 325.8, 310., 266., 230., 200.,
        120., 50., 10.
    ])
    y = np.array([
        0., 80., 131., 160., 141.5, 124.3, 113.3, 106.4, 107.4, 115., 123.,
        125.7, 123., 110.3, 90., 68., 57., 50., 42., 28., 10., -13.2, -27.5,
        -28.58, -30.5, -40.5, -60., -90, -108.7, -122.5, -127.4, -115.1,
        -116.2, -136., -159.4, -131., -69.
    ])
    s = ParametricSpline(x, y)
    s.draw(offset)
    #s.draw_points(offset)

    #scale = 1.05
    #s1 = ParametricSpline(x * scale, y * scale)
    #s1.draw(offset - Point(8., 0.))

    h1 = 52.
    h2 = 25.
    w1 = 75.
    x, y = s.calculate_contour(offset, tmin=0., tmax=0.5)
    mask = abs(y - offset.y) > h1
    x = x[mask]
    y = y[mask]
    plt.plot(x, y, color='black')
    plt.hlines(h1 + offset.y, x[0], x[-1])

    x, y = s.calculate_contour(offset, tmin=0.5, tmax=1.)
    mask = np.logical_and(abs(y - offset.y) > h1, x - offset.x < 317.)
    x = x[mask]
    y = y[mask]
    plt.plot(x, y, color='black')
    plt.hlines(-h1 + offset.y, x[0], x[-1])

    p0 = Point(-50., 0.)
    l = Line(p0, p0.move(500., 0.))
    l.draw(offset)

    p1 = Point(200., -200.)
    l = Line(p1, p1.vmove(400.))
    l.draw(offset)
Ejemplo n.º 5
0
 def test_body_draw_split(self):
     """
     """
     x0 = 200.
     y0 = 0.
     blueprint('Music Man Axis 1', 'A3', orientation='Portrait')
     offset = Point(-100., 15.)
     plt.hlines(y0, -1000., 1000.)
     plt.vlines(x0 + offset.x, -1000., 1000.)
     body = Body()
     body.draw_construction(offset)
     body.draw(offset)
     body.draw_reference_points(offset)
     plt.savefig('axis1.pdf')
     blueprint('Music Man Axis 2', 'A3', orientation='Portrait')
     offset = Point(-300., 15.)
     plt.hlines(y0, -1000., 1000.)
     plt.vlines(x0 + offset.x, -1000., 1000.)
     body = Body()
     body.draw_construction(offset)
     body.draw(offset)
     body.draw_reference_points(offset)
     plt.savefig('axis2.pdf')
Ejemplo n.º 6
0
def blueprint(name: str,
              size: str,
              author=None,
              orientation: str = 'Landscape',
              dpi: float = 100.,
              text_size: float = 3.,
              line_width: float = 0.25,
              margin: float = 0.05,
              pitch: float = 50.,
              tick_size: float = 7.5):
    """Create a custom figure for techical drawings.
    """
    assert orientation in PAPER_ORIENTATIONS
    width, height = PAPER_SIZE_DICT[size]
    if orientation == 'Landscape':
        width, height = height, width
    # Setup the page.
    width, height, dpi = setup_page((width, height), dpi, text_size,
                                    line_width)
    # Create an empty figure.
    plt.figure(name)
    # Setup the axes.
    plt.gca().set_aspect('equal')
    hmargin = margin
    vmargin = hmargin * width / height
    plt.subplots_adjust(left=hmargin,
                        right=1. - hmargin,
                        top=1. - vmargin,
                        bottom=vmargin)
    plt.xticks([])
    plt.yticks([])
    w = 0.5 * width * (1. - 2. * hmargin)
    h = 0.5 * height * (1. - 2. * vmargin)
    plt.gca().axis([-w, w, -h, h])
    # Add the reference grid on the borders.
    nx = int(width / pitch + 0.5)
    ny = int(height / pitch + 0.5)
    x = np.linspace(-w, w, nx + 1)
    y = np.linspace(-h, h, ny + 1)
    plt.hlines(y, -w, -w - tick_size, clip_on=False)
    plt.hlines(y, w, w + tick_size, clip_on=False)
    plt.vlines(x, -h, -h - tick_size, clip_on=False)
    plt.vlines(x, h, h + tick_size, clip_on=False)
    # Add the letters and numbers to the reference grid.
    dx = w / nx
    dy = h / ny
    fmt = dict(size='large', ha='center', va='center')
    for i, _x in enumerate(np.flip((x + dx)[:-1])):
        plt.text(_x, -h - tick_size, '{}'.format(i + 1), **fmt)
        plt.text(_x, h + tick_size, '{}'.format(i + 1), rotation=90., **fmt)
    for i, _y in enumerate((y + dy)[:-1]):
        plt.text(-w - tick_size, _y, '{}'.format(ascii_uppercase[i]), **fmt)
        plt.text(w + tick_size,
                 _y,
                 '{}'.format(ascii_uppercase[i]),
                 rotation=90.,
                 **fmt)
    # Add the reference rulers.
    delta = 5.
    span = 0.75
    l = 10 * int((span * w) / 10.)
    hruler(h - delta, -l, l)
    l = 10 * int((span * h) / 10.)
    vruler(-w + delta, -l, l)
    box = BlueprintBox(name, author)