Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds plot method to Bin object. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions py3dbp/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from .constants import RotationType, Axis
from .auxiliary_methods import intersect, set_to_decimal

# required to plot a representation of Bin and contained items
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d


DEFAULT_NUMBER_OF_DECIMALS = 3
START_POSITION = [0, 0, 0]

Expand Down Expand Up @@ -128,6 +133,37 @@ def put_item(self, item, pivot):
item.position = valid_item_position

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:
Expand Down