0

I know this is more high school math(wow been a long time since I was there) but I am trying to solve this programatically so I am reaching out to the collective knowledge of stackoverflow

Given this layout:

alt text

Midpoint is my reference point and in an array I have the vector points of all other points (P)

I can get to this state with code of having the light blue area by breaking it into four quadrants and doing a lame bubble sort to find largest(y) or lowest(x) value in each quadrant.

I need to find only the quadrants that outer border fully hits red no white space. For example the lower left and the up right dont have any white space hitting the light blue rectangle.

I am sure my terminology is all off here and im not looking for any specific code but if someone could point me to a more optimized solution for this problem or the next step in what I already have.

Thank you

Community
  • 1
  • 1
Armychimp
  • 123
  • 2
  • 6
  • I'm not sure I fully understand your question... if you always have the same layout, it seems like you could just say, "Well, the top right and lower left corners are always adjacent to red and not white space," and call it a day. That seems far too simple, though, so there must be more to it than that. Can you elaborate a little on what information you have available? – John Hyland Sep 06 '09 at 19:22
  • The red rectangles could be of any size and anywhere. Filling whole quadrants / going between them. Based on the refrence point given which in this example is the mid point I need to build out inner rectangle(s) (split by the axis in this example) and find out which of these rectangles bumps fully against either red or blue on all sies. Any ones not touching only blue or red (touching white space) need to be dropped and the remaining blue area will be come red. I know the 4 vector points of each red rectangle. – Armychimp Sep 06 '09 at 19:56
  • Good analogy given by my wife is the blue is a 4 pools and I need to find the pools with a leak (upper left and lower right) axis can never leak so I only need to check two sides. – Armychimp Sep 06 '09 at 19:56

2 Answers2

0

I might do some BFI solution first, then perhaps look to generalize it or at least reduce it to a table-drive loop.

So, if it's exactly these shapes, and not a general solution, I think you should proceed sort of like this:

  1. Derive the coordinates of the blue rectangle. I suspect one thing that's confusing you is that you have each individual x and y for the blue rect but you can't easily loop through them.

  2. Derive the coordinates of the midpoint of each rectangle edge. You are going to need this because you care about quadrants. It will be trivial to do this once you have done 1.

  3. Write different code for each 1/2 rectangle edge. There is no doubt a more clever way but this will get working code.

  4. Make it more elegant now if you care. I betg you can reduce the rules to an 8-row table full of things like 1, -1, or something like that.

DigitalRoss
  • 143,651
  • 25
  • 248
  • 329
0

First, you can't define red area by a single vector, since it's disjoint. You need the same number of vectors as the number of distant red regions.

Second, do we assume that different red figures neither intersect nor share a border? In the next clause I do.

Third, under assumption in point 2, the quadrant will have all red outer side iff there exists a contiguous red figure that intersects both its axes (i.e. rays). To determine this for all quadrants, you should only traverse all (P) points in the order they're given. This takes linear time and solves the problem.

P Shved
  • 96,026
  • 17
  • 121
  • 165