/
ray.py
69 lines (55 loc) · 1.94 KB
/
ray.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
# A class for the definition of a ray, which will be a vpython object #
# called a curve. It is convenient for specifying a list of points and #
# having a line connecting them. Ideal for ray-tracing purposes. #
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#
from visual import curve
class ray:
#----------------------------------#
# Constructor
#----------------------------------#
def __init__(self,angle,x0,y0):
# Set initial angle, x0, and y0
self.angle = angle
self.y = y0
self.x = x0
self.points = []
self.addPoint(x0,y0)
#----------------------------------#
# Add method to update angle
#----------------------------------#
def update(self,angle,y,x):
self.angle = angle
self.y = y
self.x = x
#----------------------------------#
# Add points
#----------------------------------#
def addPoint(self,x,y):
self.points.append((x,y))
#----------------------------------#
# Get vector of last two points
#----------------------------------#
def getVector(self):
np = len(self.points)
if np < 2:
print "\t\t\tWarning: Not enough points..."
return (0,0)
p0 = self.points[np-2]
p1 = self.points[np-1]
#print "\t Making Vector: ", p1, p0
newX = p1[0] - p0[0]
newY = p1[1] - p0[1]
vect = (newX, newY)
return vect
#----------------------------------#
# Make curve object
#----------------------------------#
def drawRay(self):
#print "Drawing Ray"
#print self.points
self.ray = curve(pos=self.points,
color=(0,0,0),
#radius=0.005
radius=0.002
)