1

I have gotten into programming recently, and was looking for some help.

For the algorithm that I'm trying to implement, there are two rectangle grids, with each cell containing an object. You can think of it as a 2D array of with an x-y coordinate assigned on its origin.

Given two integer number "m" and "n", I'm going to mark n cells in one grid and (m-n) cells in the other grid, so that the marked area in one grid is the closest location for the marked area in the other grid (vise versa).

For example, let's say grid A exists between coordinate (x1, y1) and (x2, y2), and grid B exists between (a1, b1) and (a2, b2) (x1 < x2, y1 < y2, etc). If x2 < a1 and y2 < b1 (ie. grid B is on the top right side of grid A), the top right corner of grid A and bottom left corner of grid B will be marked.

I tried to design this using switch cases, but there seemed to be too many cases to be considered. If you know any better ways to do so, I would really appreciate if you can help me out.

If my question was too vague to understand, don't hesitate to point them out :)

4

1 回答 1

0

我不确定我是否理解,但我认为您的意思是碰撞检测。如果我是对的,它看起来大约像这样,对于一个正方形:

(x + xYWidth >= a && x <= a + aBWidth) && (y + xYWidth >= b && y <= b + aBWidth)

对于矩形:确定两个矩形是否相互重叠?

于 2015-07-17T20:53:51.310 回答