-
Notifications
You must be signed in to change notification settings - Fork 0
/
11-Shearing.py
77 lines (52 loc) · 1.31 KB
/
11-Shearing.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
72
73
74
75
76
77
# Shearing
from graphics import*
import numpy as np
def shear(pointsA, h, axis):
pointsB = []
if axis=='x':
for x,y in pointsA:
xf = int(x+h*y)
yf = y
pointsB.append((xf,yf))
elif axis=='y':
for x,y in pointsA:
xf = x
yf = int(y+h*x)
pointsB.append((xf,yf))
return pointsB
def plot(pointsA, pointsB, isClosed):
win = GraphWin("Shearing", 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 = [(0,0), (0,100), (100,100), (100,0)]
isClosed = True
h=0.5
pointsB = shear(pointsA, h,'x')
print(pointsB)
plot(pointsA.copy(), pointsB, isClosed)
pointsB = shear(pointsA, h,'y')
print(pointsB)
plot(pointsA.copy(), pointsB, isClosed)
main()