Exemple #1
0
def main() -> None:
    wheel1 = (
        ps.Circle(ps.Point(w_1, R), R)
        .set_fill_color(ps.Style.Color.BLUE)
        .set_line_width(6)
    )
    wheel2 = wheel1.translate(ps.Point(L, 0))
    under = ps.Rectangle(ps.Point(w_1 - 2 * R, 2 * R), 2 * R + L + 2 * R, H)
    under.style.fill_color = ps.Style.Color.RED
    under.style.line_color = ps.Style.Color.RED
    over = ps.Rectangle(ps.Point(w_1, 2 * R + H), 2.5 * R, 1.25 * H).set_fill_color(
        ps.Style.Color.WHITE
    )
    over.style.line_width = 14
    over.style.line_color = ps.Style.Color.RED
    over.style.fill_pattern = ps.Style.FillPattern.UP_RIGHT_TO_LEFT

    ground = ps.Wall([ps.Point(w_1 - L, 0), ps.Point(w_1 + 3 * L, 0)], -0.3 * R)
    ground.style.fill_pattern = ps.Style.FillPattern.UP_LEFT_TO_RIGHT

    model = ps.Composition(
        {
            "wheel1": wheel1,
            "wheel2": wheel2,
            "under": under,
            "over": over,
            "ground": ground,
        }
    )

    fig = ps.Figure(
        0, w_1 + 2 * L + 3 * R, -1, 2 * R + 3 * H, backend=MatplotlibBackend
    )
    fig.add(model)
    fig.show()
Exemple #2
0
def main() -> None:
    c = ps.Point(w_1, R)

    wheel1 = ps.Circle(c, R)
    wheel2 = wheel1.translate(ps.Point(L, 0))
    under = ps.Rectangle(ps.Point(w_1 - 2 * R, 2 * R), 2 * R + L + 2 * R, H)
    over = ps.Rectangle(ps.Point(w_1, 2 * R + H), 2.5 * R,
                        1.25 * H).set_fill_color(ps.Style.Color.WHITE)
    ground = ps.Wall(
        [ps.Point(w_1 - L, 0), ps.Point(w_1 + 3 * L, 0)], -0.3 * R)
    ground.style.fill_pattern = ps.Style.FillPattern.UP_RIGHT_TO_LEFT

    vehicle = ps.Composition({
        "wheel1": wheel1,
        "wheel2": wheel2,
        "under": under,
        "over": over,
        "ground": ground,
    })

    vehicle.style.line_color = ps.Style.Color.RED

    wheel1_dim = ps.LinearDimension("$w_1$", c + ps.Point(2, 0.25), c)
    hdp = w_1 + L + 3 * R  # horizontal dimension position
    R_dim = ps.LinearDimension("$R$", ps.Point(hdp, 0), ps.Point(hdp, R))
    H_dim = ps.LinearDimension("$H$", ps.Point(hdp, 2 * R),
                               ps.Point(hdp, 2 * R + H))
    H2_dim = ps.LinearDimension("$\\frac{5}{4}H$", ps.Point(hdp, 2 * R + H),
                                ps.Point(hdp, 2 * R + (9 / 4) * H))

    vdp = 2 * R + H + 3 / 2 * H
    R2_dim = ps.LinearDimension("$2R$", ps.Point(w_1 - 2 * R, vdp),
                                ps.Point(w_1, vdp))
    L_dim = ps.LinearDimension("$L$", ps.Point(w_1, vdp),
                               ps.Point(w_1 + L, vdp))
    R3_dim = ps.LinearDimension("$2R$", ps.Point(w_1 + L, vdp),
                                ps.Point(w_1 + L + 2 * R, vdp))

    dimensions = ps.Composition({
        "wheel1_dim": wheel1_dim,
        "R_dim": R_dim,
        "H_dim": H_dim,
        "H2_dim": H2_dim,
        "R2_dim": R2_dim,
        "L_dim": L_dim,
        "R3_dim": R3_dim,
    })

    model = ps.Composition({"vehicle": vehicle, "dimensions": dimensions})

    figure = ps.Figure(0,
                       w_1 + 2 * L + 3 * R,
                       -1,
                       2 * R + 3 * H,
                       backend=MatplotlibBackend)
    figure.add(model)
    figure.show()
Exemple #3
0
def main() -> None:
    d = make_dashpot(0)
    s = make_spring(0)

    M = ps.Rectangle(ps.Point(0, H), 4 * H, 4 * H).set_line_width(4)
    left_wall = ps.Rectangle(ps.Point(-L, 0), H / 10, L).set_fill_pattern(
        ps.Style.FillPattern.UP_LEFT_TO_RIGHT)
    ground = ps.Wall([ps.Point(-L / 2, 0), ps.Point(L, 0)], thickness=-H / 10)
    wheel1 = ps.Circle(ps.Point(H, H / 2), H / 2)
    wheel2 = wheel1.translate(ps.Point(2 * H, 0))

    fontsize = 24
    text_m = ps.Text("$m$", ps.Point(2 * H, H + 2 * H))
    text_m.style.font_size = fontsize
    text_ku = ps.Text("$ku$", ps.Point(-L / 2, H + 4 * H))
    text_ku.style.font_size = fontsize
    text_bv = ps.Text("$bu'$", ps.Point(-L / 2, H))
    text_bv.style.font_size = fontsize
    x_axis = ps.Axis(ps.Point(2 * H, L), H, "$u(t)$")
    x_axis_start = ps.Line(ps.Point(2 * H, L - H / 4),
                           ps.Point(2 * H, L + H / 4)).set_line_width(4)

    model = ps.Composition({
        "spring": s,
        "mass": M,
        "left wall": left_wall,
        "ground": ground,
        "wheel1": wheel1,
        "wheel2": wheel2,
        "text_m": text_m,
        "text_ku": text_ku,
        "x_axis": x_axis,
        "x_axis_start": x_axis_start,
    })

    fig = ps.Figure(-L, x_max, -1, L + H, backend=MatplotlibBackend)
    fig.add(model)

    damping = ps.Composition({"dashpot": d, "text_bv": text_bv})

    # or fig = Composition(dict(fig=fig, dashpot=d, text_bv=text_bv))
    fig.add(damping)
    fig.show()
Exemple #4
0
def main() -> None:
    rect = ps.Rectangle(ps.Point(1, 1), 4, 6)

    dim_w = LinearDimension(r"$w$", rect.lower_left, rect.lower_right)
    dim_h = LinearDimension(r"$h$", rect.lower_right, rect.upper_right)

    fig = ps.Figure(0, 8, 0, 8, backend=MatplotlibBackend)
    fig.add(rect)
    fig.add(dim_w)
    fig.add(dim_h)
    fig.show()
Exemple #5
0
def main() -> None:
    i = 1
    shapes_dict = {}
    for fill_pattern in ps.Style.FillPattern:
        logging.info("Fill Pattern: %s", fill_pattern)
        name: str = "Rectangle.%d" % i
        rectangle = ps.Rectangle(ps.Point(i, 1), 1,
                                 1).set_fill_pattern(fill_pattern)
        shapes_dict[name] = rectangle
        i = i + 1.5

    shapes = ps.Composition(shapes_dict)

    fig = ps.Figure(0.0, 20.0, 0.0, 3.0, backend=MatplotlibBackend)
    fig.add(shapes)
    fig.show()
Exemple #6
0
def main() -> None:
    i = 1
    shapes = {}
    for line_color in ps.Style.Color:
        j = 1
        for fill_color in ps.Style.Color:
            logging.info("Line Color: %s", line_color)
            name: str = "Rectangle.%d.%d" % (i, j)
            rectangle = ps.Rectangle(ps.Point(i, j), 1, 1)
            rectangle.style.line_width = 3.0
            rectangle.style.line_color = line_color
            rectangle.style.fill_color = fill_color
            shapes[name] = rectangle
            j = j + 1
        i = i + 1

    model = ps.Composition(shapes)

    fig = ps.Figure(0, 12, 0, 12, backend=MatplotlibBackend)
    fig.add(model)
    fig.show()
Exemple #7
0
import pysketcher as ps
from pysketcher.backend.matplotlib import MatplotlibBackend

rect = ps.Rectangle(ps.Point(4, 4), 10, 15)

fig = ps.Figure(0, 20, 0, 20, backend=MatplotlibBackend)
fig.add(rect)
fig.show()
Exemple #8
0
import logging

import pysketcher as ps
from pysketcher.backend.matplotlib import MatplotlibBackend

i = 1
shapes_dict = {}
for fill_pattern in ps.Style.FillPattern:
    logging.info("Fill Pattern: %s", fill_pattern)
    name: str = "Rectangle.%d" % i
    rectangle = ps.Rectangle(ps.Point(i, 1), 1,
                             1).set_fill_pattern(fill_pattern)
    shapes_dict[name] = rectangle
    i = i + 1.5

shapes = ps.Composition(shapes_dict)

fig = ps.Figure(0.0, 20.0, 0.0, 3.0, backend=MatplotlibBackend)
fig.add(shapes)
fig.show()
Exemple #9
0
import logging

import pysketcher as ps
from pysketcher.backend.matplotlib import MatplotlibBackend

logging.basicConfig(level=logging.INFO)

i = 1
shapes = {}
for line_color in ps.Style.Color:
    j = 1
    for fill_color in ps.Style.Color:
        logging.info("Line Color: %s", line_color)
        name: str = "Rectangle.%d.%d" % (i, j)
        rectangle = ps.Rectangle(ps.Point(i, j), 1, 1)
        rectangle.style.line_width = 3.0
        rectangle.style.line_color = line_color
        rectangle.style.fill_color = fill_color
        shapes[name] = rectangle
        j = j + 1
    i = i + 1

model = ps.Composition(shapes)

fig = ps.Figure(0, 12, 0, 12, backend=MatplotlibBackend)
fig.add(model)
fig.show()
Exemple #10
0
import pysketcher as ps
from pysketcher.backend.matplotlib import MatplotlibBackend

R = 1  # radius of wheel
L = 4  # distance between wheels
H = 2  # height of vehicle body
w_1 = 5  # position of front wheel

# TODO : draw grids
# drawing_tool.set_grid(True)

c = ps.Point(w_1, R)

wheel1 = ps.Circle(c, R)
wheel2 = wheel1.translate(ps.Point(L, 0))
under = ps.Rectangle(ps.Point(w_1 - 2 * R, 2 * R), 2 * R + L + 2 * R, H)
over = ps.Rectangle(ps.Point(w_1, 2 * R + H), 2.5 * R,
                    1.25 * H).set_fill_color(ps.Style.Color.WHITE)
ground = ps.Wall([ps.Point(w_1 - L, 0), ps.Point(w_1 + 3 * L, 0)], -0.3 * R)
ground.style.fill_pattern = ps.Style.FillPattern.UP_RIGHT_TO_LEFT

vehicle = ps.Composition({
    "wheel1": wheel1,
    "wheel2": wheel2,
    "under": under,
    "over": over,
    "ground": ground
})

vehicle.style.line_color = ps.Style.Color.RED
    )
    d = d.rotate(-np.pi / 2, d_start)
    return d


def make_spring(x):
    s_start = ps.Point(-L, 4 * H)
    s = ps.Spring(start=s_start, length=L + x, bar_length=3 * H / 2)
    s = s.rotate(-np.pi / 2, s_start)
    return s


d = make_dashpot(0)
s = make_spring(0)

M = ps.Rectangle(ps.Point(0, H), 4 * H, 4 * H).set_line_width(4)
left_wall = ps.Rectangle(ps.Point(-L, 0), H / 10, L).set_fill_pattern(
    ps.Style.FillPattern.UP_LEFT_TO_RIGHT
)
ground = ps.Wall([ps.Point(-L / 2, 0), ps.Point(L, 0)], thickness=-H / 10)
wheel1 = ps.Circle(ps.Point(H, H / 2), H / 2)
wheel2 = wheel1.translate(ps.Point(2 * H, 0))

fontsize = 24
text_m = ps.Text("$m$", ps.Point(2 * H, H + 2 * H))
text_m.style.font_size = fontsize
text_ku = ps.Text("$ku$", ps.Point(-L / 2, H + 4 * H))
text_ku.style.font_size = fontsize
text_bv = ps.Text("$bu'$", ps.Point(-L / 2, H))
text_bv.style.font_size = fontsize
x_axis = ps.Axis(ps.Point(2 * H, L), H, "$u(t)$", label_spacing=(0.04, -0.01))