-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlines.py
115 lines (86 loc) · 2.86 KB
/
lines.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from gfxutil import *
crds = [Coord(10,10),
Coord(10,20),
Coord(20,20),
Coord(20,10)]
def oct_x_dom_imp(ptA,ptB):
dx, dy = dxdy(ptA,ptB)
startx,starty = ptA.x,ptA.y
stopx,stopy = ptB.x,ptB.y
if dx < 0:
startx,starty = ptB.x,ptB.y
stopx,stopy = ptA.x,ptA.y
dx, dy = dxdy(ptB,ptA)
yincr = 1
if dy < 0:
dy = -dy
yincr = -1
M = 1.0*dy/dx
new_error = { 'skipping y': lambda current_error : current_error + M,
'adding to y': lambda current_error : current_error + M - 1}
x = startx
y = starty
current_error = 0
while dx > 0:
dx -= 1
x += 1
a_error =new_error['skipping y'](current_error)
if a_error < 0.5:
current_error = new_error['skipping y'](current_error)
else:
y = y + yincr
current_error = new_error['adding to y'](current_error)
yield x,y
def oct_y_dom_imp(ptA,ptB):
dx, dy = dxdy(ptA,ptB)
startx,starty = ptA.x,ptA.y
stopx,stopy = ptB.x,ptB.y
if dy < 0:
startx,starty = ptB.x,ptB.y
stopx,stopy = ptA.x,ptA.y
dx, dy = dxdy(ptB,ptA)
xincr = 1
if dx < 0:
dx = -dx
xincr = -1
M = 1.0*dx/dy
new_error = { 'skipping x': lambda current_error : current_error + M,
'adding to x': lambda current_error : current_error + M -1}
x = startx
y = starty
current_error = 0
while dy > 0:
dy -= 1
y += 1
a_error =new_error['skipping x'](current_error)
if a_error < 0.5:
current_error = new_error['skipping x'](current_error)
else:
x = x + xincr
current_error = new_error['adding to x'](current_error)
yield x,y
plt2 = CharPlotter(oct_x_dom=oct_x_dom_imp, oct_y_dom=oct_y_dom_imp)
plt2.regupoly(crds,marks='.')
plt2.render()
print list(plt2.line(Coord(10,10),Coord(20,10)))
print list(plt2.line(Coord(20,10),Coord(10,10)))
print list(plt2.line(Coord(10,10),Coord(10,20)))
print list(plt2.line(Coord(10,20),Coord(10,10)))
plt2.oct_x_dom = oct_x_dom_imp
gradient_list = [1,0.75,0.5,0.25,0.15,0.1,0.05,-1]
cases = testcases(gradient_list=gradient_list,start_coord=Coord(10,25), radius=20)
for n,i in enumerate(cases):
print gradient_list[n],i
plt2.charline(*i, marks=True)
plt2.render()
gradient_list = [-gradient_list[i] for i in range(len(gradient_list)-1,0,-1)]
cases = testcases(gradient_list=gradient_list,start_coord=Coord(10,25), radius=20)
for n,i in enumerate(cases):
print gradient_list[n],i
#import pdb;pdb.set_trace()
plt2.charline(*i, marks=True)
print i,dxdy(*i) ,list(plt2.call_line(*i))
#plt2.render()
# plt2.regupoly(crds,marks='.')
# plt2.regupoly(plt2.create_npoly(x=25,y=14,num_of_corners=5,theta=pi/2),marks='.')
plt2.render()