我正在尝试模拟从点源发出的辐射。为此,在给定光源坐标和所需的发射光线长度的情况下,我随机生成球坐标中的方向向量,将其转换为笛卡尔坐标,并返回正确的终点。但是,当我运行它并在 Blender 中可视化生成的点云(由所有随机生成的端点组成)时,我发现它在球体的“极点”处的密度更高。我希望这些点沿球体均匀分布。我怎样才能做到这一点?
随机生成函数:
def getRadiationEmissionLineSeg(p, t):
if(p.size == 4):
#polar angle spans [0, pi] from +Z axis to -Z axis
#azimuthal angle spans [0, 2*pi] orthogonal to the zenith (in the XY plane)
theta = math.pi * random.random()
phi = 2 * math.pi * random.random()
#use r = 1 to get a unit direction vector
v = sphericalToCartesian(1, theta, phi)
#parametric vector form: vec = p + tv
#p = point that lies on vector (origin point in case of a ray)
#t = parameter (-inf, inf) for lines, [0, inf) for rays
#v = direction vector (must be normalized)
return p + t * v
球面坐标->笛卡尔转换函数:
def sphericalToCartesian(r, theta, phi):
x = r * math.sin(theta) * math.cos(phi)
y = r * math.sin(theta) * math.sin(phi)
z = r * math.cos(theta)
return npy.array([x, y, z, 0])
蛊毒传说
相关分类