示例#1
0
    def test_zero(self):
        v = Vector(0.0, 0.0)

        self.assertEqual(v.x, 0.0)
        self.assertEqual(v.y, 0.0)
        self.assertEqual(v.get_magnitude(), 0.0)
        self.assertEqual(v.get_angle(), None)
示例#2
0
    def test_init(self):
        v = Vector(1, 1)

        self.assertEqual(v.x, 1.0)
        self.assertEqual(v.y, 1.0)

        # Type check
        self.assertIsInstance(v.x, float)
        self.assertIsInstance(v.y, float)
        self.assertIsInstance(v.get_magnitude(), float)
        self.assertIsInstance(v.get_angle(), float)
示例#3
0
def get_point_on_line_distance_from_point(line_start, line_end, point,
                                          distance) -> Coordinates:
    a_side = distance
    c_side = get_distance(line_start, point)

    v_point = Vector(point.x - line_start.x, point.y - line_start.y)
    v_line = Vector(line_end.x - line_start.x, line_end.y - line_start.y)
    dot = v_point.dot_product(v_line)

    a_angle = np.arccos(dot / v_point.get_magnitude() / v_line.get_magnitude())

    from physics.trianglesolver import solve
    (a_side, b_side, c_side, a_angle, b_angle,
     c_angle) = solve(a=a_side, c=c_side, A=a_angle, ssa_flag='obtuse')
    assert a_angle + b_angle + c_angle == np.radians(
        180), 'a_angle: {} \nb_angle: {}\nc_angle: {}\n'.format(
            a_angle, b_angle, c_angle)
    # Compute exact point
    angle = np.radians(get_angle(line_end, line_start))
    x = line_start.x + b_side * np.cos(angle)
    y = line_start.y + b_side * np.sin(angle)

    return Coordinates(x, y)
示例#4
0
    def test_magnitude(self):
        v = Vector(3.0, 4.0)

        self.assertEqual(v.get_magnitude(), 5.0)