Line Segments from a point
I have a point p, and 2 line segments in a 2D plane. Point p is a location of view from where camera is looking towards the line segments. I want to check if line segment 1 is partially or fully hidd开发者_如何学Pythonen behind the line 2, when looking from the point P.
I think the question is whether the second line is "masked" by the first line.
Let say you camera point is C, and your segments are A1,A2 and B1,B2.
I would compute the cross products CA1xCB1 and CA2xCB2. The sign gives you if the point if the B1 point is on the left or the right of the CA1 line. It depends on how your triangles CA1A2 and CB1B2 are oriented (they must be oriented the same, they are many ways to do that).
You can then use the sign to know if you are in the following cases:
- CA1xCB1 is negative or CA2xCB2 is positive, then partially visible
- the opposite, then hidden.
You can also compute CA1xCB2 and CA2xCB1 to have fined grained cases.
slurdge's answer is a good start, but it's a bit more complicated than that.
If line segment 2 is closer to C than line segment 1, it could still be visible, e.g.
A1-------A2
B1-B2
C
Here B1 and B2 are "within" the A1A2 sector, but are not hidden.
The hardest one to work out is if B1 is 'between' A1 and A2, but closer to the camera, while B2 is 'not between' A1 and A2, but further from the camera:
B2
A1-----A2
B1
C
B1B2 could clip the edge of the line segment, thus rendering a small portion of B1B2 hidden (or maybe not!). I think you would have to find the intersection of A1A2 and B1B2 to check whether this actually happens.
精彩评论