How to find a random point in a quadrangle?

后端 未结 9 1671
忘掉有多难
忘掉有多难 2021-02-08 12:53

I have to be able to set a random location for a waypoint for a flight sim. The maths challenge is straightforward:

\"To find a single random location within a quadrangl

9条回答
  •  既然无缘
    2021-02-08 13:28

    Split your quadrangle into two triangles and then use this excellent SO answer to quickly find a random point in one of them.

    Update:

    Borrowing this great link from Akusete on picking a random point in a triangle.


    (from MathWorld - A Wolfram Web Resource: wolfram.com)

    Given a triangle with one vertex at the origin and the others at positions v1 and v2, pick
    (from MathWorld - A Wolfram Web Resource: wolfram.com)
    where A1 and A2 are uniform variates in the interval [0,1] , which gives points uniformly distributed in a quadrilateral (left figure). The points not in the triangle interior can then either be discarded, or transformed into the corresponding point inside the triangle (right figure).

提交回复
热议问题