方向矢量锥

编程入门 行业动态 更新时间:2024-10-10 11:26:03
本文介绍了方向矢量锥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个归一化的方向矢量(从3d位置到亮位置),我希望将此矢量旋转一定角度,以便创建一个圆锥体".

I have a normalized direction vector (from a 3d position to a light position) and I would like this vector to be rotated by some angle so I can create a "cone".

Id喜欢通过使用方向矢量作为圆锥体的中心来模拟圆锥体跟踪,并创建X个样本,以创建更多的光线来作为样本.

Id like to simulate cone tracing by using the direction vector as the center of the cone and create an X number of samples to create more rays to sample from.

我想知道的基本上是背后的数学:

What I would like to know is basically the math behind:

docs.unrealengine/Latest/INT/BlueprintAPI/Math/Random/RandomUnitVectorinCone/index.html

似乎完全符合我的要求.

Which seems to do exactly what Im looking for.

推荐答案

1)使任意矢量P垂直于方向矢量D. 您可以选择幅度最大的分量,将其与中等幅度的分量交换,取反,并将幅度最小的分量设为零.

1) Make arbitrary vector P, perpendicular to your direction vector D. You can choose component with max magnitude, exchange it with middle-magnitude component, negate it, and make min magnitude component zero.

例如,如果z分量最大而y分量最小,则可以将其设置为P:

For example, if z- component is maximal and y-component is minimal, you may make such P:

D = (dx, dy, dz) p = (-dz, 0, dx) P = Normalize(p) //unit vector

2)通过向量积使向量Q垂直于D和P:

2) Make vector Q perpendicular both D and P through vector product:

Q = D x P //unit vector

3)生成 PQ平面磁盘中的随机点

RMax = Tan(Phi) //where Phi is cone angle Theta = Random(0..2*Pi) r = RMax * Sqrt(Random(0..1)) V = r * (P * Cos(Theta) + Q * Sin(Theta))

4)归一化向量V

请注意,向量分布在球体段上稍微不均匀(在平面圆盘上均匀).有一些方法可以生成球体上的均匀分布,但是需要一些工作来将它们应用于细分(我编辑之前的第一次尝试是错误的.)

Note that distribution of vectors is slightly non-uniform on the sphere segment.(it is uniform on the plane disk). There are methods to generate uniform distribution on the sphere but some work needed to apply them to segment (my first attempt before edit was wrong).

编辑:进行修改以使球面分布均匀(未彻底检查)

Modification to make sphere-uniform distribution (not checked thoroughly)

RMax = Tan(Phi) //where Phi is cone angle Theta = Random(0..2*Pi) u = Random(Cos(Phi)..1) r = RMax * Sqrt(1 - u^2) V = r * (P * Cos(Theta) + Q * Sin(Theta))

更多推荐

方向矢量锥

本文发布于:2023-11-22 02:16:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615577.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:矢量   方向

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!