-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLec15.py
More file actions
68 lines (54 loc) · 1.28 KB
/
Lec15.py
File metadata and controls
68 lines (54 loc) · 1.28 KB
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
import math
# points as lists
def addPoints(p1,p2):
r=[]
r.append(p1[0]+p2[0])
r.append(p1[1]+p2[1])
return r
##p=[1,2]
##q=[3,1]
##r=addPoints(p,q)
##print r
# points as classes
class cartesianPoint:
pass
cp1=cartesianPoint()
cp2=cartesianPoint()
cp1.x=1.0
cp1.y=2.0
cp2.x=1.0
cp2.y=3.0
def samePoint(p1,p2):
return (p1.x==p2.x)and(p1.y==p2.y)
def printPoint(p):
print '('+str(p.x)+','+str(p.y)+')'
class polarPoint:
pass
pp1=polarPoint()
pp2=polarPoint()
pp1.radius=1.0
pp1.angle=0
pp2.radius=2.0
pp2.angle=math.pi/4.0
class cPoint:
def __init__(self,x,y):
self.x=x
self.y=y
self.radius=math.sqrt(self.x*self.x+self.y*self.y)
self.angle=math.atan2(self.y,self.x)
def cartesian(self):
return (self.x,self.y)
def polar(self):
return (self.radius,self.angle)
def __str__(self):
return '('+str(self.x)+','+str(self.y)+')'
def __cmp__(self,other):
return (self.x>other.x)and(self.y>other.y)
def __eq__(self,other):
return (self.x==other.x)and(self.y==other.y)
class Segment:
def __init__(self,start,end):
self.start=start
self.end=end
def length(self):
return math.sqrt((self.start.x-self.end.x)**2+(self.start.y-self.end.y)**2)