MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ reparameterize_by_arc_length() [1/2]

Eigen::MatrixXd MayaFlux::Kinesis::reparameterize_by_arc_length ( const Eigen::MatrixXd &  points,
Eigen::Index  num_samples 
)

Reparameterize curve by arc length.

Parameters
pointsOriginal points (columns)
num_samplesNumber of output samples
Returns
Arc-length parameterized points

Definition at line 420 of file MotionCurves.cpp.

423{
424 Eigen::VectorXd arc_lengths = compute_arc_length_table(points);
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.

References compute_arc_length_table().

+ Here is the call graph for this function: