예제 #1
0
    def matrix44(self) -> Matrix44:
        """Returns a transformation matrix of type :class:`Matrix44` to
        transform the block entities into :ref:`WCS`.

        """
        dxf = self.dxf
        sx = dxf.xscale
        sy = dxf.yscale
        sz = dxf.zscale

        ocs = self.ocs()
        extrusion = ocs.uz
        ux = Vec3(ocs.to_wcs(X_AXIS))
        uy = Vec3(ocs.to_wcs(Y_AXIS))
        m = Matrix44.ucs(ux=ux * sx, uy=uy * sy, uz=extrusion * sz)
        # same as Matrix44.ucs(ux, uy, extrusion) * Matrix44.scale(sx, sy, sz)

        angle = math.radians(dxf.rotation)
        if angle:
            m *= Matrix44.axis_rotate(extrusion, angle)

        insert = ocs.to_wcs(dxf.get("insert", NULLVEC))

        block_layout = self.block()
        if block_layout is not None:
            # transform block base point into WCS without translation
            insert -= m.transform_direction(
                block_layout.block.dxf.base_point)  # type: ignore

        # set translation
        m.set_row(3, insert.xyz)  # type: ignore
        return m
예제 #2
0
    def matrix44(self) -> Matrix44:
        """ Returns a transformation :class:`Matrix44` object to transform block
        entities into WCS.

        .. versionadded:: 0.13

        """
        dxf = self.dxf
        sx = dxf.xscale
        sy = dxf.yscale
        sz = dxf.zscale

        ocs = self.ocs()
        extrusion = ocs.uz
        ux = Vector(ocs.to_wcs(X_AXIS))
        uy = Vector(ocs.to_wcs(Y_AXIS))
        m = Matrix44.ucs(ux=ux * sx, uy=uy * sy, uz=extrusion * sz)

        angle = math.radians(dxf.rotation)
        if angle != 0.0:
            m = Matrix44.chain(m, Matrix44.axis_rotate(extrusion, angle))

        insert = ocs.to_wcs(dxf.get('insert', Vector()))

        block_layout = self.block()
        if block_layout is not None:
            # transform block base point into WCS without translation
            insert -= m.transform_direction(block_layout.block.dxf.base_point)

        # set translation
        m.set_row(3, insert.xyz)
        return m
예제 #3
0
파일: ucs.py 프로젝트: Rahulghuge94/ezdxf
    def __init__(
        self,
        origin: "Vertex" = (0, 0, 0),
        ux: "Vertex" = None,
        uy: "Vertex" = None,
        uz: "Vertex" = None,
    ):
        if ux is None and uy is None:
            _ux: Vec3 = X_AXIS
            _uy: Vec3 = Y_AXIS
            _uz: Vec3 = Z_AXIS
        elif ux is None:
            _uy = Vec3(uy).normalize()
            _uz = Vec3(uz).normalize()
            _ux = Vec3(uy).cross(uz).normalize()
        elif uy is None:
            _ux = Vec3(ux).normalize()
            _uz = Vec3(uz).normalize()
            _uy = Vec3(uz).cross(ux).normalize()
        elif uz is None:
            _ux = Vec3(ux).normalize()
            _uy = Vec3(uy).normalize()
            _uz = Vec3(ux).cross(uy).normalize()
        else:  # all axis are given
            _ux = Vec3(ux).normalize()
            _uy = Vec3(uy).normalize()
            _uz = Vec3(uz).normalize()

        self.matrix: Matrix44 = Matrix44.ucs(_ux, _uy, _uz, Vec3(origin))
예제 #4
0
    def __init__(self,
                 origin: 'Vertex' = (0, 0, 0),
                 ux: 'Vertex' = None,
                 uy: 'Vertex' = None,
                 uz: 'Vertex' = None):
        if ux is None and uy is None:
            ux = X_AXIS
            uy = Y_AXIS
            uz = Z_AXIS
        elif ux is None:
            uy = Vec3(uy).normalize()
            uz = Vec3(uz).normalize()
            ux = Vec3(uy).cross(uz).normalize()
        elif uy is None:
            ux = Vec3(ux).normalize()
            uz = Vec3(uz).normalize()
            uy = Vec3(uz).cross(ux).normalize()
        elif uz is None:
            ux = Vec3(ux).normalize()
            uy = Vec3(uy).normalize()
            uz = Vec3(ux).cross(uy).normalize()
        else:  # all axis are given
            ux = Vec3(ux).normalize()
            uy = Vec3(uy).normalize()
            uz = Vec3(uz).normalize()

        self.matrix: Matrix44 = Matrix44.ucs(ux, uy, uz, origin)
예제 #5
0
def test_matrix44_to_ocs():
    ocs = OCS(EXTRUSION)
    matrix = Matrix44.ucs(ocs.ux, ocs.uy, ocs.uz)
    assert is_close_points(
        matrix.ocs_from_wcs(Vector(-9.56460754, 8.44764172, 9.97894327)),
        (9.41378764657076, 13.15481838975576, 0.8689258932616031),
        places=6,
    )
예제 #6
0
def test_matrix44_to_wcs():
    ocs = OCS(EXTRUSION)
    matrix = Matrix44.ucs(ocs.ux, ocs.uy, ocs.uz)
    matrix.transpose()
    assert is_close_points(
        matrix.transform(
            (9.41378764657076, 13.15481838975576, 0.8689258932616031)),
        (-9.56460754, 8.44764172, 9.97894327),
        places=6,
    )
예제 #7
0
파일: ucs.py 프로젝트: Rahulghuge94/ezdxf
 def __init__(self, extrusion: "Vertex" = Z_AXIS):
     Az = Vec3(extrusion).normalize()
     self.transform = not Az.isclose(Z_AXIS)
     if self.transform:
         if (abs(Az.x) < _1_OVER_64) and (abs(Az.y) < _1_OVER_64):
             Ax = Y_AXIS.cross(Az)
         else:
             Ax = Z_AXIS.cross(Az)
         Ax = Ax.normalize()
         Ay = Az.cross(Ax).normalize()
         self.matrix = Matrix44.ucs(Ax, Ay, Az)
예제 #8
0
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))
예제 #9
0
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