Detect collision of a rotated rectangle?

1

I am using the following code to know if a point is inside a rectangle:

public bool Intersect(ÍcaroDantasCollisions.Rectangle rectangle)
{
    if(x >= rectangle.x && x <= rectangle.x + rectangle.width)
    {
        if(y >= rectangle.y && y <= rectangle.y + rectangle.height)
        {
            return true;
        }
    }
    return false;
}

Obs1: The 'x' and 'y' loose in the code refer to the coordinates of the 'point'.

Obs2: In the rectangle class only the declaration of the variables x, y, width and height are present.

Now the question, let's say that this rectangle is rotated by 45 °, how do you know if the point is colliding with it? Should I use polygons?

    
asked by anonymous 22.09.2016 / 23:55

1 answer

-1

I found the solution:

First you measure the angle of rotation of the rectangle from the top left, then just rotate the point in a direction opposite to the direction of the rectangle also from its origin, then just check as if the rectangle does not was rotated: D

    
23.09.2016 / 00:02