Object inside Rectangle?

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

Recommended Posts

this is 2d. How can I check if an object is inside a rectangle? The rectangle can be rotated. Ex: Person A is looking at person B. I want to find all persons 2 meters to left/right and 3 meters behind B, forming a rectangle of 4x3 meters. What would the formula be to check if person C is within that rectangle?

Share on other sites
One generalized way is to do a point-in-polygon test. Look at the Forum FAQ for "point-in-polygon". There is a link to a nice page that describes approaches.

Another way is to project the test point (location of person C) into a local coordinate frame that is located at the center of the rectangle and has an x axis parallel to one edge (width edge) and the y axis parallel to another edge (length edge). Then, just do this:

C_proj = projection of C into the local rectangle frameif (-width < C_proj.x && width > C_proj.x &&    -length < C_proj.y && length > C_proj.y){  C is inside}else{  C is outside}

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• Forum Statistics

• Total Topics
633301
• Total Posts
3011268
• Who's Online (See full list)

There are no registered users currently online

×