public CurveSample Sample(double f)
{
if (f <= 0)
{
return(new CurveSample(new Vector3D(positions[0]), tangent(0)));
}
int N = arc_len.Length;
if (f >= arc_len[N - 1])
{
return(new CurveSample(new Vector3D(positions[N - 1]), tangent(N - 1)));
}
for (int k = 0; k < N; ++k)
{
if (f < arc_len[k])
{
int a = k - 1;
int b = k;
if (arc_len[a] == arc_len[b])
{
return(new CurveSample(new Vector3D(positions[a]), tangent(a)));
}
double t = (f - arc_len[a]) / (arc_len[b] - arc_len[a]);
return(new CurveSample(
Vector3D.Lerp(positions[a], positions[b], t),
Vector3D.Lerp(tangent(a), tangent(b), t)));
}
}
throw new ArgumentException("SampledArcLengthParam.Sample: somehow arc len is outside any possible range");
}