【发布时间】:2021-11-18 07:03:00
【问题描述】:
我正在使用 three.js 来计算一个球体。我使用两个 for 循环,一个用于 theta,一个用于 phi,然后将极坐标转换为笛卡尔坐标。对于每个计算点,我添加了一个点。结果不是球体。
这是嵌套的 for 循环:
const distance = 1000;
for (var i = 0; i < 360; i += 10) {
for (let j = 0; j < 360; j += 10) {
let theta = i * (Math.PI / 180);
let phi = j * (Math.PI / 180);
let x = Math.sin(theta) * Math.cos(phi) * distance;
let y = Math.sin(theta) * Math.sin(phi) * distance;
let z = distance * Math.sin(phi);
const lightSphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
lightSphere.position.set(x, y, z);
scn.add(lightSphere);
}
}
这是完整的代码,包括结果:Link
【问题讨论】:
标签: javascript reactjs three.js trigonometry