文章目录
一、问题描述
对于给定的一系列任意维数的数据点(维数大于1),进行局部B样条插值,使曲线满足一定连续性(C1或C2连续),同时支持多种插值条件:
(1)只给定数据点;
(2)给定数据点、起点切矢、终点切矢、起点二阶导矢、终点二阶导矢;
(3)给定数据点、所有数据点处的切矢与二阶导矢。
作者用纯c语言,采用基于对象的编程思想,写了一个局部B样条插值库。函数主体:
/**********************************************************************************************
Function: local_b_spline_curve_interpolation
Description: 局部B样条插值
Input: 无
Output: 无
Input_Output: 结构体指针
Return: 错误号
Author: Marc Pony(marc_pony@163.com)
Others :局部3次/5次B样条插值参考《Trajectory Planning for Automatic Machine and Robots》8.10 Local Interpolation with B´ezier Curves
《The Nurbs Book 2nd 》 9.3.4 LOCAL CUBIC CURVE INTERPOLATION
支持n维3次B样条、n维5次B样条
***********************************************************************************************/
ERROR_ID local_b_spline_curve_interpolation(BSplineFitting* p)
{
VECTOR* u_ = NULL, *t = NULL;
INTEGER pointCount, dimension;
POINT* q = NULL;
STACKS S;
ERROR_ID errorID = _ERROR_NO_ERROR;
if (p == NULL)
{
errorID = _ERROR_INPUT_PARAMETERS_ERROR;
return errorID;
}
if (p->pointCount < 2)
{
errorID = _ERROR_INPUT_PARAMETERS_ERROR;
return errorID;
}
pointCount = p->pointCount;
q = p->points;
dimension = p->points->dimension;
init_stack(&S);
u_ = creat_vector(pointCount, &errorID, &S);
if (errorID != _ERROR_NO_ERROR) goto EXIT;
p->u_ = u_;
errorID = calculate_temp_knot_vector(p);
if (errorID != _ERROR_NO_ERROR) goto EXIT;
if (!p->givenAllTangentVectors)
{
t = creat_multiple_vectors(dimension, pointCount, &errorID, &S);
if (errorID != _ERROR_NO_ERROR) goto EXIT;
p->t = t;
errorID = calculate_all_unit_tangent_vectors(p);
if (errorID != _ERROR_NO_ERROR) goto EXIT;
}
errorID = calculate_control_points_for_local_b_spline_curve_interpolation(p);
if (errorID != _ERROR_NO_ERROR) goto EXIT;
errorID = calculate_knot_vector_for_local_b_spline_curve_interpolation(p);
if (errorID != _ERROR_NO_ERROR) goto EXIT;
EXIT:
free_stack(&S);
return errorID;
}
以下是一些结果展示,欢迎交流与学习。
2维B样条插值:
3维B样条插值:
6维B样条插值:
二、局部B样条插值的一些特性
(1)保持局部数据的共线性
(2)对于局部3次B样条插值为C1连续,对于局部5次B样条插值为C2连续
(3)曲线速率(切矢模长)近似均匀,意味着对参数s均匀离散后计算得到B样条上的点为近似等距分布
(4)若起点与终点重合,可生成平滑的封闭曲线,如上图。