Wxsr45 (deep sorting)

Source: Internet
Author: User

 

By wxsr)
2008.11
Deep hiding at 45 degreesAlgorithm

Aside from the 45-degree deep hidden algorithms on the Internet.

In the opening chapter, I want to talk about an idea before the completion of my implicit algorithm:

Before talking about this idea, let's talk about a condition for its establishment:
[Function: getonlydepthfunc (target: displayobject, source: array): object]

Target -- an item in the item list.
Source -- Item List (including target)

The final result of this condition method is to return the unique depth [itemdepth] of an item in the current item list and the list of remaining items (residualsource) with the target removed ]. (You do not need to consider the depth changes of other items, because only the depth of target is concerned here, in fact, each time you determine the depth of an item, the depth of the remaining item may change, so you do not need to consider the depth changes of other items)

Well, don't ask how this method is implemented. The specific implementation will be mentioned below. Let's talk about my ideas about this algorithm.

If there is an item list with a length of N [sourcen: array], because the known condition method [getonlydepthfunc] can return the depth of an item in the item list, can we?
Use the "getonlydepthfunc" method and the "target" parameter to specify an item in the "residualsource" List of the remaining items after each execution, the source value is assigned to the "residualsource" list of remaining items after each execution, in addition, the unique depth of target in the fragment item list obtained each time (itemdepth) is stored and restored to the depth of the item corresponding to the source item list (sourcen: array, then we should be able to get the new array of items whose depth has been sorted.

The above is my idea. To make it easier for everyone to understand, here are some important points to pay attention. The depth returned by method [getonlydepthfunc] is only the determined depth in the source list.
The remaining item list residualsource is the remaining part list of the total item list sourcen, so they have a coupling.

I am doing this. Before sorting me, declare an empty array [rebacksource] with the same length as [sourcen]. Then, from the first time, take the depth obtained for the first time as the index, and assign the corresponding items to the bits of the [rebacksource] array. And then the next time. This is because the remaining items are listed at the beginning of 2nd. Therefore, the obtained depth [itemdepth] is only relative to the list of remaining items returned each time.
The unique depth of residualsource. However, because it is a list of remaining items, we can obtain the position in the total list through the deep index [itemdepth] From the start item to the undefiend item number. That is, the specific items in the residualsource list. Then assign the target value to this location. List of items executed by Yi Dai (sourcen: array) in length. Efficiency is not considered, because the length of the remaining list is reduced each time and no sorting is required. This is an efficient nested loop.

The process can be roughly expressed as follows:

Assume that the first result is 3 and the total number of items is 6.

[Residualsource] = [undefined, [First result], undefined]
.
.
The result of the 2nd hypothesis is also 3, because the parameter list is the remaining list, you only need to find the 4th undefiend positions in the remaining 6 undefiend (because the array starts from 0, 3 is actually relative to 4th bits)

[Residualsource] = [undefined, [First result], [second result], undefined, undefined]
.
.

The result of the first hypothesis is 0.
[Residualsource] = [third result], undefined, undefined, [First result], [second result], undefined, undefined]
.
.
.
.
End 7th times

In this way, the system continues to evolve until the cycle ends.

 

Optimization: I use a two-way method for optimization.

How is the differentiation method? That is, when we find the first item and determine its depth, we then perform the above steps on the obtained two groups of content, knowing that the sorting is complete. What are the benefits of doing so? 1. We can greatly save the number of cycles for judgment. II. Of course, it is more accurate, but it should be noted that the key point of efficiency improvement is how to use interpolation when we get results.

 

 

The following describes how to implement the key conditions and methods.

To implement this method, we must know the four boundary positions of each item in a 45-degree view (for the reason, see below ). I will not talk about the specific implementation, because this is not enough. Here we just talk about the principle. Finding the four-boundary square location is also a basic task for 45-degree map.

Continue below

How to find the unique depth of an item is not difficult to implement, that is, to determine the dephtmin array of all items whose depth is smaller than yourself, or the depthmax array whose depth is larger than yourself
In this way, you can know the depth of the item. The depth of this item is the number of dephtmin elements plus 1, or the number of depthmax elements minus one
You can use the 9th gongge method.

There are many ways to implement the 9 gangular method. I use the algorithm obtained through continuous scrutiny. Below is a reference segment.
Brief Description

{[L]} {x, y} {[T]}
{X, y}
{[B]} {x, y} {[R]}

[L], [T], [R], [B] The coordinates of the four 45-degree Boundary Coordinate points of an item, that is, the necessary conditions for the getonlydepthfunc method I mentioned earlier.

Item is a non-target object in the getonlydepthfunc loop list,

Target is the target parameter of getonlydepthfunc.

Formula:

Item. Sider = (target. [B]. Y-item. [l]. Y)
Item. Sidel = (item. [B]. Y-target. [l]. Y)
Item. sideb = (target. [T]. x-item.minZ. [l]. X)
Item. sidet = (item. [T]. X-target. [l]. X)

When item. Sider <0, item is on the right of target;
When item. Sidel <0, item is on the left of target;
When item. sidet <0, item is above target;
When item. sideb <0, the item is under the target;
When item. Sidel <0 and item. sidet <0, the item is located at the top left of target;
When item. Sidel <0 and item. sideb <0, item is located at the lower left of target;
When item. Sider <0 and item. sidet <0, item is located at the upper right side of target;
When item. Sider <0 and item. sideb <0, item is located at the lower right side of target;
When the value 4 above is-1, the target corresponds to the boundary of the item.

 

Through this algorithm, we can easily determine a 9-grid distribution of the relationship between the target and the position of other items in the item list. That is, the icon below

What should I do if I get this 9th gongge? Here I will explain the depth of the layout at 45 degrees, that is, the basic principle of the painter's algorithm;

{6} {3} {0}
{7} {4} {1}
{8} {5} {2}

The depth of an item under 45 degrees should be like this. The lower the Angle of View depth, the higher the Angle of View depth.


As shown in the figure above, the target should be at {4}, and the two arrays we mentioned earlier: dephtmin and dephtmax
It should be equal to dephtmin = [{0}, {1}, {2}, {3 }]
Dephtmax = [{5}, {6}, {7}, {8 }]
Of course, the number of these two arrays is determined based on the specific number obtained by the formula above,

Okay, this is the end of the tutorial. If you don't understand it, you can reply or, mes me,

You are welcome to talk about the above ideas. I have already implemented the problems and the confidentiality of the project, so I will not issue an example. But it can be said that the results are very good, so I 'd like to share this tutorial with you. If you want to reprint it, please express it. Thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.