let\'s say I have a huge set of non-overlapping rectangle with integer coordinates, who are fixed once and for all
I have another rectangle A with integer coordinate
Method (A)
You could use an interval tree or segment tree. If the trees were created so that they would be balanced this would give you a run time of O(log n). I assume this type of preprocessing is practical because it would only happen once (it seems like you are more concerned with the runtime once the rectangle starts moving than you are with the amount of initial preprocessing for the first time). The amount of space would be O(n) or O(n log n) depending on your choice above.
Method (B)
Given that your large set of rectangles are of fixed size and never change their coordinates and that they are non-overlapping, you could try a somewhat different style of algorithm/heuristic than proposed by others here (assuming you can live with a one-time, upfront preprocessing fee).
Preprocessing Algorithm [O(n log n) or O(n^2) runtime {only run once though}, O(n) space]
Compute a probability distribution function and a cumulative distribution function of the horizontal coordinates. (Runtime of O(1) to O(n^2) depending on method used and what kind of distribution your data has)
a) If your rectangles' horizontal coordinates follow some naturally occurring process then you can probably estimate their distribution function by using a known distribution (ex: normal, exponential, uniform, etc.).
b) If your rectangles' horizontal coordinates do not follow a known distribution, then you can calculate a custom/estimated distribution by creating a histogram.
Compute a probability distribution function and a cumulative distribution function of the vertical coordinates.
a) If your rectangles' vertical coordinates follow some naturally occurring process then you can probably estimate their distribution function by using a known distribution (ex: normal, exponential, uniform, etc.).
b) If your rectangles' vertical coordinates do not follow a known distribution, then you can calculate a custom/estimated distribution by creating a histogram.
Real-time Intersection Finding Algorithm [Anywhere from O(1) to O(log n) to O(n) {note: if O(n), then the constant in front of n would be very small} run time depending on how well the distribution functions fit the dataset]
Taking the horizontal coordinate of your moving rectangle and plug it into the cumulative density function for the horizontal coordinates of the many rectangles. This will output a probability (value between 0 and 1). Multiply this value times n (where n is the number of many rectangles you have). This value will be the array index to check in the sorted rectangle list. If the rectangle of this array index happens to be intersecting then you are done and can proceed to the next step. Otherwise, you have to scan the surrounding neighbors to determine if the neighbors intersect with the moving rectangle. You can attack this portion of the problem multiple ways:
a) do a linear scan until finding the intersecting rectangle or finding a rectangle on the other side of the moving rectangle
b) calculate a confidence interval using the probability density functions you calculated to give you a best guess at potential boundaries (i.e. an interval where an intersection must lie). Then do a binary search on this small interval. If the binary search fails then revert back to a linear search in part (a).
Do the same thing as step 1, but do it for the vertical portions rather than the horizontal parts.
If step 1 yielded an intersection and step 2 yielded an intersection and the intersecting rectangle in step 1 was the same rectangle as in step 2, then the rectangle must intersect with the moving rectangle. Otherwise there is no intersection.
I'll bet you could use some kind of derivation of a quadtree to do this. Take a look at this example.
Create a matrix containing "quadrant" elements, where each quadrant represents an N*M space within your system, with N and M being the width and height of the widest and tallest rectangles, respectively. Each rectangle will be placed in a quadrant element based on its upper left corner (thus, every rectangle will be in exactly one quadrant). Given a rectangle A, check for collisions between rectangles in the A's own quadrant and the 8 adjacent quadrants.
This is an algorithm I recall seeing recommended as a simple optimization to brute force hit-tests in collision detection for game design. It works best when you're mostly dealing with small objects, though if you have a couple large objects you can avoid wrecking its efficiency by performing collision detection on them separately and not placing them in a quadrant, thus reducing quadrant size.
You can create two vectors of rectangle indexes (because two diagonal points uniquely define your rectangle), and sort them by one of coordinates. Then you search for overlaps using those two index arrays, which is going to be logarithmic instead of linear complexity.
Topcoder provides a way to determine if a point lies within a rectangle. It says that say we have a point x1,y1 and a rectangle. We should choose a random point very far away from current locality of reference in the rectangular co-ordinate system say x2,y2.
Now we should make a line segment with the points x1,y1 and x2,y2. If this line segment intersects odd number of sides of the given rectangle (it'll be 1 in our case, this method can be extended to general polygons as well) then the point x1,y1 lies inside the rectangle and if it intersects even number of sides it lies outside the rectangle.
Given two rectangles, we need to repeat this process for every vertex of 1 triangle to possibly lie in the second triangle. This way we'd be able to determine if two rectangles overlap even if they are not aligned to the x or y axis.
You can do a random "walking" algorithm ... basically create a list of neighbors for all your fixed position rectangles. Then randomly pick one of the fixed-position rectangles, and check to see where the target rectangle is in comparison to the current fixed-position rectangle. If it's not inside the rectangle you randomly picked as the starting point, then it will be in one of the eight directions which correspond to a given neighbor of your current fixed position rectangle (i.e., for any given rectangle there will be a rectangle in the N, NE, E, SE, S, SW, W, NW directions). Pick the neighboring rectangle in the closest given direction to your target rectangle, and re-test. This is essentially a randomized incremental construction algorithm, and it's performance tends to be very good for geometric problems (typically logarithmic for an individual iteration, and O(n log n) for repeated iterations).