Skip to content

Commit

Permalink
Add visualization from unmerged PR enzoruiz#23
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgen committed May 23, 2023
1 parent 574a12b commit 7dfd7e0
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions py3dbp/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from .constants import RotationType, Axis
from .auxiliary_methods import intersect, set_to_decimal
from matplotlib import pyplot as plt
from mpl_toolkits import mplot3d


DEFAULT_NUMBER_OF_DECIMALS = 3
START_POSITION = [0, 0, 0]
Expand Down Expand Up @@ -130,6 +133,38 @@ def put_item(self, item, pivot):
return fit


def _plotCube(self, ax, x, y, z, dx, dy, dz, color='red'):
""" Auxiliary function to plot a cube. code taken somewhere from the web. """
xx = [x, x, x+dx, x+dx, x]
yy = [y, y+dy, y+dy, y, y]
kwargs = {'alpha': 1, 'color': color}
ax.plot3D(xx, yy, [z]*5, **kwargs)
ax.plot3D(xx, yy, [z+dz]*5, **kwargs)
ax.plot3D([x, x], [y, y], [z, z+dz], **kwargs)
ax.plot3D([x, x], [y+dy, y+dy], [z, z+dz], **kwargs)
ax.plot3D([x+dx, x+dx], [y+dy, y+dy], [z, z+dz], **kwargs)
ax.plot3D([x+dx, x+dx], [y, y], [z, z+dz], **kwargs)

def plotBoxAndItems(self,title=""):
""" side effective. Plot the Bin and the items it contains. """
fig = plt.figure()
axGlob = plt.axes(projection='3d')
# . plot scatola
self._plotCube(axGlob,0, 0, 0, float(self.width), float(self.height), float(self.depth) )
# . plot intems in the box
colorList = ["black", "blue", "magenta", "orange"]
counter = 0
for item in self.items:
x,y,z = item.position
color = colorList[counter % len(colorList)]
self._plotCube(axGlob, float(x), float(y), float(z),
float(item.width), float(item.height), float(item.depth),
color=color)
counter = counter + 1
plt.title(title)
plt.show()


class Packer:
def __init__(self):
self.bins = []
Expand Down

0 comments on commit 7dfd7e0

Please sign in to comment.