Nephrite21

피보나치 스피어 -> 구면 상에 n개의 입자를 배치. 본문

알고리즘

피보나치 스피어 -> 구면 상에 n개의 입자를 배치.

Nephrite21 2025. 12. 15. 19:57

구면 상에 균일 분포로 입자를 배치할 때 사용하기 좋은 알고리즘이 있다

피보나치 스피어이다.

const cos = Math.cos, sin = Math.sin, asin = Math.asin, sqrt = Math.sqrt;
const M_PI = Math.PI;
function fibonacci_spiral_sphere(num_points) {
    const goldenRatio = (sqrt(5.0) + 1.0) / 2.0;                // golden ratio = 1.6180339887498948482
    const goldenAngle = (2.0 - goldenRatio) * (2.0 * M_PI);     // golden angle = 2.39996322972865332
    let points = [];
    let lat, lon;
    let x, y, z;
    for (let i=1; i <= num_points; ++i) {
        lat = asin(-1.0 + 2.0 * (i / (num_points+1)));
        lon = goldenAngle * i;
        x = cos(lon)*cos(lat);
        y = sin(lon)*cos(lat);
        z = sin(lat);
        points.push(x, y, z);
    }
    return points;
}

출처  : https://3dcodekits.tistory.com/entry/Even-distribution-of-points-on-a-sphere-with-count-control-Threejs

 

구의 표면에 점들을 균등하게 분포시키는 방법 (Three.js)

구면 상에 점들을 고르게 분포시키는 문제는 기하학에서 고전적인 문제 중 하나이며, 컴퓨터 그래픽, 분자 모델링, 물리학 등 다양한 분야에서 활용됩니다. 실용적으로 가장 적절한 방법 중 하

3dcodekits.tistory.com

lon이 위에서 내려다보았을 때 회전 각도이고, lat이 중심에서 떨어져있는 정도를 asin을 통해서 생성하는 내용이다.

피보나치 형태로 이파리가 나는 나무처럼 쌓아올리는 것. 여기서 중심축과 멀리떨어진 정도를 lat을 통해서 정하는 것.