views:

120

answers:

3

Suppose I have two points, Point1 and Point2. At any given time, these points may be at different positions-- they are not necessarily static.

Point1 is located at some position at time t, and its position is defined by the continuous functions x1(t) and y1(t) giving the x and y coordinates at time t. These functions are not differentiable, they are constructed piecewise from line segments.

Point2 is the same, with x2(t) and y2(t), each function having the same properties.

The obstacles that might prevent visibility are simple (and immobile) polygons.

How can I find the boundary points for visibility?

i.e. there are two kinds of boundaries: where the points become visible, and become invisible.

For a become-visible boundary i, there exists some ϵ>0, such that for any real number a, a ∈ (i-ϵ, i) , Point1 and Point2 are not visible (i.e. the line segment that connects (x1(a), y1(a)) to (x2(a), y2(x)) crosses some obstacles).

For b ∈ (i, i+ϵ) they are visible.

And it is the other way around for becomes-invisible.

But can I find a precise such boundary, and if so, how?

+1  A: 

It's easy to check if two lines intersect. Use this to check intersection of the line (p1, p2) and each polygon edge. If you have any intersection, the line (p1, p2) is obstructed by some obsticle.

If you need a time interval (at which p1 and p2 are not in line of sight) you could do the above check for different values of t (preferably with relatively small differences), and between a "visible-t" and an "invisible-t" you could do a binary search until you reach a small enough threshold, such as eps.

aioobe
The threshold is zero, otherwise the solution is not exact and doesn't satisfy the boundary criteria (since you can choose anything within the wrong side of the error bound and get the wrong answer).
Devin Jeanpierre
I see what you mean.
aioobe
+1  A: 
walkytalky
Right, but I don't have a discrete number of time-points, just time in general (taking any float-- admittedly floats are only of finite precision, but...).
Devin Jeanpierre
The times are vertex intersection times. If you have an infinite number of obstacle vertices or an infinite number of linear segments in your movement functions then the problem is insoluble anyway. But over any finite section there will be a finite number of times you need to test.
walkytalky
Nice solution. However, I wouldn't check visibility at (t-ε) and (t+ε), since technically no ε is small enough. And I wouldn't use the "slope" as you do, since it may very well be the case that you have infinite slope (or close to infinite, which unnecessarily ruins the precision). (Unless I misunderstood your solution.)
aioobe
A long as ε is small enough to not overlap the previous or next collision time, the visibility state will be correct. It's certainly possible that a gap might exist that is too brief to detect with any given numerical precision, but I'm not sure there's much one can do about that.
walkytalky
As for the slope or gradient, that's in the parametric equation in t, not the Cartesian plane. Unless the points are actually teleporting then it should not be infinite. (We are told the functions are continuous.) Points can move parallel to one axis or the other by having a slope 0 in the corresponding function.
walkytalky
(There *is* an implicit appeal to the XY gradient in the derivation of the quadratic, but I *think* that any unnecessary numerical imprecision gets lost in the algebra. This would need testing, of course.)
walkytalky
Ooh, the gradient x1m is a vector. I see, I thought it was a scalar... Now it looks nicer to me =)
aioobe
No, it's a scalar. x and y are defined independently in terms of t. It would certainly be possible (and bit neater) to write the whole lot in terms of vectors, but it *should* be equivalent. I just went with something approximating the original question's notation.
walkytalky
Just as a final clarification, my x10 is your Ax, my x1m is your (Bx - Ax), etc. The two methods are equivalent, but I expanded mine and did some mucking around to swap your two unknowns for a quadratic in a single unknown. I would expect to get the same answer each way, but on balance your elaboration is simpler and clearer!
walkytalky
Yep. Sorry for being slow. I see now. It's of course quite similar to my equations. I was slightly surprised to see the ^2 in your equations, but when I think about it, it seems it would show up in my equations if I played around with them a bit too, as you have done. The whole story could probably be written even clearer if one used vectors. (It's probably useful to do some vector-class when implementing this as well.)
aioobe
+2  A: 

Ok, I have a clearer picture of the problem now, and inspired by @walkytalky suggestion, here is a more ellaborate answer.

You mentioned that p1 and p2 travel along straight line segments. I don't know if these segments are aligned in a way such that both p1 and p2 always start new segments at the same time. However, you can always cut a line segment into two line segments (with the same slope) so that both p1 and p2 always start new line segments at the same time.

Assume p1 travels along line A-B, and p2 travels (at the same time) along C-D as a parameter t goes from 0 to 1. (That is, at time t=0.5, p1 is in the middle of A-B and p2 in the middle of C-D.)

By letting Ax and Ay denote the x and y coordinate of point A (and similarly for B, C and D) we can express p1 and p2 as functions of t in the following way:

p1(t) = (Ax + t*(Bx - Ax), Ay + t(By - Ay))
p2(t) = (Cx + t*(Dx - Cx), Cy + t(Dy - Cy))

(For instance, when t=0, Ax + t*(Bx - Ax) evaluates to Ax, and when t=1 it evaluates to Bx.)

To find each "a-vertex-is-passing-by-between-p1-and-p2"-time we do the following:

For each obstacle vertex v=(Vx, Vy) we need to find a t so that p1(t), p2(t) and v are in line with each other.

This can be done by solving the following equations (two equations, and two unknown, t and k):

Vx=p1(t).x + k*(p2(t).x - p1(t).x)
Vy=p1(t).y + k*(p2(t).y - p1(t).y)`

If k lies between 0 and 1, the polygon vertex v is actually between the (extended) A-B line and the (extended) C-D line. If t is also between 0 and 1, the vertex v is actually passed by the p1-p2 line during the time the points travel along these segments (since when t is, say, 1.3, the points will already be on new segments).

Once all "a-vertex-is-passing-by-between-p1-and-p2"-times has been computed, it's a simple task to figure out the rest. (That is, figuring out if it is a "becoming-in-sight", "becoming-out-of-sight" or "neither" type of passing):

For all pairs t0 and t1 of consecutive vertex-passing times, you check if the line p1((t1-t0)/2)-p2((t1-t0)/2) is free of intersections with a polygon edge. If it is free of intersections, the points will be in line of sight the entire period (t0-t1), otherwise they will be out of sight the entire period (since no other vertices are passed during this time period).

aioobe