Example #1
0
def test_express_vector_in_frame(example_frames):
    fa, fb, fc = example_frames
    v0 = (1, 3, 0)
    v1 = (2.82843, -1.41421, 0)

    res0 = Vector(v0).express_in_frame(fa, original_frame=fb)
    assert res0.as_array() == pytest.approx(v1, abs=1e-4)
    assert isinstance(res0._a, np.ndarray)

    assert express_vector_in_frame(
        v0, fa, original_frame=fb).as_array() == pytest.approx(v1, abs=1e-4)

    assert Vector(v0).express_in_frame(
        fa, original_frame=fb) == Vector(v0).express_in_frame(
            fa.express_in_frame(fb))
Example #2
0
def example_frames():
    # rotation only from UnitFrame
    fa = frame_wizard(Vector([1, 1, 0]),
                      Vector([1, -1, 0]),
                      "x",
                      "y",
                      origin=[0, 0, 0])
    # translation only from UnitFrame
    fb = frame_wizard(Vector([1, 0, 0]),
                      Vector([0, 1, 0]),
                      "x",
                      "y",
                      origin=[1, 1, 4])
    # rotation and translation from UnitFrame
    fc = frame_wizard(Vector([1, 1, 0]),
                      Vector([1, -1, 0]),
                      "x",
                      "y",
                      origin=[1, 1, 4])
    return fa, fb, fc
Example #3
0
def test_vector_express_in_frame(example_frames):
    fa, fb, fc = example_frames
    v = Vector([1, 1, 3])
    vt = v.express_in_frame(fc)
    assert vt == Vector([math.sqrt(2), 0, -3])
Example #4
0
def test_point_from_vector():
    p = Point(Vector([1, 2, 3]))
    assert p[2] == 3
Example #5
0
def test_vector_from_array():
    p = Vector([1, 2, 3])
    assert p[2] == 3
Example #6
0
def test_vector_from_np_bare_copy():
    a = np.array([1, 2, 3])
    p = Vector.from_array(a, copy=True)
    a[2] = 7
    assert p[2] == 3
Example #7
0
def test_vector_from_tuple():
    p = Vector((1, 2, 3))
    assert p[2] == 3
Example #8
0
def test_manual_frame_creation():
    rot = RotationMatrix.from_euler_angles("xyz", [90, -45, 45], degrees=True)
    vec = Vector([3, 4, 6])
    f = Frame(rotation_matrix=rot, translation_vector=vec)
    assert f.translation == vec
    assert f.rotation == rot
Example #9
0
def test_vector_from_vector():
    p = Vector(Vector([1, 2, 3]))
    assert p[2] == 3
Example #10
0
def test_vector_from_point():
    p = Vector(Point([1, 2, 3]))
    assert p[2] == 3
Example #11
0
def test_distances_plane_to_points():
    plane = Plane(normal=Vector([0, 0, -1]), point=Point([1, 2, 0]))
    points = [[1, 2, 3], [1, 2, 6]]
    d = distances_plane_to_points(plane, points)
    assert d == pytest.approx([-3, -6])
Example #12
0
def test_plane_from_normal_point():
    normal = Vector([0, 0, -1])
    point = Point([1, 2, 0])
    plane = Plane(normal=normal, point=point)
    assert plane.normal == normal
    assert plane.point == point
Example #13
0
def test_plane_as_abcd():
    normal = Vector([0, 0, -1])
    point = Point([1, 2, 0])
    plane = Plane(normal=normal, point=point)
    assert plane.as_abcd() == pytest.approx((0, 0, -1, 0))
Example #14
0
def test_vector_express_in_frame_with_original_frame(example_frames):
    fa, fb, fc = example_frames
    v = Vector([1, 1, 3])
    vt = v.express_in_frame(fc, original_frame=fa)
    assert vt == Vector([1, 1, 3])
Example #15
0
def test_vector_from_np():
    p = Vector(np.array([1, 2, 3]))
    assert p[2] == 3
Example #16
0
def test_vector_transform(example_frames):
    fa, fb, fc = example_frames
    v = Vector([1, 1, 3])
    vt = v.transform(fc)
    assert vt == Vector([math.sqrt(2), 0, -3])
Example #17
0
def test_fit_plane():
    points = [[1, 0, 0], [0, 1, 0], [-1, 0, 0]]
    plane = fit_plane(points)
    assert plane == Plane(normal=Vector([0, 0, 1]), point=Point([0, 1 / 3, 0]))