问题描述
我必须能够设置一个随机位置作为飞行模拟的航点。数学的挑战很简单:
在一个四边形内找到一个随机位置,这个位置在任何位置都有相同的机会。
这样看起来像:
一个示例ABCD四边形是:
A:[21417.78 37105.97]
B:[38197.32 24009.74]
C:[1364.19 2455.54]
D:[1227.77 37378.81]
预先感谢您提供的任何帮助。 : - )
编辑
感谢您的回复。我会在周末看看这个,然后会授予接受的答案。顺便提一下,我应该提到四边形可以是凸面或凹面。 Sry'bout dat。
将您的四边形分成两个三角形,然后使用可以快速找到其中一个随机点。
更新:
借用这个伟大的从选择一个三角形中的随机点。
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 quadrangle, where there's an equal chance of the point being at any location."
Visually like this:
An example ABCD quadrangle is: A:[21417.78 37105.97] B:[38197.32 24009.74] C:[1364.19 2455.54] D:[1227.77 37378.81]
Thanks in advance for any help you can provide. :-)
EDITThanks all for your replies. I'll be taking a look at this at the weekend and will award the accepted answer then. BTW I should have mentioned that the quadrangle can be CONVEX OR CONCAVE. Sry 'bout dat.
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.
main figure http://mathworld.wolfram.com/images/eps-gif/TrianglePointPicking_700.gif
这篇关于如何在四边形中找到一个随机点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!