How to find a random point in a quadrangle?

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

    This is an interesting problem and there's probably as really interesting answer, but in case you just want it to work, let me offer you something simple.

    Here's the algorithm:

    1. Pick a random point that is within the rectangle that bounds the quadrangle.
    2. If it is not within the quadrangle (or whatever shape), repeat.
    3. Profit!

    edit

    I updated the first step to mention the bounding box, per Bart K.'s suggestion.

提交回复
热议问题