In short:
Split up the Rectangle into the 4 triangles (quadrant), then find which triangle the point is in.
Explanation
Say we are given the Rectangle with the x, y, width, and height.
TL +--------------+ TR
| |
| |
| C |
| |
| |
BL +--------------+ BR
We can then find all the points labeled:
TL: (x, y) //topLeft
TR: (x + width, y) //topRight
BL: (x, y + height) //bottomLeft
BR: (x + width, y + height) //bottomRight
C: (x + width/2, y + height/2)
Then we create our 4 triangles (quadrants) using the same notation you have above:
a: (TL, TR, C)
b: (TL, BL, C)
c: (BL, BR, C)
d: (TR, BR, C)
Using these 4 triangles, check to see if the point is inside, if it is then you found your quadrant.
To find if a point is in a triangle you can use these:
Method1:
public boolean pointInTriangle(Point p)
{
Point a = points[0];
Point b = points[1];
Point c = points[2];
double dot00 = dot(c.x - a.x, c.y - a.y, c.x - a.x, c.y - a.y);
double dot01 = dot(c.x - a.x, c.y - a.y, b.x - a.x, b.y - a.y);
double dot02 = dot(c.x - a.x, c.y - a.y, p.x - a.x, p.y - a.y);
double dot11 = dot(b.x - a.x, b.y - a.y, b.x - a.x, b.y - a.y);
double dot12 = dot(b.x - a.x, b.y - a.y, p.x - a.x, p.y - a.y);
double invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01);
double u = (dot11 * dot02 - dot01 * dot12) * invDenom;
double v = (dot00 * dot12 - dot01 * dot02) * invDenom;
if ((u > 0) && (v > 0) && (u + v < 1))
return true;
return false;
}
public double dot(double x1, double y1, double x2, double y2)
{
return x1 * x2 + y1 * y2;
}
Method2:
public boolean pointInTriangle2(Point p)
{
double invDenom = 1.0 / det(points[1], points[2]);
double u = (det(p, points[2]) - det(points[0], points[2])) * invDenom;
double v = -(det(p, points[1]) - det(points[0], points[1])) * invDenom;
if ((u > 0) && (v > 0) && (u + v < 1))
return true;
return false;
}
public double det(Point p1, Point p2)
{
return p1.x * p2.y - p1.y * p2.x;
}