F
F
Felino2019-12-19 16:53:54
JavaScript
Felino, 2019-12-19 16:53:54

Implementation, what and how?

Good afternoon!
Tell me in which direction to dig or maybe someone has examples.
The essence of the problem:
There is a selected area of ​​arbitrary size, there are geometric shapes with height and width attributes, you need to place these shapes optimally inside the selected area, so that they do not overlap each other, and there are no holes with empty space between them.
example:
Shapes

[
  {
    "width ": 50,
    "height": 20
  },
  {
    "width ": 30,
    "height": 10
  },
  {
    "width ": 75,
    "height": 70
  }
]

The selection area below them is 500px by 700px.
How I think to do:
1. Read the data of the figures from JSON
2. Check whether these figures fit into the specified area or not (by adding their volumes and comparing the volume of the selected area)
3. Using the iteration method, try to insert these figures starting from their width (if the width they don’t pass, lower them below the height of the first figure and there try to insert the figures again by brute force and so on until I go through all the received figures)
4. draw by coordinates later on the
web , 3 paragraph is), what can you advise

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2019-12-19
@abberati

If you want to do it thoughtfully and intelligently, read about matrices, operations on matrices, and all that interesting stuff.
This is the first course in engineering mathematics, it is enough just to type formulas from there and arrange them in the right order.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question