コード例 #1
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    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))
コード例 #2
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
    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))
コード例 #3
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	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))
コード例 #4
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	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))
コード例 #5
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 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))
コード例 #6
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	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))
コード例 #7
0
ファイル: domain_test.py プロジェクト: lordmauve/lepton
 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))
コード例 #8
0
ファイル: domain_test.py プロジェクト: jmichelsen/py-lepton
	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))