gpt4 book ai didi

javascript - 如何在不使用 SphereGeometry 的情况下绘制球体?

转载 作者:行者123 更新时间:2023-11-29 10:39:12 25 4
gpt4 key购买 nike

我试图在不使用 SphereGeometry 的情况下绘制一个球体。我正在尝试绘制像纬度和经度这样的球体。这是我的代码:

for (var phi = -Math.PI / 2; phi < Math.PI / 2; phi += Math.PI / 15) {
var longVertices = new THREE.Geometry()
for (var theta = 0; theta <= 2 * Math.PI; theta += Math.PI/2 ) {

longitudes = this.point[this.numberOfVertices] = new THREE.Vector3();

longitudes.x = origin.x + this.radius * Math.cos(theta) * Math.cos(phi);
longitudes.y = origin.z + Math.sin(theta) * this.radius;
longitudes.z = origin.y + this.radius * Math.cos(theta) * Math.sin(phi);

this.numberOfVertices++;
longVertices.vertices.push(longitudes);
}
longVertices.vertices.push(longVertices.vertices[0]);
longVerticesArr.push(longVertices);
}

此代码帮助我绘制经度。 enter image description here

和:

        for (var phi = -Math.PI / 2; phi < Math.PI / 2; phi += Math.PI / 15) {

var delta = Math.cos(phi) * this.radius;
var fixedY = Math.sin(phi) * this.radius * direction;
var latVertices = new THREE.Geometry();
for (var theta = 0; theta < 2 * Math.PI; theta += Math.PI / 10) {
latitudes =/* this.point[this.numberOfVertices] =*/ new THREE.Vector3();

latitudes.z = origin.z + delta * Math.sin(theta);
latitudes.y = fixedY;
latitudes.x = origin.x + delta * Math.cos(theta);

this.numberOfVertices++;

latVertices.vertices.push(latitudes);
}
latVertices.vertices.push(latVertices.vertices[0]);
latVerticesArr.push(latVertices);

}

这有助于我绘制纬度。

enter image description here

现在我面临的问题是我没有得到交点处的纬度和经度点。如何在路口准确获取这些点?

最佳答案

简单的嵌套循环:[ http://jsfiddle.net/cdjtdkwa/ ]

var R = 18; // radius
var LON = 32; var LAT = 16; // approximation
var PILAT = Math.PI/LAT;
var PILON = 2*Math.PI/LON;
var cos1,cos2,sin1,sin2,t1,t2;
var y1,y2,r1,r2,t1,t2;
var geometry = new THREE.Geometry();

for (var i=0; i<LAT; i++) { // walk latitudes segments
t1 = Math.PI - i*PILAT;
t2 = Math.PI - (i+1)*PILAT;

y1 = Math.cos(t1); // 1 latitudes radius y-position;
y2 = Math.cos(t2); // 2 latitudes radius y-position;

r1 = Math.abs( Math.sin(t1) ); // 1 latitudes radius;
r2 = Math.abs( Math.sin(t2) ); // 2 latitudes radius;

for (var j=0; j<LON; j++) { // walk longitudes segments
t1 = j*PILON;
t2 = (j+1)*PILON;

cos1 = Math.cos(t1);
cos2 = Math.cos(t2);
sin1 = Math.sin(t1);
sin2 = Math.sin(t2);

geometry.vertices.push(
new THREE.Vector3( r1*cos1, y1, r1*sin1 ),
new THREE.Vector3( r2*cos1, y2, r2*sin1 ),
new THREE.Vector3( r2*cos2, y2, r2*sin2 )
);

}
}

关于javascript - 如何在不使用 SphereGeometry 的情况下绘制球体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32044652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com