Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

RectanglePacking

Guides

  • Rectangle Packing

Symbols

  • PackRectangles
  • RectanglePacker
JasonB`RectanglePacking`
PackRectangles
​
PackRectangles
[boundingbox,{
rect
1
,
rect
2
,..}]
packs the given
rectangles
in the given bounding box.
​
​
PackRectangles
[boundingbox,rectangles,method]
uses the given
method
to pack
rectangles
.
​
Details and Options

Examples  
(3)
Basic Examples  
(1)
Pack a sequence of squares into a larger square:
In[1]:=
PackRectangles
[{100,100},Table[{n,n},{n,30}]]
Out[1]=
{{{13,99},{14,100}},{{25,98},{27,100}},{{54,96},{57,99}},{{50,96},{54,100}},{{30,25},{35,30}},{{91,87},{97,93}},{{91,80},{98,87}},{{90,72},{98,80}},{{90,63},{99,72}},{{50,86},{60,96}},{{25,87},{36,98}},{{13,87},{25,99}},{{0,87},{13,100}},{{36,86},{50,100}},{{76,83},{91,98}},{{60,84},{76,100}},{{73,66},{90,83}},{{55,66},{73,84}},{{55,47},{74,66}},{{79,21},{99,41}},{{79,0},{100,21}},{{78,41},{100,63}},{{55,24},{78,47}},{{55,0},{79,24}},{{30,0},{55,25}},{{29,30},{55,56}},{{28,59},{55,86}},{{0,59},{28,87}},{{0,30},{29,59}},{{0,0},{30,30}}}
In[2]:=
$RectanglePackingMethods
Out[2]=
{MaxRects,Guillotine,Shelf,Skyline,MaxRectsBestShortSide,MaxRectsBestLongSide,MaxRectsBestArea,MaxRectsBottomLeft,MaxRectsContactPoint,GuillotineBestShortSide,GuillotineBestLongSide,GuillotineBestArea,GuillotineWorstShortSide,GuillotineWorstLongSide,GuillotineWorstArea,ShelfNextFit,ShelfFirstFit,ShelfBestAreaFit,ShelfBestHeightFit,ShelfBestWidthFit,ShelfWorstAreaFit,ShelfWorstWidthFit,SkylineBottomLeft,SkylineBestFit}
Visualize the result:
In[3]:=
Graphics[{EdgeForm[Black],FaceForm[None],Rectangle@@@%},FrameTrue]
Out[3]=
In[4]:=
PackRectangles
[{100,100},Table[{n,n},{n,30}],"SkylineBestFit"]
Out[4]=
{{0,0},{1,1}},{{1,0},{3,2}},{{3,0},{6,3}},{{6,0},{10,4}},{{10,0},{15,5}},{{15,0},{21,6}},{{21,0},{28,7}},{{28,0},{36,8}},{{36,0},{45,9}},{{45,0},{55,10}},{{55,0},{66,11}},{{66,0},{78,12}},{{78,0},{91,13}},{{21,8},{35,22}},{{36,10},{51,25}},{{55,12},{71,28}},{{71,13},{88,30}},{{71,30},{89,48}},{{1,6},{20,25}},{{1,25},{21,45}},{{1,45},{22,66}},{{1,66},{23,88}},{{23,25},{46,48}},{{23,48},{47,72}},{{23,72},{48,97}},{{55,48},{81,74}},Failure

Input: {27,27}
Tag: UnplacedRectangle
,Failure

Input: {28,28}
Tag: UnplacedRectangle
,Failure

Input: {29,29}
Tag: UnplacedRectangle
,Failure

Input: {30,30}
Tag: UnplacedRectangle

Scope  
(1)

Options  
(1)

SeeAlso
RectanglePacker
 
▪
Rectangle
RelatedGuides
▪
Rectangle Packing
RelatedLinks
RectangleBinPack library,
▪
https://github.com/juj/RectangleBinPack
A thousand ways to pack the bin-a practical approach to two-dimensional rectangle bin packing. Jukka Jylänki. 2010.
▪
[more info]
""

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com