How to use the ezdxf.math.vector.Vector 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_06_math / test_602_vector.py View on Github external
def test_angle_between():
    v1 = Vector(0, 1)
    v2 = Vector(1, 1)
    angle = v1.angle_between(v2)
    assert math.isclose(angle, math.pi / 4)
    # reverse order, same result
    angle = v2.angle_between(v1)
    assert math.isclose(angle, math.pi / 4)
    angle = v1.angle_between(Vector(0, -1))
    assert math.isclose(angle, math.pi)
github mozman / ezdxf / tests / test_06_math / test_602_vector.py View on Github external
def test_normalize():
    v = Vector(2, 0, 0)
    assert v.normalize() == (1, 0, 0)
github mozman / ezdxf / tests / test_06_math / test_602_vector.py View on Github external
def test_compare_vectors():
    v1 = Vector(1, 2, 3)
    assert v1 == (1, 2, 3)
    assert (1, 2, 3) == v1

    v2 = Vector(2, 3, 4)
    assert v2 > v1
    assert v1 < v2
github mozman / ezdxf / tests / test_00_dxf_low_level_structs / test_042_tags_loader.py View on Github external
def test_strtag2_vector():
    assert ' 10\n1.0\n 20\n2.0\n 30\n3.0\n' == DXFVertex(10, Vector(1, 2, 3)).dxfstr()
    assert ' 10\n1.0\n 20\n2.0\n 30\n3.0\n' == DXFVertex(10, Vector((1, 2, 3))).dxfstr()
    assert ' 10\n1.0\n 20\n2.0\n 30\n0.0\n' == DXFVertex(10, Vector(1, 2)).dxfstr()
    assert ' 10\n1.0\n 20\n2.0\n 30\n0.0\n' == DXFVertex(10, Vector((1, 2))).dxfstr()
github mozman / ezdxf / tests / test_06_math / test_602_vector.py View on Github external
def test_xy():
    assert Vector(1, 2, 3).xy == Vector(1, 2)
github mozman / ezdxf / tests / test_06_math / test_602_vector.py View on Github external
def test_angle_about():
    extrusion = Vector(0, 0, 1)
    a = Vector(1, 0, 0)
    b = Vector(1, 1, 0)
    assert math.isclose(a.angle_between(b), math.pi / 4)
    assert math.isclose(extrusion.angle_about(a, b), math.pi / 4)

    extrusion = Vector(0, 0, -1)
    assert math.isclose(a.angle_between(b), math.pi / 4)
    assert math.isclose(extrusion.angle_about(a, b), (-math.pi / 4) % math.tau)

    extrusion = Vector(0, 0, 1)
    a = Vector(1, 1, 0)
    b = Vector(1, 1, 0)
    assert math.isclose(a.angle_between(b), 0, abs_tol=1e-5)
    assert math.isclose(extrusion.angle_about(a, b), 0)

    extrusion = Vector(0, 1, 0)
    a = Vector(1, 1, 0)
    b = Vector(0, 1, -1)
    assert math.isclose(a.angle_between(b), math.pi / 3, abs_tol=1e-5)
    c = a.cross(b)
    assert math.isclose(a.angle_between(b), c.angle_about(a, b))
    assert math.isclose(extrusion.angle_about(a, b), math.pi / 2)
github mozman / ezdxf / tests / test_06_math / test_612_ucs_pass_trough.py View on Github external
def test_to_ocs():
    ucs = PassTroughUCS()
    assert ucs.to_ocs((1, 2, 3)) == Vector(1, 2, 3)
    assert ucs.to_ocs((3, 4, 5)) == Vector(3, 4, 5)
github mozman / ezdxf / tests / test_00_dxf_low_level_structs / test_042_tags_loader.py View on Github external
def test_strtag2_vector():
    assert ' 10\n1.0\n 20\n2.0\n 30\n3.0\n' == DXFVertex(10, Vector(1, 2, 3)).dxfstr()
    assert ' 10\n1.0\n 20\n2.0\n 30\n3.0\n' == DXFVertex(10, Vector((1, 2, 3))).dxfstr()
    assert ' 10\n1.0\n 20\n2.0\n 30\n0.0\n' == DXFVertex(10, Vector(1, 2)).dxfstr()
    assert ' 10\n1.0\n 20\n2.0\n 30\n0.0\n' == DXFVertex(10, Vector((1, 2))).dxfstr()
github mozman / ezdxf / tests / test_06_math / test_602_vector.py View on Github external
def test_cross_product():
    v1 = Vector(2, 7, 9)
    v2 = Vector(3, 9, 1)
    assert v1.cross(v2) == (-74, 25, -3)
github mozman / ezdxf / src / ezdxf / addons / dimlines.py View on Github external
def _build_vectors(self) -> None:
        """ build unit vectors, parallel and normal to dimension line """
        point1, point2 = self._get_dimline_bounds()
        self.parallel_vector = (Vector(point2) - Vector(point1)).normalize()
        self.normal_vector = self.parallel_vector.orthogonal()