I am rectangular on the stage in random situations, and I do not want to overlap them. So for each rectangle, I need to find an empty area to give it space.
I have thought about trying a random situation, if it is
in the private function (R: rectangle): boolean {var free: boolean = true; (Var i: int = 0; i & lt; numChildren; i ++) for free & amp; Amp; = Amp; = Meet (i) .getBounds (this) .containsRect (r); Return free; }
And if this is wrong then try another random situation.
The problem is that if there is no free space, then I am trying to always have random posts.
Is this an elegant solution?
Let's be the area of the S forum Let's have a small rectangular area that we want to attract. A potential deterministic approach:
When you draw a rectangle at an empty stage, then it divides the phase into maximum 4 which can fit into the next rectangle when you If you draw your next rectangle, then one or two areas are divided into maximum 4 sub-regions (each) which can fit a rectangle, etc. You will never make more than the N area, where S is the area of your step, and A. There is an area of your smallest rectangle, keep a list of areas (without order sorting properly), each of which is shown on the basis of its four corner points , And each is labeled with its area, and uses a weighted-by-field with the size of the reservoir of 1 to select one area, in which its area Most through proportional likely the list and place a rectangle at a random location in a neighborhood then that area. (Choose a random point from the lower left part of the area, which allows you to draw a rectangle in the form of a left-hand corner without killing the top or right wall.)
Do not start with empty steps, then just list the areas available in O (n), (for example, by reprinting all the existing rectangles on the empty phase in any order), for one of your first points Before attracting a new rectangle.
Note: You can change the size of your reservoir to Kashmir, in the next phase to choose the edges one after the other.
Note 2: You can optionally keep the available areas equal to each strand weights in a tree. The sum of the areas of sub-tree areas in the field of stage. After that, to select an area in O. (logn), we basically choose the root with the field of root area / s, or with each probabilistic weight / s with sub-division. Although the tree will be troubled by re-balancing. P << ol> runtime: o (n)
space: o (n)
A potential random approach: < / Strong>
Select a point on the stage at random. If you can draw one or more rectangles in which the point is (not just the one in the lower left corner), then return a randomly rectangular rectangle in which there is a point in which the rectangle without prejudice with some nuances It is possible to make the situation, but I will leave it to you.
In the worst place, a place for our rectangle is very large and the rest of the phase is filled. Therefore this approach succeeds with the possibility> 1 / N, or failed with the possibility & lt; 1-1 / N Repeat N times We are now unsuccessful with the possibility & lt; (1-1 / N) ^ N & LT; 1 / E By failing we mean that there is a place for our rectangle, but we did not get it. By being successful we mean that if one has existed then we have got a place. To achieve a fair chance of success, we repeat NLGO (n) times for the probability of 1 / n of failure, or n² times for 1 / e ^ n probability of failure.
Summary: As long as we try to stop a place after trying NLOG (or N²), in that situation we can believe that there is no place.
- Runtime: o (nljn) o (n²) for high probability of success space: o (1)
Comments
Post a Comment