我试图在不使用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);
                }

这段代码可以帮助我绘制经度。
javascript - 如何在不使用SphereGeometry的情况下绘制Sphere?-LMLPHP

和:
        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);

        }

这有助于我吸引纬度。

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

现在我面临的问题是我在交点处没有同时获得经度和纬度的点。如何准确地在交叉点获得这些点?

最佳答案

简单的嵌套循环:
[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的情况下绘制Sphere?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32044652/

10-09 14:08