def test_shell_Sphere_intersect(self): from lepton.domain import Sphere from lepton.particle_struct import Vec3 sphere = Sphere((2, 1, -1), 3, 1) lines = [ ((2, 1, -1), (2, 1, 1)), ((2.5, 1, -1), (4, 1, -1)), ((5, 4, -1), (3.5, 2.5, -1)), ((2, 2.5, -1), (2, 1, -1)), ] expected = [ ((2, 1, 0), (0, 0, -1)), ((3, 1, -1), (-1, 0, 0)), ((math.sin(math.pi / 4) * 3 + 2, math.sin(math.pi / 4) * 3 + 1, -1), Vec3(1, 1, 0).normalize()), ((2, 2, -1), (0, 1, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = sphere.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = sphere.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_solid_Sphere_intersect(self): from lepton.domain import Sphere from lepton.particle_struct import Vec3 sphere = Sphere((0, 1, 2), 2) lines = [ ((0, -2, 2), (0, 0, 2)), ((3, 4, 2), (1, 2, 2)), ((-1, -1, 0), (0, -1, 2)), # tangential ] expected = [ ((0, -1, 2), (0, -1, 0)), ((math.sin(math.pi / 4) * 2, math.sin(math.pi / 4) * 2 + 1, 2), Vec3(1, 1, 0).normalize()), ((0, -1, 2), (0, -1, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = sphere.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = sphere.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_shell_Sphere_intersect(self): from lepton.domain import Sphere from lepton.particle_struct import Vec3 sphere = Sphere((2, 1, -1), 3, 1) lines = [ ((2, 1, -1), (2, 1, 1)), ((2.5, 1, -1), (4, 1, -1)), ((5, 4, -1), (3.5, 2.5, -1)), ((2, 2.5, -1), (2, 1, -1)), ] expected = [ ((2, 1, 0), (0, 0, -1)), ((3, 1, -1), (-1, 0, 0)), ((math.sin(math.pi/4)*3+2, math.sin(math.pi/4)*3+1, -1), Vec3(1, 1, 0).normalize()), ((2, 2, -1), (0, 1, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = sphere.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = sphere.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_solid_Sphere_intersect(self): from lepton.domain import Sphere from lepton.particle_struct import Vec3 sphere = Sphere((0, 1, 2), 2) lines = [ ((0, -2, 2), (0, 0, 2)), ((3, 4, 2), (1, 2, 2)), ((-1, -1, 0), (0, -1, 2)), # tangential ] expected = [ ((0, -1, 2), (0, -1, 0)), ((math.sin(math.pi/4)*2, math.sin(math.pi/4)*2+1, 2), Vec3(1, 1, 0).normalize()), ((0, -1, 2), (0, -1, 0)), ] for (start, end), (point, normal) in zip(lines, expected): p, N = sphere.intersect(start, end) self.assertVector(p, point) self.assertVector(N, normal) # Reverse direction should yield same point and inverse normal p, N = sphere.intersect(end, start) self.assertVector(p, point) self.assertVector(N, -Vec3(*normal))
def test_solid_Sphere_grazing_intersect(self): from lepton.domain import Sphere sphere = Sphere((0, 0, 0), 4) p, N = sphere.intersect((-5, 0, 0), (5, 0, 0)) self.assertVector(p, (-4, 0, 0)) self.assertVector(N, (-1, 0, 0)) p, N = sphere.intersect((5, 0, 0), (-5, 0, 0)) self.assertVector(p, (4, 0, 0)) self.assertVector(N, (1, 0, 0))
def test_Sphere_stationary_particles(self): from lepton.domain import Sphere from lepton.particle_struct import Vec3 sphere = Sphere((0, 1, 2), 2) positions = [ ((0, 1.1, 2.2), (0, 1.1, 2.2)), ((3.1, 4, 2), (3.1, 4, 2)), ((-0.9, -1, 0), (-0.9, -1, 0)), ] for start, end in positions: self.assertEqual(sphere.intersect(start, end), (None, None))