Beispiel #1
0
def test_intersecting_ray_sphere_at_two_points_return_true():
    x = _intersect_ray_with_sphere(x1, y1)
    diff1 = x[0] - p1
    diff2 = x[1] - p2
    d1 = abs(np.linalg.norm(diff1._vector))
    d2 = abs(np.linalg.norm(diff2._vector))
    assert (d1 < 10**(-5) and d2 < 10**(-5)) == True is True
Beispiel #2
0
def test__intersect_ray_with_sphere__two_point_intersection():
    R = Ray(Point((0, 0, 2)), Vector(
        (1, 0, 0)))  #ray passing through the sphere
    S = Sphere(Point((0, 0, 0)), 3)
    val = np.sqrt(5)
    assert (_intersect_ray_with_sphere(R, S) == (Point(
        (val, 0, 2)), Point((-val, 0, 2)))) is True
def test__intersect_ray_with_sphere_return_false_1():
    sph = Sphere((0, 0, 0), 1)
    ray = Ray((5, 0, 0), (0, 5, 0))
    val = 2
    temp = _intersect_ray_with_sphere(ray, sph)
    if temp == 0:
        val = 0
    assert (val == 2) is False
def test__intersect_ray_with_sphere_return_true_1():
    sph = Sphere((0, 0, 0), 2)
    ray = Ray((2, 0, 0), (2, 1, 0))
    temp = _intersect_ray_with_sphere(ray, sph)
    val = 2
    if np.array_equal(temp, [[2, 0, 0]]) is True:
        val = 1
    assert (val == 1) is True
def test__intersect_ray_with_sphere_return_true():
    sph = Sphere((0, 0, 0), 1)
    ray = Ray((-1, 0, 0), (0, 0, 0))
    temp = _intersect_ray_with_sphere(ray, sph)
    val = 1
    print(temp)
    if np.array_equal(temp, [[1.0, 0.0, 0.0], [-1.0, 0.0, 0.0]]):
        val = 2
    assert (val == 2) is True
def test__intersect_ray_with_sphere_return_false():
    sph = Sphere((0, 0, 0), 1)
    ray = Ray((1, 0, 0), (1, 1, 0))
    val = 2
    temp = _intersect_ray_with_sphere(ray, sph)
    print(temp)
    if np.array_equal(temp, [[1.0, 0.0, 0.0]]) is True:
        val = 1

    assert (val == 2) is False
Beispiel #7
0
def test_intersect_ray_and_sphere_with_different_origin_and_no_intersection():
    assert (_intersect_ray_with_sphere(
        Ray(Point((0, 0, 0)), Vector(
            (-1, -1, -1))), Sphere(Point(
                (4, 4, 0)), 1)) == "No Intersecction") is True
Beispiel #8
0
def test_non_intersecting_ray_sphere_return_false():
    assert _intersect_ray_with_sphere(x, y) is False
Beispiel #9
0
def test_intersect_ray_sphere_one_intersect_tangent_point__one_correct_point():
    Ray1=Ray((5,5,0),(0,0,1))
    Sphere1=Sphere((5,5,0),5)
    np.testing.assert_array_equal (_intersect_ray_with_sphere(Ray1, Sphere1),np.array([5,5,5]))
def test__intersect_ray_with_sphere__ray_outside_sphere__two_points__return_true(
):
    assert np.array_equal(
        _intersect_ray_with_sphere(Ray((-2, 1, 1),
                                       (1, 0, 0)), Sphere((1, 1, 1), 1.0)),
        [Point([2, 1, 1]), Point([0, 1, 1])]) is True
def test__intersect_ray_with_sphere__ray_in_sphere__one_point__return_true():
    assert (_intersect_ray_with_sphere(Ray((-0.5, 0, 0), (1, 0, 0)),
                                       Sphere((0, 0, 0),
                                              1.0)) == Point([1, 0, 0]))
Beispiel #12
0
def test__intersect_given_sphere_ray__intersected_two_point_d_grater_then_0():
    assert (_intersect_ray_with_sphere(
        Ray(direction=Vector((1, -1, 0)), origin=Point(
            (0, 1, 0))), Sphere(center=Point((0, 0, 0)), radius=1)) == (Point(
                (1, 0, 0)), Point((0, 1, 0)))) is True
Beispiel #13
0
def test_given_ray_sphere_return_tangent_intersection():
    assert (_intersect_ray_with_sphere(Ray(
        (0, 0, 0), (1, 1, 0)), Sphere((1, 1, 1), 1)) == Point(
            (1, 1, 0))) is True
Beispiel #14
0
def test_given_ray_sphere_no_intersection_return_false():
    assert (_intersect_ray_with_sphere(Ray(
        (0, 0, 0), (0, 1, 0)), Sphere((5, 5, 5), 5)) is False) is True
Beispiel #15
0
def test_given_ray_sphere_same_origin_return_one_point_intersection():
    assert (_intersect_ray_with_sphere(Ray(
        (0, 0, 0), (0, -1, 0)), Sphere((0, 0, 0), 5)) == Point(
            (0, -5, 0))) is True
Beispiel #16
0
def test_intersect_ray_sphere_two_intersect_vertical__two_correct_points():
    Ray1=Ray((1,0,0),[0,1,0])
    Sphere1=Sphere((1,6,0),5)
    np.testing.assert_array_equal (_intersect_ray_with_sphere(Ray1, Sphere1),np.array([[1.0,11.0,0],[1.0,1.0,0]])) 
Beispiel #17
0
def test_intersect_ray_sphere_two_intersect_horizontal__two_correct_points():
    Ray1=Ray((-6,0,0),[1,0,0])
    Sphere1=Sphere((0,0,0),5)
    np.testing.assert_array_equal (_intersect_ray_with_sphere(Ray1, Sphere1),np.array([[5.0,0,0],[-5.0,0,0]])) 
Beispiel #18
0
def test_intersecting_ray_sphere_at_one_point_return_true():
    x = _intersect_ray_with_sphere(x2, y2)
    diff = x - p
    d = abs(np.linalg.norm(diff._vector))
    assert (d < 10**(-5)) == True is True
def test__intersect_ray_with_sphere__two_points__return_true():
    assert np.array_equal(
        _intersect_ray_with_sphere(Ray((-2, 0, 0),
                                       (1, 0, 0)), Sphere((0, 0, 0), 1.0)),
        [Point([1, 0, 0]), Point([-1, 0, 0])]) is True
Beispiel #20
0
def test__intersect_given_sphere_ray__not_intersected_two_point_d_less_than_0__return_NotImplimented(
):
    assert (_intersect_ray_with_sphere(
        Ray(direction=Vector((1, 1, 0)), origin=Point(
            (1, 1, 0))), Sphere(center=Point(
                (0, 0, 0)), radius=1))) is NotImplemented
def test__intersect_ray_with_sphere__ray_outside_sphere__one_point__return_true(
):
    assert (_intersect_ray_with_sphere(Ray((-3, 1, 0), (1, 0, 0)),
                                       Sphere((1, 1, 1),
                                              1.0)) == Point([1, 1, 0]))
Beispiel #22
0
def test__intersect_ray_with_sphere__does_not_intersect():
    R = Ray(Point((0, 0, 4)), Vector((1, 0, 0)))  #ray outside sphere
    S = Sphere(Point((0, 0, 0)), 3)  #sphere with center at origin and radius 3
    assert (_intersect_ray_with_sphere(R, S) == "Does not intersect") is True
def test__intersect_ray_with_sphere__ray_outside_sphere__no_points__return_true(
):
    assert (_intersect_ray_with_sphere(Ray((-2, 1.5, 0), (1, 0, 0)),
                                       Sphere((1, 1, 1), 1.0)) == None)
Beispiel #24
0
def test__intersect_ray_with_sphere__one_point_intersection():
    R = Ray(Point((0, 0, 3)), Vector((1, 0, 0)))  #ray touching sphere surface
    S = Sphere(Point((0, 0, 0)), 3)
    assert (_intersect_ray_with_sphere(R, S) == Point((0, 0, 3))) is True
Beispiel #25
0
def test_intersect_ray_and_sphere_with_different_origin():
    assert (_intersect_ray_with_sphere(
        Ray(Point((0, 0, 0)), Vector((1, 1, 1))), Sphere(Point((3, 3, 3)), 1))
            == (Point([2.42, 2.42, 2.42]), Point([3.58, 3.58, 3.58]))) is True
Beispiel #26
0
def test_intersect_sphere_and_ray_return_true():
    assert (intersect(y0, x0) == _intersect_ray_with_sphere(x0, y0)) is True
Beispiel #27
0
def test_intersect_ray_and_sphere_with_same_origin():
    assert (_intersect_ray_with_sphere(
        Ray(Point((0, 0, 0)), Vector((1, 1, 1))), Sphere(Point(
            (0, 0, 0)), 2)) == Point([1.15, 1.15, 1.15])) is True
Beispiel #28
0
def test_intersect_ray_sphere_no_intersect__return_False():
    Ray1=Ray((0,0,6),(1,0,0))
    Sphere1=Sphere((0,0,0),5)
    assert _intersect_ray_with_sphere(Ray1, Sphere1) is False