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

  • SEARCH
  • Home
  • 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 6649981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:50:21+00:00 2026-05-26T00:50:21+00:00

I have a container rectangle and element rectangle, both are specified only in height

  • 0

I have a container rectangle and element rectangle, both are specified only in height and width. Using PHP I need to figure out what positions and orientation would allow for the most possible blits of the element within the container having absolutely no overlap.

An Example :

$container = array(5000,2000);
$element = array(300,200);

The output should be an array of “blit” arrays (or objects) like so

$blit_object = array($x,$y,$rotation_degrees);
  • 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-05-26T00:50:21+00:00Added an answer on May 26, 2026 at 12:50 am

    Well, since no one is answering me, I am just going to show my “trial and error” solution in case anyone else ever needs it.

    It calculates the two basic layout options and sees which one has the most and uses that.

    function MakeBlits($container,$element)
    {
        $container_x = $container[0];
        $container_y = $container[1];
        $options = array();
        for($i = 0;$i<=1;$i++)
        {
            if($i == 0)
            {
                $element_x = $element[0];
                $element_y = $element[1];
            }
            else
    
    
    {
            $element_x = $element[1];
            $element_y = $element[0];
        }
        $test_x = floor($container_x/$element_x);
        $test_y = floor($container_y/$element_y);
        $test_remainder_x = $container_x - $test_x*$element_x;
        $test_remainder_y = $container_y - $test_y*$element_y;
        $test_x2 = 0;
        $test_x3 = 0;
        $test_y2 = 0;
        $test_y3 = 0;
        if($test_remainder_x > $element_y)
        {
            $test_x2 = floor($test_remainder_x/$element_y);
            $test_y2 = floor($container_y/$element_x);
        }
        if($test_remainder_y > $element_x)
        {
            $test_x3 = floor($container_x/$element_y);
            $test_y3 = floor($test_remainder_y/$element_x);
        }
        $options[] = array(
            'total'=>($test_x*$test_y)+($test_x2*$test_y2)+($test_x3*$test_y3),
            'x'=>$test_x,
            'y'=>$test_y,
            'x2'=>$test_x2,
            'y2'=>$test_y2,
            'x3'=>$test_x3,
            'y3'=>$test_y3
        );
    }
    if($options[0]['total']>=$options[1]['total'])
    {
        $option = $options[0];
        $rotate = 0;
        $width = $element[0];
        $height = $element[1];
    
    }
    else
    {
        $option = $options[1];
        $rotate = -90;
        $width = $element[1];
        $height = $element[0];
    }
    $blit_objects = array();
    for($i=0;$i<$option['x'];$i++)
    {
        for($j=0;$j<$option['y'];$j++)
        {
            $blit_objects[] = array(
                'x'=>$i*$width,
                'y'=>$j*$height,
                'rotation'=>$rotate);
        }
    }
    for($k = 0;$k < $option['x2'];$k++)
    {
        for($l = 0;$l < $option['y2'];$l++)
        {
            $blit_objects[] = array(
                'x'=>$i*$width + $k*$height,
                'y'=>$l*$width,
                'rotation'=>$rotate+90);
        }
    }
    for($k = 0;$k < $option['x3'];$k++)
    {
        for($l = 0;$l < $option['y3'];$l++)
        {
            $blit_objects[] = array(
                'x'=>$k*$height,
                'y'=>$j*$height+$l*$width,
                'rotation'=>$rotate+90);
        }
    }
    return $blit_objects;
    

    }

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

Sidebar

Related Questions

I have a container div with a fixed width and height , with overflow:
I have a container element which I need to resize as its contents change.
I have a container div that holds two internal divs; both should take 100%
I have a container filled with pairs. I want to iterate in it using
I have a container div element that has overflow:hidden on it. Unfortunately this property
I have a container element say <div id=myContainer> <form action= method=post> Radio: <input type=radio
I have these container objects (let's call them Container) in a list. Each of
I have a container of custom controls each of which have 2 controls in
Let's say I have a container (std::vector) of pointers used by a multi-threaded application.
I have a div container and have defined its style as follows: div#tbl-container {

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.