English 中文(简体)
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 hidden 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.





相关问题
Bounding ellipse

I have been given an assignement for a graphics module, one part of which is to calculate the minimum bounding ellipse of a set of arbitrary shapes. The ellipse doesn t have to be axis aligned. This ...

Line segment in a triangle

How can we check if a line segment falls partially or fully inside a triangle? Cheers.

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 ...

Creating a surface of triangles from a set of 2D points

I have a set of points and I need to convert the set to (non-overlapping) triangles (or a big polygon if equivalent)... The application: I have a list of locations (latitude,longitude) from a country,...

Radial plotting algorithm

I have to write an algorithm in AS3.0 that plots the location of points radially. I d like to input a radius and an angle at which the point should be placed. Obviously I remember from geometry ...

Delete holes in a Polygon

I have a polygon determined by an Array of Points. This polygon is crossing itself making some holes in the polygon itself. My questions is: How can I omit this holes and just get the exterior ...

Finding cycle of 3 nodes ( or triangles) in a graph

I am working with complex networks. I want to find group of nodes which forms a cycle of 3 nodes (or triangles) in a given graph. As my graph contains about million edges, using a simple iterative ...

热门标签