The problem:
I have trouble generating a random line that cuts through a polygon (not necessary convex). The lines should have the same distribution as completely random lines (random position, random angle), disregarding those that miss the polygon entirely.
My thoughts so far:
Picking a random point inside the polygon (I have that algorithm already) and picking a random angle won't do, because a hammer shaped object would be cut more often through the head (it has a larger area than the handle), where a completely random line would be more likely to cut through the handle. Also the angle would defenitely not be uniformly distributed.
For the same reasons it's not possible picking two points inside or on the surface and generating a line that goes through both points or any similar methods.
Edit: I have two methods that I can use but I'm not perfectly satisfied with either of them.
Find a circle that contains the polygon. Pick random lines through the circle until you find one that also cuts through the polygon. This basically the definition that I wrote above only with a higher chance of hitting the polygon.
Project the polygon in n directions (e.g. 0°, 10°, 20° etc.). The size of the projection is proportional to the likelyhood of getting hit from this direction. Then I pick a direction (using the projection-size as weighted probabilies). Finally, I can add a 360/n° jitter the the angle. This should approximate the distribution well enough but I wonder if there is a better way of doing it.
Edit2: -deleted-
I had written quite a lot but after thinking some more about it and discovering some mistakes I realized that this is getting over my head.
The idea was to project a convex hull of the polygon in just a few, certain directions and finding a function that gives us all the other projections by blending between the known ones. But the details turned out to be quite convoluted and just too much for me at the moment.