Results 1 to 4 of 4

Thread: [RESOLVED] Paper size fitting algorithm ?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Resolved [RESOLVED] Paper size fitting algorithm ?

    I'm trying to find a way to automatically determine the best paper size to print a file onto.

    Assume you have a list of 2 dimensional paper sizes.
    Then given a 2 dimensional image size, find the best paper fit, where "best"
    means the smallest paper the image can fit on. Rotation is acceptable - meaning the dimensions can be swapped x <-> y if they give the best fit.
    So, given an image 5x9, a page that is 10x5 is acceptable if no other fit is better.

    Also assume the list may contain repeats and swapped dimensions.

    For example:
    image: 209 x 280

    available sizes:
    1: 215 x 279
    2: 279 x 431
    3: 431 x 279
    4: 215 x 355
    5: 184 x 266
    6: 297 x 420
    7: 210 x 297
    8: 165 x 131
    9: 190 x 254

    In this scenario 2,3, 4, 6 and 7 all would work, but 7 is the "best fit".
    1, 5, 8 and 9 are too small.

    Does anyone know of an algorithm to calculate this?

    Thanks.

  2. #2
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Paper size fitting algorithm ?

    Sounds pretty straightforward. Just loop through all available sizes. Check both dimensions against both image dimensions. If one image dimension is bigger than both paper dimensions, then the paper is too small. If both dimensions fit, calculate the remaining area. Check the area against the current minimum area; if less then this is your new "best fit".
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Re: Paper size fitting algorithm ?

    zaza-
    Thanks - I was actually trying that and I thought I had it wrong.
    But I went back and checked, and it seems I was not storing the "smallest" properly.
    I think it's working now - thanks for the prodding...

  4. #4
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Re: Paper size fitting algorithm ?

    Jolly good. Don't forget to mark the thread Resolved.
    I use VB 6, VB.Net 2003 and Office 2010



    Code:
    Excel Graphing | Excel Timer | Excel Tips and Tricks | Add controls in Office | Data tables in Excel | Gaussian random number distribution (VB6/VBA,VB.Net) | Coordinates, Vectors and 3D volumes

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width