def test_cross_non_numeric(self): u = ('a', 'b', 'c') v = (1, 1, 0) with self.assertRaises( TypeError, msg='should raise TypeError when passing non-3d vectors'): cross(u, v)
def test_cross_non_3d(self): u = (1, 0) v = (1, 1, 0) with self.assertRaises( ValueError, msg='should raise TypeError when passing non-3d vectors'): cross(u, v)
def test_cross_happy_path(self): u = (1, 2, 3) v = (4, 5, 6) cross_actual_result = cross(u, v) cross_expected_result = (12 - 15, -6 + 12, 5 - 8 ) # using determinant matrix self.assertEqual(cross_actual_result, cross_expected_result, msg='cross should match')
def plane_equation(p0, p1, p2): """Returns the coefficients a, b, c, d for a plane's equation in its standard form (ax + by + cz = d) given three points p0, p1, p2 in the plane """ vector_in_the_plane_1 = subtract(p1, p0) vector_in_the_plane_2 = subtract(p2, p0) vector_perpendicular_to_the_plane = cross(vector_in_the_plane_1, vector_in_the_plane_2) a, b, c = vector_perpendicular_to_the_plane d = dot(vector_perpendicular_to_the_plane, p1) return a, b, c, d