def _intersect3d(ray1, ray2, tol): # Check for colinear case d_cross = utilities.vector_cross(ray1.d, ray2.d) if utilities.vector_is_zero(d_cross): return -1, -1, RayIntersection.COLINEAR # Find common values p_diff = utilities.vector_generate(ray1.p, ray2.p) d_magn = utilities.vector_magnitude(d_cross) d_magn_square = d_magn**2 # Find t1 pd1_cross = utilities.vector_cross(p_diff, ray2.d) pd1_dot = utilities.vector_dot(pd1_cross, d_cross) t1 = pd1_dot / d_magn_square # Find t2 pd2_cross = utilities.vector_cross(p_diff, ray1.d) pd2_dot = utilities.vector_dot(pd2_cross, d_cross) t2 = pd2_dot / d_magn_square # Check for skew case ray1_pt = ray1.eval(t1) ray2_pt = ray2.eval(t2) if utilities.point_distance(ray1_pt, ray2_pt) < tol: return t1, t2, RayIntersection.INTERSECT else: return t1, t2, RayIntersection.SKEW
def test_vector_dot3(): with pytest.raises(TypeError): utilities.vector_dot(5, 9.7)
def test_vector_dot2(): result = 32 vec1 = (1, 2, 3) vec2 = (1, 5, 7) to_check = utilities.vector_dot(vec1, vec2) assert to_check == result
def test_vector_dot1(): with pytest.raises(ValueError): vec1 = () vec2 = () utilities.vector_dot(vec1, vec2)