// // Created by dominik on 8/14/24. //# #include #include #include #include #include #include int nearest_index(const std::vector &x_ref, const double x, int start=0) { while (x > x_ref[start+1]) { start++; } return start; } double lerp(const std::vector& x_ref, const std::vector& y_ref, const double x, const int i) { /* * Linear interpolation between two */ const double x_left = x_ref[i]; const double y_left = y_ref[i]; const double x_right = x_ref[i+1]; const double y_right = y_ref[i+1]; const double dydx = (y_right - y_left) / ( x_right - x_left ); return y_left + dydx * (x - x_left); } std::array spherical_to_xyz(const double cos_theta, const double phi) { const double sin_theta = std::sin(std::acos(cos_theta)); const std::array xyz{sin_theta * std::cos(phi), sin_theta * std::sin(phi), cos_theta}; return xyz; } std::pair xyz_to_spherical(const std::array& xyz) { // std::cout << "length " < printSteps( /* * Prints roughly every 10 seconds how many runs were done and gives a time estimation */ const std::chrono::time_point last_print_out, const std::chrono::time_point start, const int total, const int steps ) { const auto now = std::chrono::high_resolution_clock::now(); if (const std::chrono::duration duration = now - last_print_out; duration.count() < 10.) { return last_print_out; } const std::chrono::duration duration = now - start; const auto passed = duration.count(); std::cout << steps << " of " << total << " steps: " << passed << "s passed; ~" << passed * static_cast(total-steps) / static_cast(steps) << "s remaining\n"; return now; }