def test_intersect_ray_pass(self): circle = Circle((10., 10.), 3) ray1_hor = Ray2D((10.,15.), angle=0) ray2_hor = Ray2D((10.,5.), angle=0) ray1_vert = Ray2D((5.,10.), angle=HALF_PI) ray2_vert = Ray2D((15.,10.), angle=-HALF_PI) ray3 = Ray2D((13.24, 14.95), angle=0.3992) self.assertFalse(circle.intersect_ray(ray1_hor)) self.assertFalse(circle.intersect_ray(ray2_hor)) self.assertFalse(circle.intersect_ray(ray1_vert)) self.assertFalse(circle.intersect_ray(ray2_vert)) self.assertFalse(circle.intersect_ray(ray3))
def test_intersect_ray_intersect(self): circle = Circle((10., 10.), 3) ray_vert = Ray2D((8.5, 10.), angle=HALF_PI) cross_points = circle.intersect_ray(ray_vert) self.assertEqual(len(cross_points), 2) p1, p2 = cross_points if p1[1] > p2[1] : p1, p2 = p2, p1 self.assertTrue(equal_points_almost(p1, (8.5, 7.4019), places=4)) self.assertTrue(equal_points_almost(p2, (8.5, 12.5981), places=4)) ray_hor = Ray2D( (10, 8.5), angle=0.) cross_points = circle.intersect_ray(ray_hor) self.assertEqual(len(cross_points), 2) p1, p2 = cross_points if p1[0] > p2[0] : p1, p2 = p2, p1 self.assertTrue(equal_points_almost(p1, (7.4019, 8.5), places=4)) self.assertTrue(equal_points_almost(p2, (12.5981, 8.5), places=4)) ray_slope = Ray2D( (5,5), (16,12)) cross_points = circle.intersect_ray(ray_slope) self.assertEqual(len(cross_points), 2) p1, p2 = cross_points if p1[0] > p2[0] : p1, p2 = p2, p1 self.assertTrue(equal_points_almost(p1, (8.64840, 7.3217), places=4)) self.assertTrue(equal_points_almost(p2, (12.9986, 10.0900), places=4)) #ray with slope through midpoint ray_slope = Ray2D( (10,10), angle=HALF_PI/2) cross_points = circle.intersect_ray(ray_slope) self.assertEqual(len(cross_points), 2) p1, p2 = cross_points if p1[0] > p2[0] : p1, p2 = p2, p1 #print (p1[0], p1[1], p2[0], p2[1]) self.assertTrue(equal_points_almost(p1, (7.8787, 7.8787), places=4)) self.assertTrue(equal_points_almost(p2, (12.1213, 12.1213), places=4)) #horizontal ray through midpoint ray_hor = Ray2D( (10,10), angle=0) cross_points = circle.intersect_ray(ray_hor) self.assertEqual(len(cross_points), 2) p1, p2 = cross_points if p1[0] > p2[0] : p1, p2 = p2, p1 #print (p1[0], p1[1], p2[0], p2[1]) self.assertTrue(equal_points_almost(p1, (7, 10), places=4)) self.assertTrue(equal_points_almost(p2, (13, 10), places=4)) #vertical ray through midpoint ray_vert = Ray2D( (10,10), angle=HALF_PI) cross_points = circle.intersect_ray(ray_vert) self.assertEqual(len(cross_points), 2) p1, p2 = cross_points if p1[1] > p2[1] : p1, p2 = p2, p1 #print (p1[0], p1[1], p2[0], p2[1]) self.assertTrue(equal_points_almost(p1, (10, 7), places=4)) self.assertTrue(equal_points_almost(p2, (10, 13), places=4))