【发布时间】:2017-02-14 07:58:45
【问题描述】:
我正在使用维基百科的spherical coordinate system article 在 Three.js 中创建一个由粒子制成的球体。根据这篇文章,我创建了一个小的Polarizer 类,它使用setPolar(rho, theta, phi) 接收极坐标并返回其对应的x、y、z
这是setPolar() 函数:
// Rho: radius
// theta θ: polar angle on Y axis
// phi φ: azimuthal angle on Z axis
Polarizer.prototype.setPolar = function(rho, theta, phi){
// Limit values to zero
this.rho = Math.max(0, rho);
this.theta = Math.max(0, theta);
this.phi = Math.max(0, phi);
// Calculate x,y,z
this.x = this.rho * Math.sin(this.theta) * Math.sin(this.phi);
this.y = this.rho * Math.cos(this.theta);
this.z = this.rho * Math.sin(this.theta) * Math.cos(this.phi);
return this;
}
我用它来定位我的粒子如下:
var tempPolarizer = new Polarizer();
for(var i = 0; i < geometry.vertices.length; i++){
tempPolarizer.setPolar(
50, // Radius of 50
Math.random() * Math.PI, // Theta ranges from 0 - PI
Math.random() * 2 * Math.PI // Phi ranges from 0 - 2PI
);
// Set new vertex positions
geometry.vertices[i].set(
tempPolarizer.x,
tempPolarizer.y,
tempPolarizer.z
);
}
效果非常好,只是我得到了高粒子密度,或者在两极“挤压”:
我不知道如何避免这种情况发生。我想将加权随机数传递给纬度,但我希望在不使经度也减慢并在两极聚集的情况下为粒子设置动画。
是否有不同的公式来生成两极没有那么重的球体?我应该改用四元数吗?
【问题讨论】:
-
我会在这里stackoverflow.com/questions/5531827/… 寻找两种可能的解决方案,而且,更一般地说,二十面体球体是 three.js 中的一个额外部分,根据您需要如何测试噪声分布,它可能很有用。示例:codepen.io/Mombasa/pen/fvgqb
-
@Radio,这正是我想要的!我不得不使用类似于加权随机数生成器的东西,它更接近 0.5 而不是 0 或 1。
标签: math three.js geometry quaternions polar-coordinates