Skip to content
PalletLab
Stacking rules

Stacking rules

checkPlacement() answers one question for every algorithm: is this placement allowed? Its checks run cheapest first and the first failure returns immediately (fail fast), because a packer calls it thousands of times per pallet.

OrderCheckCost
1Inside the pallet and under max heightO(1)
2Total load under maxO(1)
3No overlap; nothing above the spot; who supports usO(n) single pass
4Support ratio ≥ 75%O(1) after the pass
5Center inside the support polygonO(k log k)
6Not heavier than any supporterO(supporters)

Support ratio

Supported area = the sum of footprint overlaps with cartons whose top equals our bottom (or the whole base on the deck). Supporters cannot overlap each other (they would collide), so summing is safe.

The support polygon

Something stays standing when its center of mass, projected straight down, falls inside the outline of its contacts: the support polygon, which is the convex hull of the contact areas. A bridge across two pillars has only 50% of its area supported but is perfectly stable, because its centre is inside the hull. The live model shows a carton sliding across two pillars: blue is the hull, the carton turns orange when its centre leaves it.

Convex hull: Andrew's monotone chain

Sort the points by x then y; sweep left to right building the lower hull, then right to left for the upper hull. Whenever the last three points don't turn left, pop the middle one. O(k log k), the sort dominating; each point is pushed and popped at most once per sweep.

The turn test is the 2D cross product:

int64_t cross(P2 o, P2 a, P2 b) {
    return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);  // > 0: left turn
}

Box centres can land on half millimetres, so the code doubles every coordinate and the maths stays in exact integers.

Load bearing and reachability

  • Load bearing: a carton may not rest on a lighter one. Production systems sum the load down the whole "rests on" graph against each carton's crush strength.
  • Reachable from above: a top-down gripper cannot slide a carton under an overhang, even into free space. Physically valid is not the same as robot-executable.