How to use the ezdxf.math.Matrix44.translate function in ezdxf

To help you get started, we’ve selected a few ezdxf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozman / ezdxf / tests / test_02_dxf_graphics / test_242_random_transform.py View on Github external
def test_apply_transformation_multiple_times(sx, sy, sz, doc1: 'Drawing'):
    def insert():
        return Insert.new(dxfattribs={
            'name': 'AXIS',
            'insert': (0, 0, 0),
            'xscale': 1,
            'yscale': 1,
            'zscale': 1,
            'rotation': 0,
        }, doc=doc1), [(0, 0, 0), X_AXIS, Y_AXIS, Z_AXIS]

    entity, vertices = insert()
    m = Matrix44.chain(
        Matrix44.scale(sx, sy, sz),
        Matrix44.z_rotate(math.radians(10)),
        Matrix44.translate(1, 1, 1),
    )

    for i in range(5):
        entity, vertices = synced_transformation(entity, vertices, m)
        points = list(vertices)
        for num, line in enumerate(entity.virtual_entities()):
            assert points[0].isclose(line.dxf.start, abs_tol=1e-9)
            assert points[num + 1].isclose(line.dxf.end, abs_tol=1e-9)
github mozman / ezdxf / tests / test_02_dxf_graphics / test_242_transform.py View on Github external
def test_spline_transform_interface():
    spline = Spline()
    spline.set_uniform([(1, 0, 0), (3, 3, 0), (6, 0, 1)])
    spline.dxf.start_tangent = Vector(1, 0, 0)
    spline.dxf.end_tangent = Vector(2, 0, 0)
    spline.dxf.extrusion = Vector(3, 0, 0)
    spline.transform(Matrix44.translate(1, 2, 3))
    assert spline.control_points[0] == (2, 2, 3)
    # direction vectors are not transformed by translation
    assert spline.dxf.start_tangent == (1, 0, 0)
    assert spline.dxf.end_tangent == (2, 0, 0)
    assert spline.dxf.extrusion == (3, 0, 0)
github mozman / ezdxf / tests / test_02_dxf_graphics / test_226_spline.py View on Github external
def test_spline_transform_interface():
    spline = Spline()
    spline.set_uniform([(1, 0, 0), (3, 3, 0), (6, 0, 1)])
    spline.dxf.start_tangent = Vector(1, 0, 0)
    spline.dxf.end_tangent = Vector(2, 0, 0)
    spline.dxf.extrusion = Vector(3, 0, 0)
    spline.transform(Matrix44.translate(1, 2, 3))
    assert spline.control_points[0] == (2, 2, 3)
    # direction vectors are not transformed by translation
    assert spline.dxf.start_tangent == (1, 0, 0)
    assert spline.dxf.end_tangent == (2, 0, 0)
    assert spline.dxf.extrusion == (3, 0, 0)
github mozman / ezdxf / tests / test_02_dxf_graphics / test_242_transform.py View on Github external
def test_circle_default_ocs():
    circle = Circle.new(dxfattribs={'center': (2, 3, 4), 'thickness': 2})
    # 1. rotation - 2. scaling - 3. translation
    m = Matrix44.chain(Matrix44.scale(2, 2, 3), Matrix44.translate(1, 1, 1))
    # default extrusion is (0, 0, 1), therefore scale(2, 2, ..) is a uniform scaling in the xy-play of the OCS
    circle.transform(m)

    assert circle.dxf.center == (5, 7, 13)
    assert circle.dxf.extrusion == (0, 0, 1)
    assert circle.dxf.thickness == 6
github mozman / ezdxf / examples / transformation_workbench.py View on Github external
def synced_translation(entity, chk, axis_vertices=None, dx: float = 0, dy: float = 0, dz: float = 0):
    entity = entity.copy()
    entity.translate(dx, dy, dz)
    m = Matrix44.translate(dx, dy, dz)
    chk = list(m.transform_vertices(chk))
    if axis_vertices:
        axis_vertices = list(m.transform_vertices(axis_vertices))
        return entity, chk, axis_vertices
    return entity, chk
github mozman / ezdxf / examples / render / render_ellipse.py View on Github external
def tmatrix(x, y, angle):
    return Matrix44.chain(
        Matrix44.z_rotate(radians(angle)),
        Matrix44.translate(x, y, 0),
    )
github mozman / ezdxf / src / ezdxf / addons / drawing / text.py View on Github external
line_widths = [out.get_text_line_width(line, cap_height, font=font) for line in lines]
    font_measurements = out.get_font_measurements(cap_height, font=font)
    anchor, line_xs, line_ys = \
        _apply_alignment(alignment, line_widths, cap_height, line_spacing, box_width, font_measurements)
    rotation = _get_rotation(text)
    extra_transform = _get_extra_transform(text)
    insert = _get_wcs_insert(text)

    whole_text_transform = (
            Matrix44.translate(-anchor[0], -anchor[1], 0) @
            extra_transform @
            rotation @
            Matrix44.translate(*insert.xyz)
    )
    for i, (line, line_x, line_y) in enumerate(zip(lines, line_xs, line_ys)):
        transform = Matrix44.translate(line_x, line_y, 0) @ whole_text_transform
        yield line, transform, cap_height

        if debug_draw_rect:
            width = out.get_text_line_width(line, cap_height)
            ps = list(transform.transform_vertices([Vector(0, 0, 0), Vector(width, 0, 0), Vector(width, cap_height, 0),
                                                    Vector(0, cap_height, 0), Vector(0, 0, 0)]))
            for a, b in zip(ps, ps[1:]):
                out.draw_line(a, b, '#ff0000')