Reparameterize curve by arc length.
423{
425 double total_length = arc_lengths(arc_lengths.size() - 1);
426
427 if (total_length == 0.0) {
428 return points;
429 }
430
431 Eigen::MatrixXd result(points.rows(), num_samples);
432
433 for (Eigen::Index i = 0; i < num_samples; ++i) {
434 double target = (static_cast<double>(i) / static_cast<double>(num_samples - 1)) * total_length;
435
436 Eigen::Index idx = 0;
437 for (Eigen::Index j = 1; j < arc_lengths.size(); ++j) {
438 if (arc_lengths(j) >= target) {
439 idx = j - 1;
440 break;
441 }
442 }
443
444 if (idx + 1 < points.cols()) {
445 double segment_start = arc_lengths(idx);
446 double segment_end = arc_lengths(idx + 1);
447 double t = (target - segment_start) / (segment_end - segment_start);
448
449 result.col(i) = (1.0 - t) * points.col(idx) + t * points.col(idx + 1);
450 } else {
451 result.col(i) = points.col(points.cols() - 1);
452 }
453 }
454
455 return result;
456}
Eigen::VectorXd compute_arc_length_table(const Eigen::MatrixXd &points)
Compute arc length parameterization table.