hit enter before done
changes currently made
gravity_lowest.py
for i in range(1,len(polygons)):
for i in range(1,len(self.polygons)):
nfp.py
inter=Polygon(self.sliding).intersection(Polygon(self.stationary))
+print(inter)
error:
POLYGON EMPTY
Traceback (most recent call last):
File "ga.py", line 205, in
bestSequence=geneticAlgorithm(population=polyList, popSize=10, eliteSize=5, mutationRate=0.1, generations=3)
File "ga.py", line 143, in geneticAlgorithm
pop,popRanked = nextGeneration(pop, eliteSize, mutationRate)
File "ga.py", line 127, in nextGeneration
popRanked = rankSequences(currentGen) # 获得子代
File "ga.py", line 39, in rankSequences
fitnessResults[i] = Fitness(population[i]) # index和fitness共同排序
File "ga.py", line 17, in Fitness
pp=GravityLowestAlgorithm(sequence).start()
File "/home/ /gravity_lowest.py", line 20, in start
self.placePoly(i)
File "/home/ /gravity_lowest.py", line 58, in placePoly
nfp=NFP(main,adjoin).nfp
File "/home/ /nfp.py", line 22, in init
self.main()
File "/home/ /nfp.py", line 61, in main
if geoFunc.computeInterArea(mapping(inter))>1:
File "/home/ /geo_func.py", line 51, in computeInterArea
poly=inter["coordinates"][0]
IndexError: tuple index out of range
this is shapely.Polygon.intersection != geo_func.py
inter=Polygon(self.sliding).intersection(Polygon(self.stationary))
from shapely docs:
Note
These methods will always return a geometric object. An intersection of disjoint geometries for example will return an empty GeometryCollection, not None or False. To test for a non-empty result, use the geometry’s is_empty property.
in just python
from shapely.geometry import Polygon,Point,mapping,LineString
stationary= [[1083.333333333333, 433.3333333333335], [1283.3333333333333, 433.3333333333335], [1383.3333333333333, 533.3333333333335], [1383.3333333333333, 733.3333333333334], [1283.3333333333333, 833.3333333333334], [1083.333333333333, 833.3333333333334], [983.3333333333331, 733.3333333333334], [983.3333333333331, 533.3333333333335]]
sliding = [[983.3333333333331, -16.66666666666646], [1183.333333333333, 83.33333333333354], [1383.3333333333333, -16.66666666666646], [1283.3333333333333, 183.33333333333343], [1383.3333333333333, 483.3333333333334], [1183.333333333333, 383.3333333333334], [983.3333333333331, 483.3333333333334], [1083.333333333333, 283.3333333333334]]
inter=Polygon(sliding).intersection(Polygon(stationary))
print(inter)
POLYGON EMPTY