def test_intersection6(self): cylinder = Cylinder(Vector(0, 8, 14), 10, 1.5, Color().red(), 10, 0.1) ray = Ray(Vector(0, 0, 0), Vector(0.0, 0.2, 1)) intersection = cylinder.intersection(ray, 0, 1000) self.assertAlmostEqual(intersection.point.x, 0.0) self.assertAlmostEqual(intersection.point.y, 3) self.assertAlmostEqual(intersection.point.z, 15)
def test_getSurfaceNormal2(self): cylinder = Cylinder(Vector(0, 0, 5), 10, 1.5, Color().red(), 10, 0.1) point = Vector(-1.5, 2.5, 5) surfaceNormal = cylinder.getSurfaceNormal(point) self.assertEqual(surfaceNormal.x, -1) self.assertEqual(surfaceNormal.y, 0) self.assertEqual(surfaceNormal.z, 0)
def test_intersection5(self): cylinder = Cylinder(Vector(0, 0, 5), 2, 1, Color().red(), 10, 0.1) ray = Ray(Vector(0, 0, 0), Vector(0.1, -0.2, 1)) intersection = cylinder.intersection(ray, 0, 1000) self.assertAlmostEqual(intersection.point.x, 0.4087346744) self.assertAlmostEqual(intersection.point.y, -0.8174693488) self.assertAlmostEqual(intersection.point.z, 4.0873467439)
def test_intersection2(self): cylinder = Cylinder(Vector(0, 0, 5), 2, 1, Color().red(), 10, 0.1) ray = Ray(Vector(0, 0, 0), Vector(0, 0.1, 1)) intersection = cylinder.intersection(ray, 0, 1000) self.assertEqual(intersection.point.x, 0.0) self.assertEqual(intersection.point.y, 0.4) self.assertEqual(intersection.point.z, 4.0)
def test_constructor(self): cylinder = Cylinder(Vector(0, 0, 5), 2, 1, Color().red(), 10, 0.1) self.assertEqual(cylinder.center.x, 0) self.assertEqual(cylinder.center.y, 0) self.assertEqual(cylinder.center.z, 5) self.assertEqual(cylinder.radius, 1) self.assertEqual(cylinder.height, 2)
def deserializeCylinder(self, cylinderJson): center = self.deserializeVector(cylinderJson["center"]) reflection = float(cylinderJson["reflection"]) height = float(cylinderJson["height"]) radius = float(cylinderJson["radius"]) specular = float(cylinderJson["specular"]) transparency = float(cylinderJson["transparency"]) refractiveIndex = float(cylinderJson["refractiveIndex"]) color = self.deserializeColor(cylinderJson["color"]) return Cylinder(center, height, radius, color, specular, reflection, transparency, refractiveIndex)
p1 = Plane(Vector(0, -3, 0), Vector(0, 1, 0), Color(1, 0, 0), 0, 0) p2 = Plane(Vector(0, 10, 0), Vector(0, -1, 0), Color(0.1, 1.0, 1.0), 0, 0) p3 = Plane(Vector(0, 0, 30), Vector(0, 0, -1), Color(0.7, 0.1, 0.2), 0, 0) p4 = Plane(Vector(0, 0, -1), Vector(0, 0, 1), Color(0.1, 0.4, 0.8), 0, 0) p5 = Plane(Vector(-10, 0, 0), Vector(1, 0, 0), Color(0.2, 0.1, 0.6), 0, 0) p6 = Plane(Vector(10, 0, 0), Vector(-1, 0, 0), Color(0.1, 0.7, 0.2), 0, 0) s1 = Sphere(sCenter1, 1, Color(1.0, 0, 0), 600, 0, 0) s2 = Sphere(sCenter2, 1.3, Color(0, 1.0, 0), 500, 0, 0) cube = Cube(Vector(0, 0, 25), 10, Color(0, 1, 0), 1000, 0, 0) cone = Cone(Vector(0, 0, 10), 1, 1, Color(1, 0, 0), 1000, 0, 0) cylinder = Cylinder(Vector(0, -3, 8), 1, 1, Color(1, 0, 0), 1000, 0.8, 0) light1 = Light(0, 3, 8, 0.5) light2 = Light(1, 3, 5, 0.3) light0 = AmbientLight(0.2) scene = Scene() scene.addLight(light0) scene.addLight(light1) scene.addLight(light2) scene.addObject3D(s1) scene.addObject3D(cylinder)
def test_intersection4(self): cylinder = Cylinder(Vector(0, 8, 14), 10, 1.5, Color().red(), 10, 0.1) ray = Ray(Vector(0, 0, 0), Vector(0.0, 1.8, 1)) intersection = cylinder.intersection(ray, 0, 1000) self.assertIsNone(intersection)
def test_intersection3(self): cylinder = Cylinder(Vector(0, 0, 5), 2, 1, Color().red(), 10, 0.1) ray = Ray(Vector(0, 0, 0), Vector(0, 1, 1)) intersection = cylinder.intersection(ray, 0, 1000) self.assertIsNone(intersection)