Jump to content
  • Advertisement
Sign in to follow this  
teel

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!