DEV Community

HandsomeTan
HandsomeTan

Posted on

Create a sphere with evenly distributed points with three.js

In fact, I have yet to find a way that all points are distributed uniformly. All the methods I have found can only approach a uniform distribution, so I recommend a simpler method in my opinion:

const spherical = new THREE.Spherical();
spherical.radius = 5;
for (let i = 0; i < points; i++) {
ο»Ώ
  let phi = Math.acos(1.0 - (2.0 * i + 0.5) / points);
  let theta = Math.PI * (1 + Math.sqrt(5)) * i;
ο»Ώ
  spherical.phi = phi; 
  spherical.theta = theta; 
  const x = spherical.radius * Math.sin(spherical.phi) * 
  Math.cos(spherical.theta);
  const y = spherical.radius * Math.sin(spherical.phi) * 
            Math.sin(spherical.theta);
  const z = spherical.radius * Math.cos(spherical.phi);
......
}
Enter fullscreen mode Exit fullscreen mode

I also don't understand this theoretical principle, because my math is bad, if you are intersting in this principle you can search for relevant information on Stack Overflow.
ο»Ώ
ο»Ώ

Top comments (0)