![]() ![]() Take two random numbers between 0 and 1.If you can restrict your input to parallelogram, this is really simple: The point x' will be inside the triangle.įurther note that, if the quadrilateral was already a parallelogram, then we do not have to pick a triangle at random, we can pick either one deterministically, and then choose the point x without testing that it is inside it's source triangle.Ī. In that case, we can generate a new point x' = v0 + R(pi)(x - v3), where R(pi) is a rotation by pi (180 deg). ![]() Note that with probability 0.5, x lies outside outside the triangle, however if it does, it lies inside the parallelogram composed of the union of the triangle with it's image after a rotation of pi around the midpoint of (v1,v2) (dashed lines in the image). Then we calculate the random point x by x = a0 (v1-v0) + a1 (v2-v0). Then we generate two random numbers a0 and a1, both drawn uniformly from the interval. Let v0, v1, v2 be vertices of the triangle (represented by their point locations, so that v0 = (x0,y0), etc. For the quadrilateral, this is a Bernoulli distribution: Then generate a random index i from the finite distribution over indexes given their weights. For each triangle we assign a weight equal as follows: To pick one of the triangles randomly, let us assign an index to each triangle (i.e. For other polygons, see for a starting point, or if you just need a library. For the case of a quadrilateral, create an edge acrossĪny two non-adjacent vertices. generate a collection of non-overlapping triangular regions which cover the polygon). The answer is based on the case of generating a sample from a uniform distribution in a triangle (see, which has a very nice explanation). The question by the OP is a bit ambiguous so the question I will answer is: How to generate a point from a uniform distribution within an arbitrary quadrilateral, which is actually a generalization of How to generate a point from a uniform distribution within an arbitrary (convex) polygon. ![]()
0 Comments
Leave a Reply. |