golden sphere cpp

Solutions on MaxInterview for golden sphere cpp by the best coders in the world

showing results for - "golden sphere cpp"
Malakai
04 Jan 2020
1std::vector<Vec3> fibonacci_spiral_sphere(const int num_points) {
2    std::vector<Vec3> vectors;
3    vectors.reserve(num_points);
4    
5    const double gr=(sqrt(5.0) + 1.0) / 2.0;  // golden ratio = 1.6180339887498948482
6    const double ga=(2.0 - gr) * (2.0*M_PI);  // golden angle = 2.39996322972865332
7
8    for (size_t i=1; i <= num_points; ++i) {
9        const double lat = asin(-1.0 + 2.0 * double(i) / (num_points+1));
10        const double lon = ga * i;
11
12        const double x = cos(lon)*cos(lat);
13        const double y = sin(lon)*cos(lat);
14        const double z = sin(lat);
15
16        vectors.emplace_back(x, y, z);
17    }
18    
19    return vectors;
20}
similar questions
queries leading to this page
golden sphere cpp