Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

javascript - Can someone explain the formula

I have found a formula which does the following:

https://threejs.org/examples/css3d_periodictable.html (the sphere version)

I modified the code a little bit to work with my objects, but changed nothing in the math behind it.

My question is if someone can explain what is exactly happening in the calculation for the position.

This is the code:

for ( var i = 0, l = 30; i < l; i ++ ) {

    var phi = Math.acos( -1 + ( 2 * i ) / l );
    var theta = Math.sqrt( l * Math.PI ) * phi;

    var object = new THREE.Mesh( geometry, material );

    object.position.x = 1000 * Math.cos( theta ) * Math.sin( phi );
    object.position.y = 1000 * Math.sin( theta ) * Math.sin( phi );
    object.position.z = 1000 * Math.cos( phi );

    scene.add(object);

}

I hope someone is able to help me

Thanks in advance

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This code is transforming Cartesian coordinates to spherical coordinates. Check this wikipedia entry on coordinate system convertions.

The best way to draw a sphere ;)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...