▲ | wpollock a day ago | |
I'm certainly not knowledgeable about these algorithms, but I'm willing to look foolish. In any regular polygon, you can fill it with a line of any thickness by starting at one vertex and spiraling inward until the shape is completely filled. The line can be as thin as required for any application. The problem is now transformed into finding random points on a finite line. I don't have the mathematical chops to know, but I'd guess that finding the length of such a line and coverting to the 2d coordinates of any point on the line would be possible perhaps even practical. Does anyone here know if this is possible? | ||
▲ | teraflop a day ago | parent [-] | |
So from a mathematical perspective, the issue is that your "line" (path) actually has zero thickness, and so there are gaps between the spiral windings. If you sample a point from any finite-length path then you have probability zero of hitting any of the points in the gaps between segments. (Maybe you don't care about this if the gaps are sufficiently small, but from a mathematical perspective it's not strictly valid.) And you can't just say "the path is infinitely long and spirals infinitely many times" because then you have no way of uniformly sampling a random real number between zero and infinity (it can be proven that no such probability distribution exists). But I think the basic idea is sound and you make it work by formulating it slightly differently: 1. Divide up the triangle into infinite concentric triangles 2. Choose a random triangle with probability proportional to that triangle's length 3. Choose a random point on that triangle's perimeter The interesting part is step 2. If you parameterize the triangles by a scale factor s, ranging from 0 to 1, then the perimeter is proportional to s. So I believe you can choose s appropriately by choosing x uniformly at random from 0..1 and letting s = sqrt(x). See https://en.wikipedia.org/wiki/Triangular_distribution Then step 3 is mathematically straightforward: if the lengths of the triangle's sides are a,b,c, you choose a random number between 0 and a+b+c, and "wrap" that length around the triangle's perimeter. Then you have to do the correct coordinate transformation to find the appropriate point on the scaled triangle you chose. So I think it would work, but it probably wouldn't be any simpler to implement than the "accept-flip" method described in the article. |