1
I’m 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;
}
Obs¹: The loose x and y in the code refer to the coordinates of the point'.
Obs²: 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 we know if the point is colliding with it? I should necessarily use polygons?
It would be important for a real solution here. If it’s just to point out an external link, better post as comment. Another thing, the "rotation" of the point has to be in the opposite direction of the rectangle. Otherwise, your question does not mention the origin of the rotation, it would be good to add there this detail (and take advantage to remove the unnecessary ifs, since the return is bool). And one more thing: the post indicated is very bad as a solution. It is suggested to post real code in the answer, for better evaluation, and to help other community members with similar doubt.
– Bacco
Jeez! Really :O! The rotation has to be really in reverse, sorry and!
– Ícaro Dantas
You don’t have to apologize, I just warned you to warn you about the problem. As for the rest, it’s just a suggestion for improvement to enhance the answer (and the question too).
– Bacco
I improved on.
– Ícaro Dantas