I used to be a package handler and was very slow at first. Part of the job was to find the appropriate barcode and then scan it.
I sped up a lot after realizing that if I grab opposite corners, then rotate it around that axis with the boxes about the same distance from me in my 'power zone'. By tilting it so the silhouette formed a hexagon while rotating it along that axis and moving one of the corners closer to myself, I get to see scan more of the surface area quicker than from going to one face at a time. There was the last step of making the barcode presentable once it starts to appear.
So, I was curious how to refine this method to be optimal at finding the barcode with the least amount of effort when I don't necessarily know which side the barcode is on and each successive box (cuboid) is randomly given to me.
I am sorry if this might be too big of a problem to post here, but I want to appease my curiosity.
Pseudocode
Generate the random box.
Look at the box and find the edges.
Rotate along two opposite corners. (I am not sure which ones to exactly choose. I think it is the ones that make the largest hexagonal silhouette. But I am not sure how to mathematically decide that.)
Once the barcode starts to show up change the rotation so that the path for the increase in the size of the rectangle is accelerated until it is large and clear enough to scan with a barcode scanner.
Generating the box (sometimes the sticker sticks out):
randomCuboidCoordinates[] := Module[
{x1, x2, y1, y2, z1, z2},
{x1, x2} = Sort[RandomReal[{0, 10}, 2]];
{y1, y2} = Sort[RandomReal[{0, 10}, 2]];
{z1, z2} = Sort[RandomReal[{0, 10}, 2]];
{{x1, y1, z1}, {x2, y2, z2}}
]
randomSurfaceRectangle[coords_] := Module[
{x1, x2, y1, y2, z1, z2, face, width, height, x, y, z, rect},
{{x1, y1, z1}, {x2, y2, z2}} = coords;
face = RandomInteger[{1, 6}];
width = RandomReal[{1, Min[x2 - x1, y2 - y1, z2 - z1]}];
height = RandomReal[{1, Min[x2 - x1, y2 - y1, z2 - z1]}];
Switch[
face,
1,
x = RandomReal[{x1, x2 - width}];
y = RandomReal[{y1, y2 - height}];
rect = Polygon[{{x, y, z1}, {x + width, y, z1}, {x + width, y + height, z1}, {x, y + height, z1}}],
2,
x = RandomReal[{x1, x2 - width}];
y = RandomReal[{y1, y2 - height}];
rect = Polygon[{{x, y, z2}, {x + width, y, z2}, {x + width, y + height, z2}, {x, y + height, z2}}],
3,
y = RandomReal[{y1, y2 - height}];
z = RandomReal[{z1, z2 - width}];
rect = Polygon[{{x1, y, z}, {x1, y, z + width}, {x1, y + height, z + width}, {x1, y + height, z}}],
4,
y = RandomReal[{y1, y2 - height}];
z = RandomReal[{z1, z2 - width}];
rect = Polygon[{{x2, y, z}, {x2, y, z + width}, {x2, y + height, z + width}, {x2, y + height, z}}],
5,
x = RandomReal[{x1, x2 - width}];
z = RandomReal[{z1, z2 - height}];
rect = Polygon[{{x, y1, z}, {x + width, y1, z}, {x + width, y1, z + height}, {x, y1, z + height}}],
6,
x = RandomReal[{x1, x2 - width}];
z = RandomReal[{z1, z2 - height}];
rect = Polygon[{{x, y2, z}, {x + width, y2, z}, {x + width, y2, z + height}, {x, y2, z + height}}]
];
rect
]
drawRandomCuboidWithRectangle[] := Module[
{coords, rect},
coords = randomCuboidCoordinates[];
rect = randomSurfaceRectangle[coords];
Show[{Graphics3D[{
{RGBColor[202/255, 142/255, 91/255, 1], Cuboid[coords[[1]], coords[[2]]]}
},Boxed->False],Graphics3D[{Blue, Opacity[1], rect},Boxed->False]
}]]
img=drawRandomCuboidWithRectangle[]
which gave:
I would rather do this approach then using Texture[]
, but the blue and the brown don't display how I want where the blue takes precedence.
I explicitly wrote the code to generate each face instead of directly just using Cuboid[]
because the thought is to make each face randomly chosen for where the blue rectangle will be. My thought is to not have Bertrand's Paradox situation is to weight each face by the area of itself compared to the total surface area.
Finding the Edges (partially done):
data=ImageCorners[img];
rasterizedImageEdgeDataGraph=EdgeDetect[
Rasterize[
NearestNeighborGraph[data,{4,15}]
]
,1,.25]
ridges = ImageAdjust[RidgeFilter[rasterizedImageEdgeDataGraph, .1]];
segments = FindImageShapes[ridges, "LineSegment"];
HighlightImage[rasterizedImageEdgeDataGraph, segments]
gives respectively:
And while I know segments
gives the list of line segments, I don't know how to get where they are and how they relate since AdjacencyMatrix[segments]
throws an error.