18 const std::vector<Eigen::VectorXd>& path,
19 const std::vector<double>& weights = {})
21 if (path.size() < 2 || path.front().size() < 1)
22 throw std::invalid_argument(
23 "A nonempty geodesic chart with two endpoints is required");
24 const auto count = weights.empty() ? path.size() : weights.size() + 1;
25 std::vector<double> arc(path.size(), 0), fraction(count, 0);
26 for (std::size_t j = 0; j < path.size(); ++j) {
27 if (path[j].size() != path.front().size() || !path[j].allFinite())
28 throw std::invalid_argument(
29 "Finite matching geodesic chart coordinates required");
31 const double length = (path[j] - path[j - 1]).norm();
32 if (!(length > 0) || !std::isfinite(length))
33 throw std::invalid_argument(
34 "Distinct finite geodesic chart nodes required");
35 arc[j] = arc[j - 1] + length;
38 if (!std::isfinite(arc.back()))
39 throw std::invalid_argument(
"Finite geodesic arclength required");
42 scale = *std::max_element(weights.begin(), weights.end());
43 for (std::size_t j = 1; j < count; ++j) {
44 const double weight = weights.empty() ? 1. : weights[j - 1];
45 if (!(weight > 0) || !std::isfinite(weight))
46 throw std::invalid_argument(
47 "Positive finite geodesic sampling weights required");
48 fraction[j] = fraction[j - 1] + weight / scale;
49 if (!(fraction[j] > fraction[j - 1]) || !std::isfinite(fraction[j]))
50 throw std::invalid_argument(
51 "Resolved positive geodesic sampling fractions required");
53 std::vector<Eigen::VectorXd> result(count);
54 result.front() = path.front();
55 result.back() = path.back();
56 for (std::size_t j = 1; j + 1 < count; ++j) {
57 const double target = arc.back() * (fraction[j] / fraction.back());
58 const auto upper = std::upper_bound(arc.begin(), arc.end(), target);
59 const auto right = std::min(
60 path.size() - 1,
static_cast<std::size_t
>(upper - arc.begin()));
61 const auto left = right - 1;
62 const double t = (target - arc[left]) / (arc[right] - arc[left]);
63 result[j] = (1 - t) * path[left] + t * path[right];
ZeroEnergyGeodesicResult optimizeZeroEnergyGeodesic(const M &omega, double radius, const std::vector< V > &initial, const ZeroEnergyGeodesicPotential &potential, const ZeroEnergyGeodesicOptions &options, const std::function< void(const ZeroEnergyGeodesicResult &)> &retain)
ZeroEnergyGeodesicEvaluation evaluateZeroEnergyGeodesic(const M &omega, double radius, const std::vector< V > &path, const std::vector< PotentialEvaluation > &native, double stiffness, const std::vector< M > &hessians)