コード例 #1
0
def test_non_uniformed_scaled_ucs():
    ucs = UCS(origin=(3, 2, 1)).scale(1.5, 2.5, 3.5)
    assert ucs.is_cartesian is True
    assert ucs.to_wcs((0, 0, 0)) == (3, 2, 1)
    assert ucs.to_wcs((1, 0, 0)) == (4.5, 2, 1)
    assert ucs.to_wcs((0, 1, 0)) == (3, 4.5, 1)
    assert ucs.to_wcs((0, 0, 1)) == (3, 2, 4.5)
コード例 #2
0
def test_uniformed_scaled_ucs():
    ucs = UCS(origin=(1, 2, 3)).scale(2, 2, 2)
    assert ucs.is_cartesian is True
    assert ucs.to_wcs((0, 0, 0)) == (1, 2, 3)
    assert ucs.to_wcs((1, 0, 0)) == (3, 2, 3)
    assert ucs.to_wcs((0, 1, 0)) == (1, 4, 3)
    assert ucs.to_wcs((0, 0, 1)) == (1, 2, 5)
コード例 #3
0
def test_non_uniformed_scaled_ucs_at_origin():
    ucs = UCS().scale(1.5, 2.5, 3.5)
    assert ucs.is_cartesian is True
    assert ucs.to_wcs((0, 0, 0)) == (0, 0, 0)
    assert ucs.to_wcs((1, 0, 0)) == (1.5, 0, 0)
    assert ucs.to_wcs((0, 1, 0)) == (0, 2.5, 0)
    assert ucs.to_wcs((0, 0, 1)) == (0, 0, 3.5)
コード例 #4
0
def test_uniformed_scaled_ucs_at_origin():
    ucs = UCS().scale(2, 2, 2)
    assert ucs.is_cartesian is True
    assert ucs.to_wcs((0, 0, 0)) == (0, 0, 0)
    assert ucs.to_wcs((1, 0, 0)) == (2, 0, 0)
    assert ucs.to_wcs((0, 1, 0)) == (0, 2, 0)
    assert ucs.to_wcs((0, 0, 1)) == (0, 0, 2)
コード例 #5
0
def test_points_from_wcs():
    points = Vec3.list([(1, 2, 3), (3, 4, 5)])
    ucs = PassTroughUCS()
    assert list(ucs.points_from_wcs(points)) == points

    ucs2 = UCS()
    assert list(ucs.points_from_wcs(points)) == list(ucs2.points_from_wcs(points))
コード例 #6
0
ファイル: test_ucs.py プロジェクト: suffrajet/ezdxf
def test_translation():
    ucs = UCS(origin=(3, 4, 5))
    assert ucs.origin == (3, 4, 5)
    assert ucs.ux == (1, 0, 0)
    assert ucs.uy == (0, 1, 0)
    assert ucs.uz == (0, 0, 1)
    assert ucs.from_wcs((3, 4, 5)) == (0, 0, 0)
    assert ucs.to_wcs((1, 1, 1)) == (4, 5, 6)
コード例 #7
0
def test_from_wcs():
    ucs = PassTroughUCS()
    assert ucs.from_wcs((1, 2, 3)) == Vec3(1, 2, 3)
    assert ucs.from_wcs((3, 4, 5)) == Vec3(3, 4, 5)

    ucs2 = UCS()
    assert ucs.from_wcs((1, 2, 3)) == ucs2.from_wcs(Vec3(1, 2, 3))
    assert ucs.from_wcs((3, 4, 5)) == ucs2.from_wcs(Vec3(3, 4, 5))
コード例 #8
0
 def ucs(self):
     """ Returns the block reference coordinate system as
     :class:`ezdxf.math.UCS` object.
     """
     m = self.matrix44()
     ucs = UCS()
     ucs.matrix = m
     return ucs
コード例 #9
0
ファイル: line.py プロジェクト: k3rn3l3rr0r/ezdxf
    def transform_to_wcs(self, ucs: UCS) -> None:
        """ Transform LINE entity from local :class:`~ezdxf.math.UCS` coordinates to
        :ref:`WCS` coordinates.

        .. versionadded:: 0.11

        """
        self.dxf.start = ucs.to_wcs(self.dxf.start)
        self.dxf.end = ucs.to_wcs(self.dxf.end)
コード例 #10
0
ファイル: test_ucs.py プロジェクト: suffrajet/ezdxf
def test_ucs_init():
    ucs = UCS()
    assert ucs.origin == (0, 0, 0)
    assert ucs.ux == (1, 0, 0)
    assert ucs.uy == (0, 1, 0)
    assert ucs.uz == (0, 0, 1)

    assert ucs.from_wcs((3, 4, 5)) == (3, 4, 5)
    assert ucs.to_wcs((5, 4, 3)) == (5, 4, 3)
コード例 #11
0
ファイル: test_611_ucs.py プロジェクト: Rahulghuge94/ezdxf
def test_rotate_local_z():
    ucs = UCS()
    assert ucs.ux == (1, 0, 0)  # WCS x-axis
    assert ucs.uy == (0, 1, 0)  # WCS y-axis
    assert ucs.uz == (0, 0, 1)  # WCS z-axis
    ucs = ucs.rotate_local_z(pi / 2)
    assert ucs.ux.isclose((0, 1, 0))  # WCS y-axis
    assert ucs.uy.isclose((-1, 0, 0))  # WCS -x-axis
    assert ucs.uz.isclose((0, 0, 1))  # WCS z-axis
コード例 #12
0
ファイル: test_ucs.py プロジェクト: suffrajet/ezdxf
def test_arbitrary_ucs():
    origin = Vector(3, 3, 3)
    ux = Vector(1, 2, 0)
    def_point_in_xy_plane = Vector(3, 10, 4)
    uz = ux.cross(def_point_in_xy_plane - origin)
    ucs = UCS(origin=origin, ux=ux, uz=uz)
    def_point_in_ucs = ucs.from_wcs(def_point_in_xy_plane)
    assert def_point_in_ucs.z == 0
    assert ucs.to_wcs(def_point_in_ucs) == def_point_in_xy_plane
    assert ucs.is_cartesian is True
コード例 #13
0
def scene1(filename):
    doc = ezdxf.new('R2010', setup=True)
    msp = doc.modelspace()

    ucs = UCS()
    angle = math.pi / 12  # 15 degree

    for ix in range(X_COUNT):
        for iy in range(Y_COUNT):
            ucs.moveto((ix * DX, iy * DY, 0))
            ucs.render_axis(msp, length=1)
            add_circle(msp, ucs)
            # add_ocs_circle(msp, ucs)
            # add_ocs_arc(msp, ucs)
            # add_text(msp, ucs)
            add_mtext(msp, ucs)
            add_ellipse(msp, ucs)
            # add_solid(msp, ucs)
            add_trace(msp, ucs)
            # add_3dface(msp, ucs)
            # add_lwpolyline(msp, ucs)
            ucs = ucs.rotate_local_z(angle)
        ucs = UCS().rotate_local_x(ix * angle)

    doc.set_modelspace_vport(Y_COUNT * (DY + 2),
                             center=(X_COUNT * DX / 2, Y_COUNT * DY / 2))
    doc.saveas(filename)
コード例 #14
0
def test_points_to_wcs():
    ucs = PassTroughUCS()
    assert list(ucs.points_to_wcs([(1, 2, 3), (3, 4, 5)])) == [
        Vec3(1, 2, 3),
        Vec3(3, 4, 5),
    ]

    ucs2 = UCS()
    assert list(ucs.points_to_wcs([
        (1, 2, 3), (3, 4, 5)
    ])) == list(ucs2.points_to_wcs([(1, 2, 3), (3, 4, 5)]))
コード例 #15
0
def test_ocs_points_to_ocs():
    ucs = UCS(ux=(0, 0, -1), uz=(1, 0, 0))
    points = [(1, 2, 3), (4, 5, 6), (9, 8, 7)]
    # tests only the actual state - as it is - not granted results are correct
    expected = [
        Vector(-1.4547842173342707, 1.6981174520612865, 3),
        Vector(-3.0545253372991867, 5.6275993961721635, 6),
        Vector(-3.8776861825487807, 11.400155694974972, 7),
    ]
    result = list(ucs.ocs_points_to_ocs(points, extrusion=Vector(2, 4, 7)))
    assert result == expected
コード例 #16
0
ファイル: test_611_ucs.py プロジェクト: Rahulghuge94/ezdxf
def test_matrix44_rotation():
    # normalization is not necessary
    ux = Vec3(1, 2, 0)
    # only cartesian coord systems work
    uy = ux.rotate_deg(90)
    ucs = UCS(ux=ux, uy=uy)
    m = Matrix44.ucs(ux=ux.normalize(), uy=uy.normalize())
    assert m.ux == ux.normalize()
    assert m.uy == uy.normalize()
    assert m.uz == (0, 0, 1)
    assert m.is_cartesian
    v = m.transform((1, 2, 3))
    assert v == ucs.to_wcs((1, 2, 3))
    assert m.ucs_vertex_from_wcs(v).isclose((1, 2, 3))
コード例 #17
0
ファイル: test_611_ucs.py プロジェクト: Rahulghuge94/ezdxf
def test_transformation():
    axis = Vec3.random()
    angle = 1.5
    ucs = UCS(origin=(3, 4, 5))
    m = Matrix44.axis_rotate(axis, angle)
    expected_origin = m.transform(ucs.origin)
    expected_ux = m.transform(ucs.ux)
    expected_uy = m.transform(ucs.uy)
    expected_uz = m.transform(ucs.uz)
    new = ucs.transform(m)

    assert new.origin.isclose(expected_origin)
    assert new.ux.isclose(expected_ux)
    assert new.uy.isclose(expected_uy)
    assert new.uz.isclose(expected_uz)
コード例 #18
0
ファイル: test_611_ucs.py プロジェクト: Rahulghuge94/ezdxf
def test_ucs_direction_to_ocs_direction():
    ucs = UCS.from_x_axis_and_point_in_xy(origin=(1, 2, 3),
                                          axis=(2, 3, 4),
                                          point=(3, 2, 5))
    assert ucs.is_cartesian is True
    expected = (-3.350073025395333, 2.9626020192591795, 6)
    assert ucs.ucs_direction_to_ocs_direction(Vec3(2, 4, 6)).isclose(expected)
コード例 #19
0
ファイル: dimension_linear.py プロジェクト: yening2020/ezdxf
def example_for_all_text_placings_in_space_R2007():
    ucs = UCS(origin=(20, 20, 0)).rotate_local_x(
        math.radians(45)).rotate_local_z(math.radians(45))
    doc = ezdxf.new('R2007', setup=True)
    set_text_style(doc)
    example_for_all_text_placings(
        doc, 'dim_linear_text_placing_in_space_R2007.dxf', ucs)
コード例 #20
0
def test_virtual_entities_elevation(lwpolyline):
    ucs = UCS(origin=(1, 1, 1))
    lwpolyline = lwpolyline.transform_to_wcs(ucs)
    assert lwpolyline.dxf.elevation == 1
    result = list(lwpolyline.virtual_entities())
    assert len(result) == 3
    e = result[0]
    assert e.dxftype() == 'LINE'
    assert e.dxf.start == (1, 1, 1)
    assert e.dxf.end == (2, 1, 1)

    e = result[1]
    assert e.dxftype() == 'ARC'
    assert e.dxf.center == (2.5, 1, 1)
    assert e.dxf.radius == 0.5
    assert math.isclose(e.dxf.start_angle, 180, abs_tol=1e-12)
    assert math.isclose(e.dxf.end_angle, 0, abs_tol=1e-12)

    assert e.start_point.isclose((2, 1, 1))
    assert e.end_point.isclose((3, 1, 1))

    e = result[2]
    assert e.dxftype() == 'LINE'
    assert e.dxf.start == (3, 1, 1)
    assert e.dxf.end == (4, 1, 1)
コード例 #21
0
def test_spatial_arc_from_3p():
    start_point_wcs = Vector(0, 1, 0)
    end_point_wcs = Vector(1, 0, 0)
    def_point_wcs = Vector(0, 0, 1)

    ucs = UCS.from_x_axis_and_point_in_xy(origin=def_point_wcs,
                                          axis=end_point_wcs - def_point_wcs,
                                          point=start_point_wcs)
    start_point_ucs = ucs.from_wcs(start_point_wcs)
    end_point_ucs = ucs.from_wcs(end_point_wcs)
    def_point_ucs = Vector(0, 0)

    arc = ConstructionArc.from_3p(start_point_ucs, end_point_ucs,
                                  def_point_ucs)
    dwg = ezdxf.new('R12')
    msp = dwg.modelspace()

    dxf_arc = arc.add_to_layout(msp, ucs)
    assert dxf_arc.dxftype() == 'ARC'
    assert isclose(dxf_arc.dxf.radius, 0.81649658, abs_tol=1e-9)
    assert isclose(dxf_arc.dxf.start_angle, -30)  # ???
    assert isclose(dxf_arc.dxf.end_angle, -150)  # ???
    assert is_close_points(dxf_arc.dxf.extrusion,
                           (0.57735027, 0.57735027, 0.57735027),
                           abs_tol=1e-9)
コード例 #22
0
 def ucs(self) -> UCS:
     """ Returns an :class:`ezdxf.math.UCS` object for this UCS table entry. """
     return UCS(
         origin=self.dxf.origin,
         ux=self.dxf.xaxis,
         uy=self.dxf.yaxis,
     )
コード例 #23
0
def test_angles_to_ocs_deg():
    ucs = UCS.from_x_axis_and_point_in_xy(origin=(1, 2, 3),
                                          axis=(2, 3, 4),
                                          point=(3, 2, 5))
    angles = [15, 30, 90]
    expected = [ucs.to_ocs_angle_deg(a) for a in angles]
    result = ucs.angles_to_ocs_deg(angles)
    assert result == expected
コード例 #24
0
def test_vertext_array_transform_to_wcs():
    vertices = VertexArray()
    vertices.extend([(0, 0, 0), (1, 0, 0), (1, 1, 0)])
    ucs = UCS(origin=(0, 0, 1))
    vertices.transform_to_wcs(ucs)
    assert vertices[0] == (0, 0, 1)
    assert vertices[1] == (1, 0, 1)
    assert vertices[2] == (1, 1, 1)
コード例 #25
0
ファイル: test_611_ucs.py プロジェクト: Rahulghuge94/ezdxf
def test_arbitrary_ucs():
    origin = Vec3(3, 3, 3)
    ux = Vec3(1, 2, 0)
    def_point_in_xy_plane = Vec3(3, 10, 4)
    uz = ux.cross(def_point_in_xy_plane - origin)
    ucs = UCS(origin=origin, ux=ux, uz=uz)
    m = Matrix44.ucs(ucs.ux, ucs.uy, ucs.uz, ucs.origin)
    def_point_in_ucs = ucs.from_wcs(def_point_in_xy_plane)

    assert ucs.ux == m.ux
    assert ucs.uy == m.uy
    assert ucs.uz == m.uz
    assert ucs.origin == m.origin

    assert def_point_in_ucs == m.ucs_vertex_from_wcs(def_point_in_xy_plane)
    assert def_point_in_ucs.z == 0
    assert ucs.to_wcs(def_point_in_ucs).isclose(def_point_in_xy_plane)
    assert ucs.is_cartesian is True
コード例 #26
0
def test_ocs_angles_to_ocs_deg():
    ucs = UCS.from_x_axis_and_point_in_xy(origin=(1, 2, 3),
                                          axis=(2, 3, 4),
                                          point=(3, 2, 5))
    angles = [15, 30, 90]
    # tests only the actual state - as it is - not granted results are correct
    expected = [-128.92976741554182, -113.92976741554183, -53.929767415541825]
    result = ucs.ocs_angles_to_ocs_deg(angles, extrusion=Vector(1, 2, 3))
    assert result == expected
コード例 #27
0
    def _ucs_and_ocs_transformation(self, ucs: UCS, vector_names: Sequence, angle_names: Sequence = None) -> None:
        """ Transforms entity for given `ucs` to the parent coordinate system (most likely the WCS).

        Transforms the entity vectors and angles attributes from `ucs` to the parent coordinate system.
        Takes established OCS by the extrusion vector :attr:`dxf.extrusion` into account.

        """
        extrusion = self.dxf.extrusion
        vectors = (self.dxf.get_default(name) for name in vector_names)
        ocs_vectors = ucs.ocs_points_to_ocs(vectors, extrusion=extrusion)
        for name, value in zip(vector_names, ocs_vectors):
            self.dxf.set(name, value)
        if angle_names is not None:
            angles = (self.dxf.get_default(name) for name in angle_names)
            ocs_angles = ucs.ocs_angles_to_ocs_deg(angles=angles, extrusion=extrusion)
            for name, value in zip(angle_names, ocs_angles):
                self.dxf.set(name, value)
        self.dxf.extrusion = ucs.direction_to_wcs(extrusion)
コード例 #28
0
ファイル: test_ucs.py プロジェクト: suffrajet/ezdxf
def test_rotation():
    # normalization is not necessary
    ux = Vector(1, 2, 0)
    # only cartesian coord systems work
    uy = ux.rotate_deg(90)
    ucs = UCS(ux=ux, uy=uy)
    assert ucs.ux == ux.normalize()
    assert ucs.uy == uy.normalize()
    assert ucs.uz == (0, 0, 1)
    assert ucs.is_cartesian is True
コード例 #29
0
ファイル: mtext.py プロジェクト: Rahulghuge94/ezdxf
    def ucs(self) -> UCS:
        """Returns the :class:`~ezdxf.math.UCS` of the :class:`MText` entity,
        defined by the insert location (origin), the text direction or rotation
        (x-axis) and the extrusion vector (z-axis).

        """
        dxf = self.dxf
        return UCS(
            origin=dxf.insert,
            ux=self.get_text_direction(),
            uz=dxf.extrusion,
        )
コード例 #30
0
def setup_csys(blk, size=3):
    # draw axis
    blk.add_line((0, 0), (size, 0), dxfattribs={'color': RED})  # x-axis
    blk.add_line((0, 0), (0, size), dxfattribs={'color': GREEN})  # y-axis
    blk.add_line((0, 0), (0, 0, size), dxfattribs={'color': BLUE})  # z-axis

    # place text
    size2 = size / 2
    txt_props = {
        'style': 'OpenSans',
        'height': size / 2,
        'color': RED,
    }
    # XY-plane text
    blk.add_text('XY', dxfattribs=txt_props).set_pos((size2, size2),
                                                     align='MIDDLE_CENTER')

    # YZ-plane text
    ucs = UCS(ux=(0, 1, 0), uy=(0, 0, 1))
    txt_props['extrusion'] = ucs.uz
    txt_props['color'] = GREEN
    blk.add_text('YZ', dxfattribs=txt_props).set_pos(ucs.to_ocs(
        (size2, size2)),
                                                     align='MIDDLE_CENTER')

    # XZ-plane text
    ucs = UCS(ux=(1, 0, 0), uy=(0, 0, 1))
    txt_props['extrusion'] = ucs.uz
    txt_props['color'] = BLUE
    txt_props['text_generation_flag'] = MIRROR_X
    blk.add_text('XZ', dxfattribs=txt_props).set_pos(ucs.to_ocs(
        (size2, size2)),
                                                     align='MIDDLE_CENTER')