findspan.c
来自「非均匀有理B样条的matlab程序」· C语言 代码 · 共 39 行
C
39 行
// Find the knot span of the parametric point u.
//
// INPUT:
//
// n - number of control points - 1
// p - spline degree
// u - parametric point
// U - knot sequence
//
// RETURN:
//
// s - knot span
//
// Algorithm A2.1 from 'The NURBS BOOK' pg68
int findspan(int n, int p, double u, double *U)
{
int low, high, mid;
// special case
if (u == U[n+1]) return(n);
// do binary search
low = p;
high = n + 1;
mid = (low + high) / 2;
while (u < U[mid] || u >= U[mid+1])
{
if (u < U[mid])
high = mid;
else
low = mid;
mid = (low + high) / 2;
}
return(mid);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?