-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsphere.py
More file actions
29 lines (21 loc) · 898 Bytes
/
sphere.py
File metadata and controls
29 lines (21 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
__author__ = 'Henry Vogt'
import math
class Sphere(object):
def __init__(self, center, radius, material):
self.center = center # Zentrum der Kugel
self.radius = float(radius) # Radius der Kugel
self.material = material # Material der Kugel
def __repr__(self):
return 'Sphere(%s,%s,%s)' % (repr(self.center),repr(self.radius),repr(self.material))
def intersectionParameter(self, ray): # Berechnung der Schnittstelle des Objekts mit dem Sichtstrahl
co = self.center - ray.origin
v = co * ray.direction
discriminant = v*v - co * co + self.radius*self.radius
if discriminant < 0:
return None
else:
return v - math.sqrt(discriminant)
def normalAt(self, p):
return (p - self.center).normalized()
def getMaterial(self):
return self.material