Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9107799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:39:35+00:00 2026-06-17T02:39:35+00:00

Possible Duplicate: Algorithm needed for packing rectangles in a fairly optimal way I have

  • 0

Possible Duplicate:
Algorithm needed for packing rectangles in a fairly optimal way

I have N rectangles, each of a random size (random width & height). All rectangles are parallel to the X & Y axes. I’m looking for an algorithm that helps me arrange these rectangles side-by-side in a way that the resulting bounding rectangle has minimum area and the potential gaps around / between the input rectangles are as small as possible. Rectangles cannot be rotated and may not overlap each other.

(I need these to automate the arrangement of game sprites so I can create sprite sheets and save sprite locations from the various images I get from animators.)

For example:

+---+   +----------+
| 1 |   |    2     |
+---+   +----------+                 +----------+..           +---+----------+
                                     |    2     |..           | 1 |    2     |
+--------+                ===>       +--------+-+-+    vs     +---+----+-----+
|        |                           |        | 1 |           |        |......
|    3   |                           |    3   +---+           |    3   |......
+--------+                           +--------+....           +--------+......

                                       Unused: 8                 Unused: 18

Unused space is marked by the dots (.) in the drawing. Since the first result has a bounding rectangle with smaller unused space, it’d be preferable to find this arrangement of the input rectangles.

Is there an algorithm already that helps with this? I did a lot of googling but most results are related to finding minimum bounding rectangle or to finding if N rectangles cover a pre-determined area.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:39:36+00:00Added an answer on June 17, 2026 at 2:39 am

    The solution suggested at What algorithm can be used for packing rectangles of different sizes into the smallest rectangle possible in a fairly optimal way? looks nice, but I would change it slightly: Rather than greedily extend the bounding box by the smallest area, greedily extend it to the smallest area leaving space greater than the area used by the remaining rectangles. Also, select the next rectangle by greatest dimension, not greatest area.

    That should give it more room early on, and prevent it from always running out of space at the last minute and leaving a mostly-empty margin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: optimal algorithm for finding unique divisors I have asked this question before,
Possible Duplicate: Algorithm for generating a random number is posible to generate a random
Possible Duplicate: C#: Is using Random and OrderBy a good shuffle algorithm? I want
Possible Duplicate: How exactly should I implement a shuffle or random-number algorithm for an
Possible Duplicate: An algorithm to "spacify" CamelCased strings I have a string like this:
Possible Duplicate: How to apply DBSCAN algorithm on grouping of similar url I have
Possible Duplicate: Does anyone have a good Proper Case algorithm I am currently in
Possible Duplicate: Fast convolution algorithm I have two arrays a and b of N
Possible Duplicate: Fastest Hash Algorithm for Text Data For some reason I have to
Possible Duplicate: Algorithm for generating a random number Hi i need to assign a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.