Hier ist die rote Linie die Tür des Behälters und das Blau ist das Regal. Wie Sie sehen können, wird das Regal in der Abbildung gezeichnet, aber die Gegenstände ignorieren den Bereich. Ich muss die Gegenstände im Regal packen lassen. In der PY3DBP -Bibliothek befindet sich ein Hilfsmethode -Skript mit einer Kreuzungsfunktion: < /p>
Code: Select all
from decimal import Decimal
from .constants import Axis
def rectIntersect(item1, item2, x, y):
d1 = item1.getDimension()
d2 = item2.getDimension()
cx1 = item1.position[x] + d1[x]/2
cy1 = item1.position[y] + d1[y]/2
cx2 = item2.position[x] + d2[x]/2
cy2 = item2.position[y] + d2[y]/2
ix = max(cx1, cx2) - min(cx1, cx2)
iy = max(cy1, cy2) - min(cy1, cy2)
return ix < (d1[x]+d2[x])/2 and iy < (d1[y]+d2[y])/2
def intersect(item1, item2):
return (
rectIntersect(item1, item2, Axis.WIDTH, Axis.HEIGHT) and
rectIntersect(item1, item2, Axis.HEIGHT, Axis.DEPTH) and
rectIntersect(item1, item2, Axis.WIDTH, Axis.DEPTH)
)
def binIntersect(item, bin, x, y):
# Assuming 'bin' has 'width', 'height', 'depth', and 'position' attributes
d1 = item.getDimension()
d2 = [bin.width, bin.height, bin.depth/2] # Modify based on your Bin class attributes
cx1 = item.position[x] + d1[x]/2
cy1 = item.position[y] + d1[y]/2
cx2 = bin.width + d2[Axis.WIDTH]/2
cy2 = bin.height + d2[Axis.HEIGHT]/2
ix = max(cx1, cx2) - min(cx1, cx2)
iy = max(cy1, cy2) - min(cy1, cy2)
return ix < (d1[Axis.WIDTH] + d2[Axis.WIDTH])/2 and iy < (d1[Axis.HEIGHT] + d2[Axis.HEIGHT])/2
def itemIntersectsWithBin(item, bin):
# Assuming 'item' has 'position' and 'getDimension' methods
return (
binIntersect(item, bin, Axis.WIDTH, Axis.HEIGHT) and
binIntersect(item, bin, Axis.HEIGHT, Axis.DEPTH) and
binIntersect(item, bin, Axis.WIDTH, Axis.DEPTH/2)
)
def getLimitNumberOfDecimals(number_of_decimals):
return Decimal('1.{}'.format('0' * number_of_decimals))
def set2Decimal(value, number_of_decimals=0):
number_of_decimals = getLimitNumberOfDecimals(number_of_decimals)
return Decimal(value).quantize(number_of_decimals)
print("Too Heavy for container: ", self.item.partno)
fit = False
return fit
# fix point float prob
if self.fix_point == True :
[w,h,d] = dimension
[x,y,z] = [float(pivot[0]),float(pivot[1]),float(pivot[2])]
for i in range(3):
# fix height
y = self.checkHeight([x,x+float(w),y,y+float(h),z,z+float(d)])
# fix width
x = self.checkWidth([x,x+float(w),y,y+float(h),z,z+float(d)])
# fix depth
z = self.checkDepth([x,x+float(w),y,y+float(h),z,z+float(d)])
# check stability on item
# rule :
# 1. Define a support ratio, if the ratio below the support surface does not exceed this ratio, compare the second rule.
# 2. If there is no support under any vertices of the bottom of the item, then fit = False.
if self.check_stable == True :
# Cal the surface area of item.
# item_area_lower = int(dimension[0] * dimension[1])
item_area_lower = dimension[0] * dimension[1]
# Cal the surface area of the underlying support.
support_area_upper = 0
for i in self.fit_items:
# Verify that the lower support surface area is greater than the upper support surface area * support_surface_ratio.
if z == i[5] :
area = len(set([ j for j in range(int(x),int(x+int(w)))]) & set([ j for j in range(int(i[0]),int(i[1]))])) * \
len(set([ j for j in range(int(y),int(y+int(h)))]) & set([ j for j in range(int(i[2]),int(i[3]))]))
support_area_upper += area
# If not , get four vertices of the bottom of the item.
if support_area_upper / item_area_lower < self.support_surface_ratio :
four_vertices = [[x,y],[x+float(w),y],[x,y+float(h)],[x+float(w),y+float(h)]]
# If any vertices is not supported, fit = False.
c = [False,False,False,False]
for i in self.fit_items:
if z == i[5] :
for jdx,j in enumerate(four_vertices) :
if (i[0]