vmayer
vmayer

Reputation: 1063

Determining whether an object is in the path of two other objects in 2D space

Say there are 3 objects defined by rectangles in x-y coordinates. The rectangles can be of any orientation (not necessarily parallel to the axes).

How would you go about approaching the problem of determining whether object C is partially, fully, or not at all obscured by object B from the perspective of object A (object A can see from anywhere on its rectangle)?

Second question: is it possible to determine the percentage of object C that is visible?

Upvotes: 1

Views: 89

Answers (1)

SirGuy
SirGuy

Reputation: 10770

Here is my (completely untested) approach.
Consider first the same problem but only looking from one fixed point P.

Find the two (infinite) lines that go through P and enclose your rectangle B. Since it is a rectangle these two lines will be two of the four lines that go through P and each vertex of B.

Check whether each vertex of C is in between these two lines or not. If any vertex of C is between these two lines check whether it is closer or farther from P than B is. If it is farther than B is at least partially obscuring C.

Now do this for each vertex of A. You may get more complicated results if you see a part of C from one point P in A and a different part of C from a different point P in A. I will leave it up to you how to deal with that.

To determine the percent coverage, compute the shape that you get from intersecting rectangle C with these two lines and compute its area, then divide by the total area of the shape.

I have left all the math in this up to you to figure out, but if you have any specific questions about your work, feel free to ask those.

This answer would benefit nicely from having some pictures added, but I'm hoping you can understand this answer while drawing your own diagrams according to the steps provided.

Upvotes: 1

Related Questions