计算以环形排列球体

时间:2015-03-31 19:35:42

标签: javascript three.js

我正试图在一个戒指中安排10个球体。这是我到目前为止所计算的计算,但是它没有工作

            var bubbleGeo = new THREE.SphereGeometry(300, 20, 20);
            var bubbleMat = new THREE.MeshLambertMaterial( { color: 0x888888 } );
            var numBubbles = 10;
            var bubbleMesh;
            var bubbles = [];
            var startX = 0;
            var startY = 500;
            var spacing = 80 * Math.sin( angle );
            for (var i=0; i<numBubbles; i++) {
                bubbleMesh = new THREE.Mesh(bubbleGeo, bubbleMat);
                console.log("bubble" + i);
                var angle = 360/numBubbles*i*Math.PI/180;
                bubbleMesh.position.set((startX + Math.cos(angle)*bubbleR) + spacing, 
                                        (startY + Math.sin(angle)*bubbleR) + spacing, 
                                        100
                                        );
                scene.add(bubbleMesh);
                bubbles.push(bubbleMesh);
            }

我对数学的了解并不多。如果有人确实看到我出错的地方,那么任何帮助都会有很大的帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

            var bubbleR = 400;
            var bubbleGeo = new THREE.SphereGeometry(bubbleR, 10, 10);
            var bubbleMat = new THREE.MeshLambertMaterial( { color: 0x888888 } );
            var numBubbles = 5;
            var bubbleMesh;
            bubbles = [];
            var startX = 1000;
            var startZ = 1000;
            for (var i=0; i<numBubbles; i++) {
                bubbleMesh = new THREE.Mesh(bubbleGeo, bubbleMat);
                var angle = 360/numBubbles*i*Math.PI/180;
                bubbleMesh.position.set((startX + Math.sin(angle)*bubbleR) * 2, 
                                         1000, 
                                         startZ + (Math.cos(angle)*bubbleR) * 2
                );
                scene.add(bubbleMesh);
                bubbles.push(bubbleMesh);       
            }

出于某种原因,如果我在循环后将数组添加到场景中,它就不起作用了。我也希望他们在一个新的THREE.group,所以我可以定位整个小组,但目前似乎没有工作