看起来你已经用极坐标系做了很多繁重的工作。但是,请记住,角度是以弧度为单位的,而不是以度为单位的,因此不要使用
360
,您应该使用
PI * 2
. 现在你要做的就是两者都增加
distance
theta
同时创造一个螺旋,而
phi
-
距离
将从
0
到
galaxySize
-
将从
0
Math.PI
(或
π*2
,如果您想要更紧密的螺旋)
-
保持接近0
// Temp variables to assign new values inside loop
var norm, theta, phi, thetaVar, distance;
// Generate particles for spiral galaxy:
for (let i = 0; i < 1000; i++) {
// Norm increments from 0 to 1
norm = i / 1000;
// Random variation to theta [-0.5, 0.5]
thetaVar = THREE.Math.randFloatSpread(0.5);
// Theta grows from 0 to Math.PI (+ random variation)
theta = norm * Math.PI + thetaVar;
// Phi stays close to 0 to create galaxy ecliptic plane
phi = THREE.Math.randFloatSpread(0.1);
// Distance grows from 0 to galaxySize
distance = norm * galaxySize;
// Here I need generate spiral arms instead of sphere.
geometry.vertices.push(new THREE.Vector3(
distance * Math.sin(theta) * Math.cos(phi),
distance * Math.sin(theta) * Math.sin(phi),
distance * Math.cos(theta)
));
}
你可以为每只手臂创建一个环。请注意,我没有像您在示例中那样在末尾除以10,而是将phi的范围限制为
[-0.1, 0.1]
in this fiddle