def test_cross_angle_equality(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): if v1.norm > 0 and v2.norm > 0: theta = vector_ops.angle_between(v1, v2) f1 = vector_ops.cross(v1, v2).norm f2 = v1.norm * v2.norm * abs(math.sin(theta)) self.assertAlmostEqual(f1, f2, PRECISION)
def test_dot_angle_equality(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): if v1.norm > 0 and v2.norm > 0: f1 = vector_ops.dot(v1, v2) f2 = v1.norm * v2.norm * math.cos( vector_ops.angle_between(v1, v2)) self.assertAlmostEqual(f1, f2, PRECISION)
def test_project(self): for v1, v2 in itertools.product(utils.ALL_VECTORS, utils.ALL_VECTORS): if v1.norm > 0 and v2.norm > 0: pass vec = vector_ops.project(v1, v2) value = v1.norm * math.cos(vector_ops.angle_between(v1, v2)) self.assertIsInstance(vec, Vector) self.assertAlmostEqual(vec.norm, abs(value))
def test_angle_between_orthogonal(self): v1 = Vector([0, 1, 0]) v2 = Vector([1, 0, 0]) self.assertAlmostEqual(vector_ops.angle_between(v1, v2), math.pi / 2, PRECISION)
def test_angle_between_antiparallel(self): v1 = Vector([-1, 0, 0]) v2 = Vector([2, 0, 0]) self.assertAlmostEqual(vector_ops.angle_between(v1, v2), math.pi, PRECISION)