-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08-Rotation.py
71 lines (46 loc) · 1.22 KB
/
08-Rotation.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
70
71
# Rotation
from graphics import*
import numpy as np
def rotate(pointsA, t, xp, yp):
t = t*np.pi/180
pointsB = []
for x,y in pointsA:
xf = int((x-xp)*np.cos(t)-(y-yp)*np.sin(t)) + xp
yf = int((x-xp)*np.sin(t)+(y-yp)*np.cos(t)) + yp
pointsB.append((xf,yf))
return pointsB
def plot(pointsA, pointsB, isClosed):
win = GraphWin("Rotation", 500, 500)
win.setCoords(-250,-250,250,250)
l = Line(Point(0,-250), Point(0,250))
l.draw(win)
l = Line(Point(-250,0), Point(250,0))
l.draw(win)
if isClosed:
pointsA.append(pointsA[0])
pointsB.append(pointsB[0])
for i in range(len(pointsA)-1):
(x1,y1) = pointsA[i]
(x2,y2) = pointsA[i+1]
l = Line(Point(x1,y1), Point(x2,y2))
l.setOutline("green")
l.setWidth(5)
l.draw(win)
for i in range(len(pointsB)-1):
(x1,y1) = pointsB[i]
(x2,y2) = pointsB[i+1]
l = Line(Point(x1,y1), Point(x2,y2))
l.setOutline("blue")
l.setWidth(3)
l.draw(win)
win.getMouse()
def main():
pointsA = [(50,50), (100,100), (150,100), (100,50)]
isClosed = True
t = 60
xp = 50
yp = 50
pointsB = rotate(pointsA, t, xp, yp)
print(pointsB)
plot(pointsA, pointsB, isClosed)
main()