Function anim::bezier_utils::solve_t_for_time

Function Documentation

double anim::bezier_utils::solve_t_for_time(const Point &P0, const Point &P1, const Point &P2, const Point &P3, double target_time, double *initial_guess = nullptr, double precision = 1e-6, int max_iterations = 4)

Finds the parameter t whose time component equals target_time.

Uses Newton-Raphson seeded by initial_guess and falls back to bisection if it fails to converge. Returns 0 or 1 for targets at or beyond the segment’s time range.

Parameters:
  • P0, P1, P2, P3 – The cubic Bézier control points.

  • target_time – The time to solve for.

  • initial_guess – Optional starting estimate for t in [0,1]; used only as a convergence hint and never modified. Pass nullptr to seed from a linear estimate.

  • precision – Absolute time error at which to stop.

  • max_iterations – Maximum Newton-Raphson steps before falling back.

Throws:

std::invalid_argument – if the segment’s start and end times are equal.

Returns:

The parameter t in [0,1].