made script for optimal circle compuation more general by allowing also other number of circles
This commit is contained in:
parent
3398f44be0
commit
b0a658a7b7
BIN
prototype/cci/cci1.pdf
Normal file
BIN
prototype/cci/cci1.pdf
Normal file
Binary file not shown.
1
prototype/cci/cci1.txt
Normal file
1
prototype/cci/cci1.txt
Normal file
|
@ -0,0 +1 @@
|
|||
1 0.000000000000000000000000000000 0.000000000000000000000000000000
|
BIN
prototype/cci/cci10.pdf
Normal file
BIN
prototype/cci/cci10.pdf
Normal file
Binary file not shown.
10
prototype/cci/cci10.txt
Normal file
10
prototype/cci/cci10.txt
Normal file
|
@ -0,0 +1,10 @@
|
|||
1 -0.262258924190165855095630653709 -0.689552138434555425611558523406
|
||||
2 0.262258924190165855095630653709 -0.689552138434555425611558523406
|
||||
3 -0.654207495490543857031888931623 -0.340990392505480262378855842125
|
||||
4 0.654207495490543857031888931623 -0.340990392505480262378855842125
|
||||
5 0.000000000000000000000000000000 -0.235306356998833687832605108517
|
||||
6 -0.715460686241806569843043724712 0.179938604472344027862805139398
|
||||
7 0.715460686241806569843043724712 0.179938604472344027862805139398
|
||||
8 0.000000000000000000000000000000 0.289211491381498022358656198900
|
||||
9 -0.415055617900124834285924684739 0.609910427019080420778753583334
|
||||
10 0.415055617900124834285924684739 0.609910427019080420778753583334
|
BIN
prototype/cci/cci11.pdf
Normal file
BIN
prototype/cci/cci11.pdf
Normal file
Binary file not shown.
11
prototype/cci/cci11.txt
Normal file
11
prototype/cci/cci11.txt
Normal file
|
@ -0,0 +1,11 @@
|
|||
1 -0.254854701717148909608835737700 -0.700207538209709779458522719445
|
||||
2 0.254854701717148909608835737700 -0.700207538209709779458522719445
|
||||
3 -0.645314757823482092972348022140 -0.372572649141425545195582131150
|
||||
4 0.645314757823482092972348022140 -0.372572649141425545195582131150
|
||||
5 -0.254854701717148909608835737700 -0.044937760073141310932641542855
|
||||
6 0.254854701717148909608835737700 -0.044937760073141310932641542855
|
||||
7 -0.733824866869546118800008853460 0.129393123143898335937886211109
|
||||
8 0.733824866869546118800008853460 0.129393123143898335937886211109
|
||||
9 0.000000000000000000000000000000 0.396483531848771796650108754372
|
||||
10 -0.478970165152397209191173115760 0.570814415065811443520636508336
|
||||
11 0.478970165152397209191173115760 0.570814415065811443520636508336
|
BIN
prototype/cci/cci12.pdf
Normal file
BIN
prototype/cci/cci12.pdf
Normal file
Binary file not shown.
12
prototype/cci/cci12.txt
Normal file
12
prototype/cci/cci12.txt
Normal file
|
@ -0,0 +1,12 @@
|
|||
1 0.000000000000000000000000000000 -0.751836529428313158455945512868
|
||||
2 -0.468509916422022800799147453449 -0.588010735613764119868275923156
|
||||
3 0.468509916422022800799147453449 -0.588010735613764119868275923156
|
||||
4 -0.248163470571686841544054487132 -0.143277246537595169579619996000
|
||||
5 0.248163470571686841544054487132 -0.143277246537595169579619996000
|
||||
6 -0.743487192950506270382840218584 -0.111736121739513839036609043190
|
||||
7 0.743487192950506270382840218584 -0.111736121739513839036609043190
|
||||
8 0.000000000000000000000000000000 0.286554493075190339159239992000
|
||||
9 -0.651109533978045892394293176753 0.375918264714156579227972756434
|
||||
10 0.651109533978045892394293176753 0.375918264714156579227972756434
|
||||
11 -0.274977276528483469583692765135 0.699746857353277958904884966346
|
||||
12 0.274977276528483469583692765135 0.699746857353277958904884966346
|
BIN
prototype/cci/cci13.pdf
Normal file
BIN
prototype/cci/cci13.pdf
Normal file
Binary file not shown.
13
prototype/cci/cci13.txt
Normal file
13
prototype/cci/cci13.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
1 0.000000000000000000000000000000 -0.763932022500210303590826331269
|
||||
2 -0.449027976579585372441945151797 -0.618033988749894848204586834366
|
||||
3 0.449027976579585372441945151797 -0.618033988749894848204586834366
|
||||
4 0.000000000000000000000000000000 -0.291796067500630910772478993806
|
||||
5 -0.726542528005360885895466757481 -0.236067977499789696409173668731
|
||||
6 0.726542528005360885895466757481 -0.236067977499789696409173668731
|
||||
7 -0.277514551425775513453521605683 0.090169943749474241022934171828
|
||||
8 0.277514551425775513453521605683 0.090169943749474241022934171828
|
||||
9 -0.726542528005360885895466757481 0.236067977499789696409173668731
|
||||
10 0.726542528005360885895466757481 0.236067977499789696409173668731
|
||||
11 0.000000000000000000000000000000 0.472135954999579392818347337463
|
||||
12 -0.449027976579585372441945151797 0.618033988749894848204586834366
|
||||
13 0.449027976579585372441945151797 0.618033988749894848204586834366
|
BIN
prototype/cci/cci2.pdf
Normal file
BIN
prototype/cci/cci2.pdf
Normal file
Binary file not shown.
2
prototype/cci/cci2.txt
Normal file
2
prototype/cci/cci2.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
1 -0.500000000000000000000000000000 0.000000000000000000000000000000
|
||||
2 0.500000000000000000000000000000 0.000000000000000000000000000000
|
BIN
prototype/cci/cci3.pdf
Normal file
BIN
prototype/cci/cci3.pdf
Normal file
Binary file not shown.
3
prototype/cci/cci3.txt
Normal file
3
prototype/cci/cci3.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
1 -0.464101615137754587054892683011 -0.267949192431122706472553658494
|
||||
2 0.464101615137754587054892683011 -0.267949192431122706472553658494
|
||||
3 0.000000000000000000000000000000 0.535898384862245412945107316988
|
BIN
prototype/cci/cci4.pdf
Normal file
BIN
prototype/cci/cci4.pdf
Normal file
Binary file not shown.
4
prototype/cci/cci4.txt
Normal file
4
prototype/cci/cci4.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
1 -0.414213562373095048801688724210 -0.414213562373095048801688724210
|
||||
2 0.414213562373095048801688724210 -0.414213562373095048801688724210
|
||||
3 -0.414213562373095048801688724210 0.414213562373095048801688724210
|
||||
4 0.414213562373095048801688724210 0.414213562373095048801688724210
|
BIN
prototype/cci/cci5.pdf
Normal file
BIN
prototype/cci/cci5.pdf
Normal file
Binary file not shown.
5
prototype/cci/cci5.txt
Normal file
5
prototype/cci/cci5.txt
Normal file
|
@ -0,0 +1,5 @@
|
|||
1 -0.370191908158750137702237641058 -0.509525449494428810513706911251
|
||||
2 0.370191908158750137702237641058 -0.509525449494428810513706911251
|
||||
3 -0.598983089761037227177173011864 0.194621403573803879364825731779
|
||||
4 0.598983089761037227177173011864 0.194621403573803879364825731779
|
||||
5 0.000000000000000000000000000000 0.629808091841249862297762358942
|
BIN
prototype/cci/cci6.pdf
Normal file
BIN
prototype/cci/cci6.pdf
Normal file
Binary file not shown.
6
prototype/cci/cci6.txt
Normal file
6
prototype/cci/cci6.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
1 -0.333333333333333333333333333333 -0.577350269189625764509148780502
|
||||
2 0.333333333333333333333333333333 -0.577350269189625764509148780502
|
||||
3 -0.666666666666666666666666666667 0.000000000000000000000000000000
|
||||
4 0.666666666666666666666666666667 0.000000000000000000000000000000
|
||||
5 -0.333333333333333333333333333333 0.577350269189625764509148780502
|
||||
6 0.333333333333333333333333333333 0.577350269189625764509148780502
|
BIN
prototype/cci/cci7.pdf
Normal file
BIN
prototype/cci/cci7.pdf
Normal file
Binary file not shown.
7
prototype/cci/cci7.txt
Normal file
7
prototype/cci/cci7.txt
Normal file
|
@ -0,0 +1,7 @@
|
|||
1 -0.333333333333333333333333333333 -0.577350269189625764509148780502
|
||||
2 0.333333333333333333333333333333 -0.577350269189625764509148780502
|
||||
3 -0.666666666666666666666666666667 0.000000000000000000000000000000
|
||||
4 0.000000000000000000000000000000 0.000000000000000000000000000000
|
||||
5 0.666666666666666666666666666667 0.000000000000000000000000000000
|
||||
6 -0.333333333333333333333333333333 0.577350269189625764509148780502
|
||||
7 0.333333333333333333333333333333 0.577350269189625764509148780502
|
BIN
prototype/cci/cci8.pdf
Normal file
BIN
prototype/cci/cci8.pdf
Normal file
Binary file not shown.
8
prototype/cci/cci8.txt
Normal file
8
prototype/cci/cci8.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
1 -0.302593388348611302909204224933 -0.628341645367213738512227388956
|
||||
2 0.302593388348611302909204224933 -0.628341645367213738512227388956
|
||||
3 -0.679921171839088240043878874469 -0.155187570571975671990838057814
|
||||
4 0.679921171839088240043878874469 -0.155187570571975671990838057814
|
||||
5 0.000000000000000000000000000000 0.000000000000000000000000000000
|
||||
6 -0.545254445070410775447749861103 0.434825910113495061957667559237
|
||||
7 0.545254445070410775447749861103 0.434825910113495061957667559237
|
||||
8 0.000000000000000000000000000000 0.697406611651388697090795775067
|
BIN
prototype/cci/cci9.pdf
Normal file
BIN
prototype/cci/cci9.pdf
Normal file
Binary file not shown.
9
prototype/cci/cci9.txt
Normal file
9
prototype/cci/cci9.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
1 -0.276768653914155215717770973808 -0.668178637919298919997757686523
|
||||
2 0.276768653914155215717770973808 -0.668178637919298919997757686523
|
||||
3 -0.668178637919298919997757686523 -0.276768653914155215717770973808
|
||||
4 0.668178637919298919997757686523 -0.276768653914155215717770973808
|
||||
5 0.000000000000000000000000000000 0.000000000000000000000000000000
|
||||
6 -0.668178637919298919997757686523 0.276768653914155215717770973808
|
||||
7 0.668178637919298919997757686523 0.276768653914155215717770973808
|
||||
8 -0.276768653914155215717770973808 0.668178637919298919997757686523
|
||||
9 0.276768653914155215717770973808 0.668178637919298919997757686523
|
15
prototype/cci/radii.txt
Normal file
15
prototype/cci/radii.txt
Normal file
|
@ -0,0 +1,15 @@
|
|||
# N (number of circles) | radius of enclosed circles (enclosing circle has radius of 1)
|
||||
# source: http://www.packomania.com
|
||||
1 1.000000000000000000000000000000
|
||||
2 0.500000000000000000000000000000
|
||||
3 0.464101615137754587054892683012
|
||||
4 0.414213562373095048801688724210
|
||||
5 0.370191908158750137702237641058
|
||||
6 0.333333333333333333333333333333
|
||||
7 0.333333333333333333333333333333
|
||||
8 0.302593388348611302909204224934
|
||||
9 0.276768653914155215717770973808
|
||||
10 0.262258924190165855095630653709
|
||||
11 0.254854701717148909608835737700
|
||||
12 0.248163470571686841544054487132
|
||||
13 0.236067977499789696409173668731
|
|
@ -1,20 +1,70 @@
|
|||
from casadi import *
|
||||
import matplotlib.pyplot as plt
|
||||
import math
|
||||
import operator
|
||||
|
||||
file = open('tmp2019_cci_08_26_11_36_00.txt')
|
||||
N = 7 # number of enclosed circles
|
||||
|
||||
# this function reads and processes data for optimal circle packaging obtained form packomania.com
|
||||
def read_circle_data(N):
|
||||
coords_raw = open('cci/cci{}.txt'.format(N))
|
||||
radii_raw = open('cci/radii.txt'.format(N))
|
||||
|
||||
coords_raw = coords_raw.readlines()
|
||||
coords_raw = [c.split() for c in coords_raw if c[0] != '#']
|
||||
coords = {}
|
||||
for c in coords_raw:
|
||||
coords[int(c[0])] = (float(c[1]), float(c[2]))
|
||||
|
||||
coords = sort_ccw(coords, (0,0))
|
||||
|
||||
radii_raw = radii_raw.readlines()
|
||||
radii_raw = [r.split() for r in radii_raw if r[0] != '#']
|
||||
radii = {}
|
||||
for r in radii_raw:
|
||||
radii[int(r[0])] = float(r[1])
|
||||
|
||||
return radii[N], coords
|
||||
|
||||
# this function sorts enclosed circle coordinates counter-clockwise w.r.t. the center point
|
||||
# TODO: there is a problem when circles are present that are not touching the boundary of the enclosing circle (e.g. N = 7)
|
||||
def sort_ccw(coords, center):
|
||||
a = {}
|
||||
for c in coords:
|
||||
a[c] = math.atan2(coords[c][1] - center[1], coords[c][0] - center[0])
|
||||
a_sort = sorted(a.items(), key=operator.itemgetter(1))
|
||||
|
||||
coords_sort = []
|
||||
for a in a_sort:
|
||||
coords_sort.append(coords[a[0]])
|
||||
|
||||
return coords_sort
|
||||
|
||||
# read radius and center coordinates for enclosed circles
|
||||
rtilde, coords = read_circle_data(N)
|
||||
|
||||
c = (0.0, 0.0) # center of big circle
|
||||
R = 15.0 # radius of big circle
|
||||
R = 1.0 # radius of big circle
|
||||
|
||||
# center for smaller circles
|
||||
p1 = (-5.55287862, -7.64288174)
|
||||
p2 = (5.55287862, -7.64288174)
|
||||
p3 = (-8.98474635, 2.91932105)
|
||||
p4 = (8.98474635, 2.91932105)
|
||||
p5 = (0.00000000, 9.44712138)
|
||||
rtilde = 5.5 # radius of smaller circles
|
||||
plt.xlim((-1, 1))
|
||||
plt.ylim((-1, 1))
|
||||
plt.gca().set_aspect('equal', 'box')
|
||||
|
||||
points = [p1, p2, p3, p4, p5]
|
||||
plt.ion()
|
||||
plt.show()
|
||||
|
||||
for p in coords:
|
||||
plt.plot(p[0], p[1], 'o')
|
||||
circle = plt.Circle(p, rtilde, fill=False)
|
||||
plt.gca().add_artist(circle)
|
||||
circle = plt.Circle(c, R, fill=False)
|
||||
plt.gca().add_artist(circle)
|
||||
|
||||
plt.plot(c[0], c[1], 'o')
|
||||
|
||||
for k in range(0, N):
|
||||
p1 = coords[k]
|
||||
p2 = coords[(k+1) % N]
|
||||
|
||||
# midpoint between center of two circles
|
||||
m = np.mean([p1, p2], axis=0)
|
||||
|
@ -22,42 +72,20 @@ m = np.mean([p1, p2], axis=0)
|
|||
# vector in direction of midpoint
|
||||
v = m - np.array(c)
|
||||
v = v/np.linalg.norm(v)
|
||||
|
||||
plt.xlim((-16, 16))
|
||||
plt.ylim((-16, 16))
|
||||
plt.gca().set_aspect('equal', 'box')
|
||||
|
||||
|
||||
for p in points:
|
||||
plt.plot(p[0], p[1], 'o')
|
||||
circle = plt.Circle(p, rtilde, fill=False)
|
||||
plt.gca().add_artist(circle)
|
||||
circle = plt.Circle(c, R, fill=False)
|
||||
plt.gca().add_artist(circle)
|
||||
#plt.show()
|
||||
|
||||
plt.plot(c[0], c[1], 'o')
|
||||
plt.plot(m[0], m[1], 'o')
|
||||
|
||||
opti = casadi.Opti()
|
||||
|
||||
r = opti.variable(1) # radius of new circle
|
||||
p = opti.variable(2) # center of new circle
|
||||
#v1 = opti.variable(2) # direction vector from
|
||||
#v2 = opti.variable(2)
|
||||
lamb = opti.variable(1)
|
||||
|
||||
opti.minimize(-r)
|
||||
opti.subject_to(p == c + v * lamb)
|
||||
opti.subject_to((p[0] - p1[0])**2 + (p[1] - p1[1])**2 >= (rtilde + r)**2)
|
||||
#opti.subject_to(p == (rtilde + r) * v1 + p1)
|
||||
#opti.subject_to(p == (rtilde + r) * v2 + p2)
|
||||
#opti.subject_to((v1[0]**2+v1[1]**2)**0.5 == 1)
|
||||
#opti.subject_to((v2[0]**2+v2[1]**2)**0.5 == 1)
|
||||
opti.subject_to(R == lamb + r)
|
||||
opti.subject_to(r >= 0)
|
||||
opti.subject_to(r <= R)
|
||||
#opti.subject_to(lamb >= 0.6 * R)
|
||||
|
||||
opti.solver('ipopt')
|
||||
|
||||
|
@ -65,11 +93,9 @@ init_r = 0.1
|
|||
init_lamb = R - init_r
|
||||
init_p = c + v * init_lamb
|
||||
|
||||
|
||||
opti.set_initial(r, init_r)
|
||||
opti.set_initial(p, init_p)
|
||||
opti.set_initial(lamb, init_lamb)
|
||||
#opti.set_initial(v1, )
|
||||
|
||||
sol = opti.solve()
|
||||
|
||||
|
@ -85,6 +111,5 @@ print("v = {}".format(v))
|
|||
plt.plot(p[0], p[1], 'o')
|
||||
circle = plt.Circle(p, r, fill=False)
|
||||
plt.gca().add_artist(circle)
|
||||
plt.show()
|
||||
|
||||
pass
|
|
@ -1,95 +0,0 @@
|
|||
%!PS-Adobe-3.0 EPSF-3.0
|
||||
%%Title: /srv/http/htdocs/packing/tmp/tmp2019_cci_08_26_11_36_00.ps
|
||||
%%Creator: nicefig-2.0
|
||||
%%Pages: 1
|
||||
%%BoundingBox: 40 250 580 790
|
||||
%%DocumentProcessColors: Cyan Magenta Yellow Black
|
||||
%%CreationDate: 26-Aug-2019 11:36:00
|
||||
%%DocumentFonts: Courier
|
||||
%%+ Courier-Bold
|
||||
%%+ Helvetica
|
||||
%%+ Helvetica-Oblique
|
||||
%%+ Symbol
|
||||
%%EndComments
|
||||
%%EndProlog
|
||||
|
||||
20 dict begin
|
||||
gsave
|
||||
/g { setgray } bind def
|
||||
/rgb { setrgbcolor } bind def
|
||||
/np { newpath } bind def
|
||||
/m { moveto } bind def
|
||||
/rm { rmoveto } bind def
|
||||
/l { lineto } bind def
|
||||
/rl { rlineto } bind def
|
||||
/c { curveto } bind def
|
||||
/s { stroke } bind def
|
||||
/f { closepath fill } bind def
|
||||
/la { setlinejoin setlinecap 1.0417 mul setlinewidth } bind def
|
||||
/lc { setlinecap } bind def
|
||||
/lj { setlinejoin } bind def
|
||||
/ld { setdash } bind def
|
||||
/lw { setlinewidth } bind def
|
||||
/font { findfont exch scalefont setfont } bind def
|
||||
/rgh { dup stringwidth pop neg 0 rm } bind def
|
||||
/ctr { dup stringwidth pop 2 div neg 0 rm } bind def
|
||||
|
||||
1 lj 1 lc 0.200 lw
|
||||
|
||||
%
|
||||
0.400 lw
|
||||
%
|
||||
% box
|
||||
%
|
||||
310.000 520.000 250.000 0 360 arc s
|
||||
%
|
||||
% circles
|
||||
%
|
||||
1.000 0.843 0.000 rgb
|
||||
309.119 392.619 m 217.452 392.619 91.667 0 360 arc f
|
||||
0.000 0.000 0.000 rgb
|
||||
1.000 0.843 0.000 rgb
|
||||
494.215 392.619 m 402.548 392.619 91.667 0 360 arc f
|
||||
0.000 0.000 0.000 rgb
|
||||
1.000 0.843 0.000 rgb
|
||||
251.921 568.655 m 160.254 568.655 91.667 0 360 arc f
|
||||
0.000 0.000 0.000 rgb
|
||||
1.000 0.843 0.000 rgb
|
||||
551.412 568.655 m 459.746 568.655 91.667 0 360 arc f
|
||||
0.000 0.000 0.000 rgb
|
||||
1.000 0.843 0.000 rgb
|
||||
401.667 677.452 m 310.000 677.452 91.667 0 360 arc f
|
||||
0.000 0.000 0.000 rgb
|
||||
0.000 0.000 0.000 rgb
|
||||
217.452 392.619 91.667 0 360 arc s
|
||||
0.000 0.000 0.000 rgb
|
||||
402.548 392.619 91.667 0 360 arc s
|
||||
0.000 0.000 0.000 rgb
|
||||
160.254 568.655 91.667 0 360 arc s
|
||||
0.000 0.000 0.000 rgb
|
||||
459.746 568.655 91.667 0 360 arc s
|
||||
0.000 0.000 0.000 rgb
|
||||
310.000 677.452 91.667 0 360 arc s
|
||||
%
|
||||
% centers
|
||||
%
|
||||
218.580 392.619 m 217.452 392.619 1.128 0 360 arc f
|
||||
403.676 392.619 m 402.548 392.619 1.128 0 360 arc f
|
||||
161.383 568.655 m 160.254 568.655 1.128 0 360 arc f
|
||||
460.874 568.655 m 459.746 568.655 1.128 0 360 arc f
|
||||
311.128 677.452 m 310.000 677.452 1.128 0 360 arc f
|
||||
%
|
||||
12.00 /Courier font
|
||||
70.000 251.000 m (www.packomania.com) show
|
||||
12.00 /Symbol font
|
||||
430.000 250.000 m (Ó) show
|
||||
12.00 /Courier font
|
||||
442.000 251.000 m (E.S) show
|
||||
9.00 /Courier font
|
||||
464.000 251.000 m (PECHT) show
|
||||
500.000 251.000 m (26-AUG-2019) show
|
||||
|
||||
showpage
|
||||
grestore end
|
||||
%%Trailer
|
||||
%%EOF
|
|
@ -1,5 +0,0 @@
|
|||
1 -5.55287862 -7.64288174
|
||||
2 5.55287862 -7.64288174
|
||||
3 -8.98474635 2.91932105
|
||||
4 8.98474635 2.91932105
|
||||
5 0.00000000 9.44712138
|
Loading…
Reference in New Issue
Block a user