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

This topic is 3117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
Perhaps I don't understand the situation. Assuming that the rectangles do not overlap, something like
Quote:
 Original post by teelit 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 on other sites
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 teelit 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

1. 1
2. 2
Rutin
17
3. 3
4. 4
5. 5

• 9
• 9
• 14
• 12
• 10
• ### Forum Statistics

• Total Topics
633271
• Total Posts
3011160
• ### Who's Online (See full list)

There are no registered users currently online

×