예제 #1
0
 def matrix(self):
     return Matrix44.chain(
         Matrix44.x_rotate(0.75),
         Matrix44.translate(2, 3, 4),
     )
예제 #2
0
def test_transform_interface():
    curve = Bezier(DEFPOINTS3D)
    new = curve.transform(Matrix44.translate(1, 2, 3))
    assert new.control_points[0] == curve.control_points[0] + (1, 2, 3)
예제 #3
0
def tmatrix(x, y, angle):
    return Matrix44.chain(
        Matrix44.z_rotate(radians(angle)),
        Matrix44.translate(x, y, 0),
    )
예제 #4
0
def m44():
    return Matrix44.chain(
        Matrix44.z_rotate(math.pi / 2),
        Matrix44.translate(1, 2, 0),
    )
예제 #5
0
 def test_translate(self, msp):
     mline = msp.add_mline([(0, 5), (10, 5)])
     m = Matrix44.translate(1, 1, 1)
     mline.transform(m)
     assert mline.start_location().isclose((1, 6, 1))
     assert mline.dxf.scale_factor == 1
예제 #6
0
def test_transform_interface():
    curve = Bezier4P(DEFPOINTS3D)
    new = curve.transform(Matrix44.translate(1, 2, 3))
    assert new.control_points[0] == Vector(DEFPOINTS3D[0]) + (1, 2, 3)
    assert new.control_points[0] != curve.control_points[
        0], 'expected a new object'
예제 #7
0
    (1, 0, 1),
    (1, 1, 1),
    (0, 1, 1),
]

# 6 cube faces
cube_faces = [
    [0, 3, 2, 1],
    [4, 5, 6, 7],
    [0, 1, 5, 4],
    [1, 2, 6, 5],
    [3, 7, 6, 2],
    [0, 4, 7, 3],
]

doc = ezdxf.new("R2018")
msp = doc.modelspace()
mesh = msp.add_mesh(dxfattribs=GfxAttribs(color=6))
with mesh.edit_data() as mesh_data:
    mesh_data.vertices = cube_vertices
    mesh_data.faces = cube_faces

# Add the same mesh as PolyFaceMesh:
mesh_builder = MeshBuilder.from_mesh(mesh)
mesh_builder.render_polyface(
    msp,
    dxfattribs=GfxAttribs(color=6),
    matrix=Matrix44.translate(5, 0, 0),
)
doc.saveas(DIR / "cube_mesh_1.dxf")
예제 #8
0
def tmatrix(dx, dy, sx=1, sy=1, angle=0):
    return Matrix44.chain(
        Matrix44.scale(sx=sx, sy=sy, sz=1),
        Matrix44.z_rotate(radians(angle)),
        Matrix44.translate(dx, dy, 0),
    )
예제 #9
0
from pathlib import Path

OUT_DIR = Path('~/Desktop/Outbox').expanduser()

doc = ezdxf.new('R2010')
msp = doc.modelspace()

# Using an UCS simplifies 3D operations, but UCS definition can happen later
# calculating corner points in local (UCS) coordinates without Vec3 class
angle = math.radians(360 / 5)
corners_ucs = [(math.cos(angle * n), math.sin(angle * n), 0) for n in range(5)]

# let's do some transformations
tmatrix = Matrix44.chain(  # creating a transformation matrix
    Matrix44.z_rotate(math.radians(15)),  # 1. rotation around z-axis
    Matrix44.translate(0, .333, .333),  # 2. translation
)
transformed_corners_ucs = tmatrix.transform_vertices(corners_ucs)

# transform UCS into WCS
ucs = UCS(
    origin=(0, 2, 2),  # center of pentagon
    ux=(1, 0, 0),  # x-axis parallel to WCS x-axis
    uz=(0, 1, 1),  # z-axis
)
corners_wcs = list(ucs.points_to_wcs(transformed_corners_ucs))

msp.add_polyline3d(
    points=corners_wcs,
    close=True,
)
예제 #10
0
# Purpose: examples for using Spline() add-on
# Created: 09.02.2010, 2018 adapted for ezdxf
# Copyright (c) 2010-2018, Manfred Moitzi
# License: MIT License
import ezdxf
from ezdxf.render import Spline
from ezdxf.math import Vector, Matrix44


next_frame = Matrix44.translate(0, 5, 0)
right_frame = Matrix44.translate(10, 0, 0)

NAME = 'spline.dxf'
dwg = ezdxf.new('R2000')
msp = dwg.modelspace()


def draw(points):
    for point in points:
        msp.add_circle(radius=0.1, center=point, dxfattribs={'color': 1})


spline_points = Vector.list([(1., 1.), (2.5, 3.), (4.5, 2.), (6.5, 4.)])

# fit points
draw(spline_points)
Spline(spline_points).render_as_fit_points(msp, method='distance', dxfattribs={'color': 2})  # curve with definition points as fit points
Spline(spline_points).render_as_fit_points(msp, method='uniform', dxfattribs={'color': 3})
Spline(spline_points).render_as_fit_points(msp, method='centripetal', dxfattribs={'color': 4})  # distance ^ 1/2
Spline(spline_points).render_as_fit_points(msp, method='centripetal', power=1./3., dxfattribs={'color': 6})  # distance ^ 1/3
예제 #11
0
파일: text.py 프로젝트: Rahulghuge94/ezdxf
def simplified_text_chunks(
    text: AnyText,
    out: BackendInterface,
    *,
    font: fonts.FontFace = None,
    debug_draw_rect: bool = False
) -> Iterable[Tuple[str, Matrix44, float]]:
    """Splits a complex text entity into simple chunks of text which can all be
    rendered the same way:
    render the string (which will not contain any newlines) with the given
    cap_height with (left, baseline) at (0, 0) then transform it with the given
    matrix to move it into place.
    """
    alignment = _get_alignment(text)
    box_width = _get_text_width(text)

    cap_height = _get_cap_height(text)
    lines = _split_into_lines(
        text,
        box_width,
        lambda s: out.get_text_line_width(s, cap_height, font=font),
    )
    line_spacing = _get_line_spacing(text, cap_height)
    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, line_spacing, box_width, font_measurements
    )
    rotation = _get_rotation(text)

    # first_line_width is used for TEXT, ATTRIB and ATTDEF stretching
    if line_widths:
        first_line_width = line_widths[0]
    else:  # no text lines -> no output, value is not important
        first_line_width = 1.0

    extra_transform = _get_extra_transform(text, first_line_width)
    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, font)
            ps = list(
                transform.transform_vertices(
                    [
                        Vec3(0, 0, 0),
                        Vec3(width, 0, 0),
                        Vec3(width, cap_height, 0),
                        Vec3(0, cap_height, 0),
                        Vec3(0, 0, 0),
                    ]
                )
            )
            draw_rect(ps, "#ff0000", out)
def test_proxy_entity_is_not_transformable(proxy):
    # Transformation is only for the virtual entities possible!
    with pytest.raises(NotImplementedError):
        proxy.transform(Matrix44.translate(1, 1, 1))
예제 #13
0
def synced_translation(entity, chk, dx, dy, dz):
    entity = entity.copy()
    entity.translate(dx, dy, dz)
    chk = list(Matrix44.translate(dx, dy, dz).transform_vertices(chk))
    return entity, chk
예제 #14
0
def test_transformation_interface(bezier):
    curve = bezier(DEFPOINTS3D)
    new = curve.transform(Matrix44.translate(1, 2, 3))
    assert new.control_points[0] == Vec3(DEFPOINTS3D[0]) + (1, 2, 3)
    assert (new.control_points[0] !=
            curve.control_points[0]), "expected a new object"
예제 #15
0
# Copyright (c) 2018-2021, Manfred Moitzi
# License: MIT License
import ezdxf
from ezdxf.render import R12Spline
from ezdxf.math import Vec3, Matrix44, UCS, OCS

next_frame = Matrix44.translate(0, 7, 0)

NAME = "r12spline.dxf"
SEGMENTS = 40
doc = ezdxf.new("R12")
msp = doc.modelspace()


def draw(points, extrusion=None):
    dxfattribs = {"color": 1}
    if extrusion is not None:
        ocs = OCS(extrusion)
        points = ocs.points_from_wcs(points)
        dxfattribs["extrusion"] = extrusion

    for point in points:
        msp.add_circle(radius=0.1, center=point, dxfattribs=dxfattribs)


spline_points = Vec3.list([
    (8.55, 2.96),
    (8.55, -0.03),
    (2.75, -0.03),
    (2.76, 3.05),
    (4.29, 1.78),
예제 #16
0
 def test_transformation_is_executed(self):
     # Real transformation is just tested once, because Matrix44
     # transformation is tested in 605:
     result = transform_paths([Path((1, 2, 3))],
                              Matrix44.translate(1, 1, 1))
     assert result[0].start == (2, 3, 4)
예제 #17
0
def test_transform_interface():
    from ezdxf.math import Matrix44
    spline = BSpline(control_points=[(1, 0, 0), (3, 3, 0), (6, 0, 1)], order=3)
    spline.transform(Matrix44.translate(1, 2, 3))
    assert spline.control_points[0] == (2, 2, 3)
예제 #18
0
def test_mesh_transform_interface():
    mesh = Mesh()
    mesh.vertices.append(Vec3(1, 2, 3))
    mesh.transform(Matrix44.translate(1, 1, 1))
    assert mesh.vertices[0] == (2, 3, 4)
예제 #19
0
def test_transform_returns_always_3d_curves():
    curve = Bezier4P(DEFPOINTS2D)
    new = curve.transform(Matrix44.translate(1, 2, 3))
    assert len(new.control_points[0]) == 3
예제 #20
0
def matrix(scale=1.0, rotate=0, tx=0, ty=0, tz=0) -> Matrix44:
    return (Matrix44.scale(scale) @ Matrix44.z_rotate(radians(rotate))
            @ Matrix44.translate(tx, ty, tz))