Wanneer een diameter van een cirkel (of cirkels te samen) gelijk is aan de breedte of de lengte van een rechthoek (of vierkant) dan is het vrij eenvoudig te berekenen hoeveel cirkels er in een vierkant passen. Maar stel je nu eens voor dat er meerdere cirkels in een rechthoek (of vierkant) moeten worden geplaatst waarbij de cirkels niet allemaal gelijk zijn in afmeting en waarbij je graag een zo optimale indeling wilt realiseren binnen de rechthoek (of het vierkant).

Uiteraard is de voorwaarde dat er geen overlapping van snijpunten mag zijn.

Tijdens het ontwikkelen van planning software ontstond deze vraag. Hoe krijgen we gasflessen, met verschillende afmetingen, zo optimaal mogelijk geladen op een vrachtwagen of in een zogenaamde transportkooi.

Omdat de vraag niet veel voorkomt heb ik de functie, waarmee je dit kunt berekenen, als gratis API beschikbaar gemaakt. Feed-back is uiteraard van harte welkom.

EN

When a diameter of a circle (or circles together) is equal to the width or length of a rectangle (or square), it is quite easy to calculate how many circles fit in a square.

But now imagine that several circles have to be placed in a rectangle (or square) where the circles are not all equal in size and where you would like to realize an optimal layout within the rectangle (or square).

The condition is, of course, that there should be no overlapping of intersections.

This question arose during the development of planning software. How do we get gas bottles, of different sizes, loaded as optimally as possible on a truck or in a so-called transport cage.

Because the question is not common I have made the function, with which you can calculate this, available as a free API. Feed-back is of course very welcome.

Endpoint

Het endpointadres is https://functionbase.nl/api/v2022/circle/rectangle [POST]

Model

Het, JSON, model kent 3 lagen die zijn onder te verdelen in een vierkant, de details van het vierkant en de cirkels die je in het vierkant wilt positioneren.

  • Rectangle (definitie van het vierkant of de rechthoek)

    • Width = De breedte van het vierkant/rechthoek in centimeters of inches – The width of the square/rectangle in centimeters or inches
    • length = De lengte van het vierkant/rechthoek in centimeters of inches – The length of the square/rectangle in centimeters or inches
    • height = De hoogte van het vierkant/rechthoek in centimeters of inches – The height of the square/rectangle in centimeters or inches
    • allowStack = Mag er in het vierkant worden gestapeld. Toekomstig gebruik. – May be stacked in the square. Future use.
    • identitiy = Vrij veld voor de identiteit van het vierkant. – Free field for the identity of the square/rectangle .
    • External = Vrij veld voor een extern nummer. – Free field for an external number.
    • details = Lijst met details – List of details
  • Details (De positie details van de cirkel)

    • row = De rij positie van de cirkel binnen het vierkant/rechthoek. – The row position of the circle within the square/rectangle.
    • Column = De kolom positie van de cirkel binnen het vierkant/rechthoek. – The column position of the circle within the square/rectangle.
    • densityType = Voor toekomstig gebruik. Verplicht. For future use. mandatory.
    • Stack = Stapelhoogte. Voor toekomstig gebruik. – Stack height. For future use.
    • itemNotFit = Response waarde wanneer de object niet binnen het vierkant past. – Response value when the object does not fit inside the square.
    • Circle = Definitie van de cirkel. Zal in de toekomst meerdere functies bevatten. – Circle definition. Will include multiple features in the future.
  • Circle (Definitie van de cirkel)

    • name = De naam van het object (optioneel). – The name of the object (optional).
    • identity = Vrij veld voor identiteit van de cirkel. – Free field for circle identity.
    • external = Externe nummer van de cirkel (optioneel). – External number of the circle (optional).
    • diameter = De diameter van de cirkel (verplicht). – The diameter of the circle (required).
    • height = De hoogte van het object (verplicht maar nog niet in gebruik). The height of the object (mandatory but not yet in use).

Body voorbeeld request (JSON)

{
"Width": 211,
"Length": 115,
"Height": 85,
"AllowStack": false,
"Identitiy": "",
"External": "",
"Details": [
 {
  "Row": 0.0,
  "Column": 0.0,
  "DensityType": 0,
  "Circle": 
   {
    "Name": "",
    "Identitiy": "",
    "Diameter": 15,
    "Height": 47
   }
  },
 {
  "Row": 0.0,
  "Column": 0.0,
  "DensityType": 0,
  "Circle": 
   {
    "Name": "",
    "Identitiy": "",
    "External": "",
    "Diameter": 20,
    "Height": 47
   }
  },…..
]
}

Response voorbeeld

{
    "objectResult": {
        "width": 211,
        "length": 115,
        "height": 85,
        "allowStack": false,
        "identitiy": "",
        "external": "",
        "details": [
            {
                "row": 30.029972485131996,
                "column": 151.7779693010317,
                "densityType": 0,
                "stack": 0,
                "itemNotFit": false,
                "circle": {
                    "name": "",
                    "identitiy": "",
                    "external": "",
                    "diameter": 15,
                    "height": 47
                }
            },
            {
                "row": 104.99354432591645,
                "column": 10.00337273797777,
                "densityType": 0,
                "stack": 0,
                "itemNotFit": false,
                "circle": {
                    "name": "",
                    "identitiy": "",
                    "external": "",
                    "diameter": 20,
                    "height": 47
                }
            },….
        ]
    },
    "objectImage": "https://functionbase.nl/documents/01f4c928-0495-4a1e-a961-235a5473e6ed.jpg",
    "objectBestAreaRatio": 0.761446189735214,
    "objectFit": false,
    "statusCode": 200,
    "statusDescription": ""
}

Response velden

  • objectImage = De link naar het jpg bestand waarin de indeling is weergegeven.
  • objectBestAreaRatio = De dichtheid van de meest optimale situatie.
  • objectFit = Bepaald of alle cirkels passen in het vierkant.
  • statusCode = De statuscode waarmee het resultaat wordt benoemd. Mogelijke statuscodes zijn :
    200 – OK
    500 – ERROR
  • statusDescription = De foutmelding die hoort bij de responsecode

CURL voorbeeld

curl --location --request POST 'https://functionbase.nl/api/v2022/circle/rectangle' \
--header 'Content-Type: application/json' \
--data-raw '{
    "Width": 211,
    "Length": 115,
    "Height": 85,
    "AllowStack": false,
    "Identitiy": "",
    "External": "",
    "Details": [
        {
            "Row": 0.0,
            "Column": 0.0,
            "DensityType": 0,
            "Circle": {
                "Name": "",
                "Identitiy": "",
                "External": "",
                "Diameter": 15,
                "Height": 47
            }
        },
        {
            "Row": 0.0,
            "Column": 0.0,
            "DensityType": 0,
            "Circle": {
                "Name": "",
                "Identitiy": "",
                "External": "",
                "Diameter": 20,
                "Height": 47
            }
        }
]
}

Project informatie

  • Categorie: API