Sign in to follow this  
teel

Point in rotated rectangle - axis-aligned method and wrong rectangle identified

Recommended Posts

teel    122
Hi, I'm writing a game with multiple (let's say 10) rotated rectangles on the screen which I need to iterate through upon the game area click to check which one has been clicked. Ok, the standard method in this case: 1. get the click coordinates 2. start iterating though rotated rectangles collection 2a. perform click coordinates rotation by negative rotated rectangle rotation angle to get the axis-aligned rectangles 2b. check whether the rotated click lies within rectangle boundaries Now, that works fine, but has some minor flaw: while iterating through those rectangles and performing click point rotation by currently analyzed rectangle's angle it may happen that the the rotated point will match another rectangle! I came up with a solution to check only rectangles within the radius of max(rectangle_dimension) but I don't think that's right attitude, because still the issue may occur in case of 2 perpendicular rectangles. What is the other possible solutions to that? Cheers, teel

Share this post


Link to post
Share on other sites
haegarr    7372
Perhaps I don't understand the situation. Assuming that the rectangles do not overlap, something like
Quote:
Original post by teel
it may happen that the the rotated point will match another rectangle
isn't be possible. Tempted due to the wording chosen in the OP, I ask whether you only consider rotation or also translation? I.e. you have to transform the click point with the inverse of the entire placement. Let's assume you rotate a rectangle and translate it then to its final location. Hence you need to inverse translate the click point and inverse rotate it then. Now you can do the test.

Share this post


Link to post
Share on other sites
teel    122
Quote:
Original post by haegarr
Perhaps I don't understand the situation. Assuming that the rectangles do not overlap, something like
Quote:
Original post by teel
it may happen that the the rotated point will match another rectangle
isn't be possible.


Yeah, thanks, that was just a fault in my calculation procedure...

Regards,
Tomek

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this