How to compute the average distance till intersection within a triangle in $\mathbb{R}^2$? You are given 3 points in $\mathbb{R}^2$; $A$, $B$, $C$ forming a triangle with area > 0. You pick an arbitrary point inside $ABC$ and an arbitrary direction. After some distance $d$, you will intersect some side of a triangle. The task is to compute the expected $d$ for a given triangle. Also, it would be nice to know the whole distribution. What kind of distribution (e.g. uniform, normal) would it be?
Next, what if I have a complex polygon? Can I combine my knowledge from individual triangles somehow to compute mean and distribution for the convex polygon?
Finally, how about a non-convex polygon?
 A: If you call the random variable you described X, then it's much easier to compute the expected value of X2.  Indeed, for any point P inside triangle ABC, the expected value of X2 where X is the length of a ray through P intersected with the interior of ABC is just the area of ABC divided by π—imagine trying to compute the area of ABC using polar coordinates with origin at P.
You can use a similar trick to write the expected value of X in terms of the average value of 1/d(P, Q) where P and Q are selected uniformly at random from the interior of triangle ABC, but this doesn't seem terribly helpful.
A: We can start by solving the problem for an arbitrary triangle and a fixed direction, say the upward direction, as we can always rotate the whole figure into that position.
In the generic case, no edge of the triangle is horizontal.  Thus the triangle has a "top" vertex at $(0, 0)$ -- this is the vertex with the largest y-coordinate.  Without loss of generality, rescale so that the edge opposite the vertex at $(0, 0)$ passes through $(-1, 0)$.  We'll say that the "height" of this triangle is 1, where by height we mean the length of the vertical dropped from the top vertex.
Then the set of points of vertical distance at least $r$ from the top of the original triangle form a triangle of height $1-r$, similar to the original triangle.  Thus
$$ Prob(\hbox{vertical distance from top } > r) = (1-r)^2 $$
and this gives the distribution.  In particular the expected value of the vertical distance from a random point to the top of the triangle (after the rescaling given above) is $1/3$.
If you want to pick a random direction, though, then this gets a lot harder because the rescaling step will act differently for different directions.
A: For a triangle, this seems relatively easy. construct the voronoi diagram of the sides, which in this case is merely the partition formed by the angle bisectors at each vertex. they intersect at the center of the incircle, forming three triangles. In each triangle, the 'distance to boundary' is really the distance to the corresponding side of the original triangle, and the answer is a straight integration. 
A: x is in the triangle. Draw segments that connect x to each vertex and segments perpendicular to each side from x. Then, starting from the nearest perpendicular segment, measure the angle formed by your vector and call it $\theta$. Note the length of the perpendicular, call it R. Then the distance, from x to the side in the direction of the vector, is: $R \sec (\theta)$.
A: I know this question was asked more than eight years ago. Still, here's the answer for the triangle and the rectangle case. I'm sure they can be extended to other convex polygons too..
An Expected Value problem III
EDIT: Yes, that's my blog. The answer is easy to obtain but a bit long to explain. Unfortunately, I'm not sure when I'll be posting it. If that's not the norm in SO, I request the moderators to delete this answer. I'll post it again when I've completed my answer in my blog. Thanks.
EDIT: I've updated the proof in the blog.
