Reputation: 51
I have a square that is grid into many small cells. Each cell has a size of 0.1*0.1. Several zigzag lines are drawn to divided that square into sub-area. The zigzag lines only follow the cell edges.
The vertices that these zigzag lines cross are calculated and stored in a different matrix. In this case, there are 6 zigzag lines that meet at the center, thus there are 6 matrix that store the coordinated of the lines.
The center of each cell, as well as the four vertices, are calculated and store in a big matrix. Now, if I want to track to which sub-area each of the cell belongs, what looping algorithm should I use?
Say, we mark the top left area as 1, and count it clockwise. Then the cells in the top left area should be marked 1. Cells in the top right area should be marked 2, and so on.
Upvotes: 0
Views: 260
Reputation:
From the given example, we can infer that the areas are "sectors" with a common center and the radial lines meeting the outline.
You can get the starting edges (on the outline) of the zigzag lines from their respective array. They each separate two cells belonging to different areas. By computing the angles and sorting them, you can number the areas increasingly and associate them a starting cell.
Now "draw" the zigzag lines in the big matrix (every cell having two flags that indicate the presence of an edge to the right or below it). Then, starting from the cell of every area, use a seed filling algorithm. You will need to modify the basic algorithm to account for the presence of the edges.
Upvotes: 0