Basic check
If your rectangle is not rotated the problem is limited to check if Point (x,y) is between some range
(rectangle.x, rectangle.x + rectangle.width)
(rectangle.y, rectangle.y + rectangle.height)
Adding rotation
As the rectangle is rotated you could make the inverse rotation to bring the point to the "unrotated state" and make the previous check.
How to "un-rotate" the point
Well. If your rectangle is rotated 27º, the "unrotation" will have to be -27º (from the same center of rotation point).
How to rotate a point given a center of rotation point?
Well, you must:
- translate the thing to make (0,0) the center point: it is, translate the original point (-x, -y) where (x, y) is the point of rotation
- apply rotation on origin (see section below)
- undo the first transformation (translate (x, y) where (x, y) is the point of rotation
Rotation on origin
You have to make matrix multiplication Ax. Where A is the matrix and x is the (x, y) vector of the point to rotate.
Matrix A is built this way