How to find a random point in a quadrangle?

后端 未结 9 1668
忘掉有多难
忘掉有多难 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:46

    You may randomly create points in a bound-in-box only stopping after you find one that it's inside your polygon.

    So:

    1. Find the box that contains all the points of your polygon.
    2. Create a random point inside the bounds of the previously box found. Use random functions to generate x and y values.
    3. Check if that point is inside the polygon (See how here or here)
    4. If that point is inside the polygon stop, you're done, if not go to step 2

提交回复
热议问题