RDG-Networks 0.2.4__tar.gz → 0.2.6__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/PKG-INFO +1 -1
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_Networks.egg-info/PKG-INFO +1 -1
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_Networks.egg-info/SOURCES.txt +1 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_Networks.egg-info/entry_points.txt +1 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/__init__.py +2 -0
- RDG-Networks-0.2.6/RDG_networks/generate_line_segments_static.py +253 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/setup.py +2 -1
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/LICENSE.txt +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_Networks.egg-info/dependency_links.txt +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_Networks.egg-info/requires.txt +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_Networks.egg-info/top_level.txt +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/Classes.py +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/draw_segments.py +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/generate_line_network.py +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/generate_line_segments.py +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/generate_line_segments_dynamic.py +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/get_intersection_segments.py +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/RDG_networks/sample_in_polygon.py +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/README.md +0 -0
- {RDG-Networks-0.2.4 → RDG-Networks-0.2.6}/setup.cfg +0 -0
@@ -13,5 +13,6 @@ RDG_networks/draw_segments.py
|
|
13
13
|
RDG_networks/generate_line_network.py
|
14
14
|
RDG_networks/generate_line_segments.py
|
15
15
|
RDG_networks/generate_line_segments_dynamic.py
|
16
|
+
RDG_networks/generate_line_segments_static.py
|
16
17
|
RDG_networks/get_intersection_segments.py
|
17
18
|
RDG_networks/sample_in_polygon.py
|
@@ -3,4 +3,5 @@ draw_segments = RDG_networks.draw_segments:main
|
|
3
3
|
generate_line_network = RDG_networks.generate_line_network:main
|
4
4
|
generate_line_segments = RDG_networks.generate_line_segments:main
|
5
5
|
generate_line_segments_dynamic = RDG_networks.generate_line_segments_dynamic:main
|
6
|
+
generate_line_segments_static = RDG_networks.generate_line_segments_static:main
|
6
7
|
get_intersection_segments = RDG_networks.get_intersection_segments:main
|
@@ -5,12 +5,14 @@ from .generate_line_segments import generate_line_segments
|
|
5
5
|
from .generate_line_network import generate_line_network
|
6
6
|
from .get_intersection_segments import get_intersection_segments
|
7
7
|
from .generate_line_segments_dynamic import generate_line_segments_dynamic
|
8
|
+
from .generate_line_segments_static import generate_line_segments_static
|
8
9
|
from .draw_segments import draw_segments
|
9
10
|
|
10
11
|
__all__ = ['generate_line_segments',
|
11
12
|
'generate_line_network',
|
12
13
|
'get_intersection_segments',
|
13
14
|
'generate_line_segments_dynamic',
|
15
|
+
'generate_line_segments_static',
|
14
16
|
'draw_segments',
|
15
17
|
'sample_in_polygon',
|
16
18
|
'Line',
|
@@ -0,0 +1,253 @@
|
|
1
|
+
import matplotlib.pyplot as plt
|
2
|
+
import numpy as np
|
3
|
+
import math
|
4
|
+
import random
|
5
|
+
import os
|
6
|
+
import sys
|
7
|
+
import networkx as nx
|
8
|
+
|
9
|
+
from .Classes import LineSegment
|
10
|
+
|
11
|
+
def minDistance_line_point(A, B, E):
|
12
|
+
# vector AB
|
13
|
+
AB = np.array(B) - np.array(A)
|
14
|
+
EB = np.array(B) - np.array(E)
|
15
|
+
AE = np.array(E) - np.array(A)
|
16
|
+
|
17
|
+
# Calculating the dot product
|
18
|
+
AB_BE = np.dot(AB, EB)
|
19
|
+
AB_AE = np.dot(AB, AE)
|
20
|
+
|
21
|
+
# Case 1
|
22
|
+
if (AB_BE > 0):
|
23
|
+
# Finding the magnitude
|
24
|
+
y = E[1] - B[1]
|
25
|
+
x = E[0] - B[0]
|
26
|
+
reqAns = np.sqrt(x * x + y * y)
|
27
|
+
|
28
|
+
# Case 2
|
29
|
+
elif (AB_AE < 0):
|
30
|
+
y = E[1] - A[1]
|
31
|
+
x = E[0] - A[0]
|
32
|
+
reqAns = np.sqrt(x * x + y * y)
|
33
|
+
|
34
|
+
# Case 3
|
35
|
+
else:
|
36
|
+
reqAns = np.linalg.outer(AB, AE) / np.linalg.norm(AB)
|
37
|
+
|
38
|
+
return reqAns
|
39
|
+
|
40
|
+
def doLinesIntersect(line1, line2):
|
41
|
+
"""
|
42
|
+
Check if two lines intersect and return the intersection point.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
- line1 (Line): The first line segment.
|
46
|
+
- line2 (Line): The second line segment.
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
- intersect (bool): True if the lines intersect, False otherwise.
|
50
|
+
- intersection_point (tuple or None): The intersection point (x, y) if lines intersect, None otherwise.
|
51
|
+
"""
|
52
|
+
|
53
|
+
x1, y1 = line1[0]
|
54
|
+
v1, w1 = (np.cos(line1[1]), np.sin(line1[1]))
|
55
|
+
|
56
|
+
x2, y2 = line2[0]
|
57
|
+
v2, w2 = (np.cos(line2[1]), np.sin(line2[1]))
|
58
|
+
|
59
|
+
determinant = v1 * w2 - v2 * w1
|
60
|
+
|
61
|
+
if determinant == 0:
|
62
|
+
return False, (None, None)
|
63
|
+
|
64
|
+
t1 = ((x2 - x1) * w2 - (y2 - y1) * v2) / determinant
|
65
|
+
t2 = ((x2 - x1) * w1 - (y2 - y1) * v1) / determinant
|
66
|
+
|
67
|
+
intersect_x = x1 + v1 * t1
|
68
|
+
intersect_y = y2 + w2 * t2
|
69
|
+
|
70
|
+
if -1e-6 < intersect_x < 1 + 1e-6 and -1e-6 < intersect_y < 1 + 1e-6:
|
71
|
+
return True, (intersect_x, intersect_y)
|
72
|
+
else:
|
73
|
+
return False, (None, None)
|
74
|
+
|
75
|
+
def seeds(number_of_lines, radius = 0.015, number_of_trials = 10000):
|
76
|
+
Line = {}
|
77
|
+
line_id = 0
|
78
|
+
|
79
|
+
nucleation_points = [(0,0), (1,0), (1,1), (0,1)]
|
80
|
+
angle = [0,np.pi/2, np.pi, 3*np.pi/2]
|
81
|
+
|
82
|
+
Line = {'b1':[ (0,0), 0], 'b2':[ (1,0), np.pi/2], 'b3':[ (1,1), np.pi], 'b4':[ (0,1), 3*np.pi/2] }
|
83
|
+
|
84
|
+
for i in range(number_of_lines):
|
85
|
+
new_points = (random.uniform(0,1), random.uniform(0,1))
|
86
|
+
|
87
|
+
line_new_point = []
|
88
|
+
for j in range(len(nucleation_points)):
|
89
|
+
start = (np.cos(angle[i])*10+nucleation_points[i][0], np.sin(angle[i])*10+nucleation_points[i][1])
|
90
|
+
end = (-np.cos(angle[i])*10+nucleation_points[i][0], -np.sin(angle[i])*10+nucleation_points[i][1])
|
91
|
+
line_new_point += [minDistance_line_point(start, end, new_points)]
|
92
|
+
|
93
|
+
trial = 0
|
94
|
+
while sum(np.array(line_new_point) < radius) != 0 or np.sum( np.sqrt(np.sum((np.array(nucleation_points) - np.array(new_points))**2, axis = 1)) < radius) != 0:
|
95
|
+
new_points = (random.uniform(0,1), random.uniform(0,1))
|
96
|
+
|
97
|
+
line_new_point = []
|
98
|
+
for j in range(len(nucleation_points)):
|
99
|
+
start = (np.cos(angle[i])*10+nucleation_points[i][0], np.sin(angle[i])*10+nucleation_points[i][1])
|
100
|
+
end = (-np.cos(angle[i])*10+nucleation_points[i][0], -np.sin(angle[i])*10+nucleation_points[i][1])
|
101
|
+
line_new_point += [minDistance_line_point(start, end, new_points)]
|
102
|
+
|
103
|
+
trial += 1
|
104
|
+
|
105
|
+
if trial > number_of_trials:
|
106
|
+
break
|
107
|
+
|
108
|
+
if trial <= number_of_trials:
|
109
|
+
nucleation_points += [new_points]
|
110
|
+
angles = [0, np.pi/4, np.pi/2, 3*np.pi/4]
|
111
|
+
angle_new = random.uniform(0, 2*np.pi) #random.choice(angles)#np.pi #random.uniform(0, 2*np.pi)
|
112
|
+
angle += [angle_new]
|
113
|
+
Line[line_id] = [ new_points ,angle_new]
|
114
|
+
line_id += 1
|
115
|
+
else:
|
116
|
+
print('jammed')
|
117
|
+
break
|
118
|
+
|
119
|
+
#number of Line
|
120
|
+
print("Number of line: ", len(Line))
|
121
|
+
|
122
|
+
return(Line)
|
123
|
+
|
124
|
+
def all_intersection(Line):
|
125
|
+
intersections_dict = {}
|
126
|
+
|
127
|
+
for k,v in Line.items():
|
128
|
+
#intersections_dict[k] = {}
|
129
|
+
intersections_dict[k] = {'back':{}, 'front':{}}
|
130
|
+
|
131
|
+
for kk,vv in Line.items():
|
132
|
+
intersect, (intersect_x, intersect_y) = doLinesIntersect(v ,vv)
|
133
|
+
|
134
|
+
if intersect:
|
135
|
+
segment_length = np.sqrt( (v[0][0] - intersect_x)**2 + (v[0][1] - intersect_y)**2)
|
136
|
+
|
137
|
+
if intersect_x < v[0][0]:
|
138
|
+
intersections_dict[k]['back'][kk] = [(intersect_x, intersect_y), segment_length]
|
139
|
+
else:
|
140
|
+
if intersect_x == v[0][0] and intersect_y < v[0][1]:
|
141
|
+
intersections_dict[k]['back'][kk] = [(intersect_x, intersect_y), segment_length]
|
142
|
+
else:
|
143
|
+
intersections_dict[k]['front'][kk] = [(intersect_x, intersect_y), segment_length]
|
144
|
+
intersections_dict[k]['back'] = dict(sorted(intersections_dict[k]['back'].items(), key=lambda e:e[1], reverse = True))
|
145
|
+
intersections_dict[k]['front'] = dict(sorted(intersections_dict[k]['front'].items(), key=lambda e:e[1]))
|
146
|
+
|
147
|
+
return intersections_dict
|
148
|
+
|
149
|
+
def transform_to_standard_lines(segments):
|
150
|
+
|
151
|
+
data = []
|
152
|
+
for s in segments:
|
153
|
+
start = (s[3], s[4])
|
154
|
+
end = (s[5], s[6])
|
155
|
+
line = LineSegment(start=start, end=end, id=s[0], neighbors_initial=[s[1], s[2]], neighbors=None)
|
156
|
+
data.append(line)
|
157
|
+
|
158
|
+
return data
|
159
|
+
|
160
|
+
def static_line_graph_generation(Line, intersections_dict):
|
161
|
+
borders = ['b1', 'b2', 'b3', 'b4']
|
162
|
+
segments = []
|
163
|
+
edges = []
|
164
|
+
|
165
|
+
for k,v in Line.items():
|
166
|
+
if k not in borders:
|
167
|
+
#front
|
168
|
+
for kk_f, vv_f in intersections_dict[k]['front'].items():
|
169
|
+
try:
|
170
|
+
d_k_kk = intersections_dict[kk_f]['back'][k][1]
|
171
|
+
front_coordinate = intersections_dict[kk_f]['back'][k][0]
|
172
|
+
front_id = kk_f
|
173
|
+
where = 'back'
|
174
|
+
except:
|
175
|
+
d_k_kk = intersections_dict[kk_f]['front'][k][1]
|
176
|
+
front_coordinate = intersections_dict[kk_f]['front'][k][0]
|
177
|
+
front_id = kk_f
|
178
|
+
where = 'front'
|
179
|
+
|
180
|
+
if vv_f[1] > d_k_kk:
|
181
|
+
#check kk neighbors
|
182
|
+
boolean = []
|
183
|
+
for kkk, vvv in intersections_dict[kk_f][where].items():
|
184
|
+
if vvv[1] < d_k_kk:
|
185
|
+
try:
|
186
|
+
d_kk_kkk = intersections_dict[kkk]['back'][kk_f][1]
|
187
|
+
except:
|
188
|
+
d_kk_kkk = intersections_dict[kkk]['front'][kk_f][1]
|
189
|
+
|
190
|
+
if d_kk_kkk > vvv[1]:
|
191
|
+
boolean += [0]
|
192
|
+
else:
|
193
|
+
boolean += [1]
|
194
|
+
|
195
|
+
#print(k,kk, boolean)
|
196
|
+
|
197
|
+
if sum(boolean) == 0:
|
198
|
+
#print(k, kk, front_coordinate)
|
199
|
+
break
|
200
|
+
|
201
|
+
#back
|
202
|
+
for kk_b, vv_b in intersections_dict[k]['back'].items():
|
203
|
+
try:
|
204
|
+
d_k_kk = intersections_dict[kk_b]['back'][k][1]
|
205
|
+
back_coordinate = intersections_dict[kk_b]['back'][k][0]
|
206
|
+
back_id = kk_b
|
207
|
+
where = 'back'
|
208
|
+
except:
|
209
|
+
d_k_kk = intersections_dict[kk_b]['front'][k][1]
|
210
|
+
back_coordinate = intersections_dict[kk_b]['front'][k][0]
|
211
|
+
back_id = kk_b
|
212
|
+
where = 'front'
|
213
|
+
|
214
|
+
if vv_b[1] > d_k_kk:
|
215
|
+
#check kk neighbors
|
216
|
+
boolean = []
|
217
|
+
for kkk, vvv in intersections_dict[kk_b][where].items():
|
218
|
+
if vvv[1] < d_k_kk:
|
219
|
+
#print(vvv[1], d_k_kk)
|
220
|
+
try:
|
221
|
+
d_kk_kkk = intersections_dict[kkk]['back'][kk_b][1]
|
222
|
+
except:
|
223
|
+
d_kk_kkk = intersections_dict[kkk]['front'][kk_b][1]
|
224
|
+
|
225
|
+
if d_kk_kkk > vvv[1]:
|
226
|
+
boolean += [0]
|
227
|
+
else:
|
228
|
+
boolean += [1]
|
229
|
+
#print(k,kk, boolean)
|
230
|
+
|
231
|
+
|
232
|
+
if sum(boolean) == 0:
|
233
|
+
#print(k, kk, back_coordinate)
|
234
|
+
break
|
235
|
+
|
236
|
+
|
237
|
+
try:
|
238
|
+
if k!= kk_f and k!= kk_b and kk_f != kk_b and (k, kk_f) not in edges and (kk_f, k) not in edges and (k, kk_b) not in edges and (kk_b, k) not in edges:
|
239
|
+
segments+= [[k, kk_f, kk_b, front_coordinate[0], front_coordinate[1], back_coordinate[0], back_coordinate[1]]]
|
240
|
+
edges += [(k,kk_f)]
|
241
|
+
edges += [(k,kk_b)]
|
242
|
+
except:
|
243
|
+
None
|
244
|
+
|
245
|
+
return segments
|
246
|
+
|
247
|
+
def generate_line_segments_static(size, seed_loc=None):
|
248
|
+
if seed_loc is None:
|
249
|
+
seed_loc = seeds(size, 0.0)
|
250
|
+
segments = static_line_graph_generation(seed_loc, all_intersection(seed_loc))
|
251
|
+
segments = transform_to_standard_lines(segments)
|
252
|
+
|
253
|
+
return segments
|
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|
2
2
|
|
3
3
|
setup(
|
4
4
|
name='RDG-Networks',
|
5
|
-
version='0.2.
|
5
|
+
version='0.2.6',
|
6
6
|
author='Niek Mooij',
|
7
7
|
author_email='mooij.niek@gmail.com',
|
8
8
|
description='Most of the code from the RDG Networks project',
|
@@ -27,6 +27,7 @@ setup(
|
|
27
27
|
'generate_line_network=RDG_networks.generate_line_network:main',
|
28
28
|
'get_intersection_segments=RDG_networks.get_intersection_segments:main',
|
29
29
|
'generate_line_segments_dynamic=RDG_networks.generate_line_segments_dynamic:main',
|
30
|
+
'generate_line_segments_static=RDG_networks.generate_line_segments_static:main',
|
30
31
|
'draw_segments=RDG_networks.draw_segments:main'
|
31
32
|
],
|
32
33
|
},
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|