简体   繁体   English

如何生成与给定平面相距一定距离的随机3D点?

[英]How to generate a random 3D point with a distance to a given plane?

I have a plane from 3 points (triangle). 我有3点(三角形)的飞机。 How can I generate a random point to this plane with a specified distance? 如何生成具有指定距离的该平面的随机点? The projection of the generated point should also be within the triangle. 生成点的投影也应在三角形内。

Let's we have non-collinear points A, B, C. 我们有非共线点A,B,C。
1. Generate two random values t and u in range 0..1. 1.生成范围为0..1的两个随机值t和u。 We can use these values to get uniform distribution in parallelogram formed by vectors AB and AC. 我们可以使用这些值来获得由矢量AB和AC形成的平行四边形的均匀分布。 To get uniform distribution in triangle, we reflect points which hit the second triangle, about parallelogram diagonal (if-branch of pseudocode) 为了获得三角形中的均匀分布,我们反映了到达第二个三角形的点,大约平行四边形对角线(如果是伪代码,则为分支)

在此处输入图片说明

t = random ( 0, 1 ) 
u = random ( 0, 1 )
if (t + u > 1 ) then
   t = 1 - t
   u = 1 - u
  1. Make random point P inside triangle ABC: 在三角形ABC内设置随机点P:

P = A + t * AB + u * AC

  1. Move P away off ABC plane 将P从ABC飞机上移开

    n = normalized(AB x AC) (vector product) n = normalized(AB x AC) (矢量积)

    P' = P + d * n

where d - needed distance d-所需距离

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM