Deboor算法实现clamped uniform Bspline求解程序
[TOC]
本文为clamped uniform Bspline用C++实现的代码readme,代码链接.(代码重构中待重新开放)
功能概述(Fuction overview)
给定一组数据点拟合出一条clamped uniform Bspline.
Calculate a fitted clamped uniform Bspline for a given set data.
求指定位置/所有位置的Bspline拟合值.
Get fitted Bspline value at specific or all poisions.
求指定位置/所有位置的Bspline拟合一阶导数值.
Get fitted Bspline first derivative at specific or all poisions.
求2D的拟合Bspline曲线,并按照输入长度对拟合后的曲线进行分段,并得到分段点处的x,y坐标值及y对x的1阶导数.
Calculate clamped uniform Bspline for 2D points and devide it into specified segment length. Get x,y coordinates at segmentation points and dy/dx.
约定(premise)
Bspline的parameter vector $\textbf{u}$ 为$[0,1]$,步长$u_{step}$可以设定,默认为0.01.
Paremeter vector u of Bspline is [0,1]. Step of u is u_step and its defalut value is 0.01.
求特定位置点输入值为$input = \frac{u_i}{u_{step}}$.
Input for getting value/derivative at specific poisition will be formula above.
用于求导数的长度的近似方法:
Curve length approximation for calculating derivative is as follows:
$$
l_{seg} = \sum_{i=0}^{s} du \sqrt{ (\frac{dx_i}{du})^2 + (\frac{dy_i}{du})^2} \
= \sum_{i=0}^{s} u_{step} \sqrt{ x_i’ + y_i’}
$$
这种近似方法比实际值偏小.如果不是为了分段求长,可以考虑使用辛普森法则/高斯求解等数值方式求解.
对求出的B样条曲线求解点处的theta:$\theta$角以及曲率kappa:$\kappa$.
采用$y(u),x(u)$表述:
$$
\dot y =\frac{dy}{du} \\
\dot x =\frac{dx}{du} \\
y’ = \frac{dy}{dx}
$$
易知
$$
\begin{aligned}
&\tan \theta = \frac{dy}{dx} = \frac{dy/du}{dx/du} \\
&\theta = \arctan \frac{\dot y}{\dot x} = \arctan y’
\end{aligned}
$$
曲线上某点的曲率半径是该点的密切圆的半径,在$\lim\limits_{\Delta s \to 0}= \frac{\Delta \theta}{\Delta s} = \frac{d\theta}{ds}$存在的前提下,$\kappa = |\frac{d\theta}{ds}|$.
$$
\begin{aligned}
&\kappa = \Big|\frac{d\theta}{ds} = \frac{d(\arctan \frac{\dot y}{\dot x})}{ds}\Big|
= \Big|\frac{\frac{d(\arctan \frac{\dot y}{\dot x})}{dx}}{\frac{ds}{dx}} \Big| \\
&= \Big| \frac{d(\arctan y’)}{dx} \cdot \frac{dx}{ds} \Big|
= \frac{|y’’|}{1+(y’)^2} \cdot \frac{1}{\sqrt{1+(y’)^2}}
= \frac{|y’’|}{(1+(y’)^2)^ \frac{3}{2}} \\
&= \frac{|\ddot y \dot x - \dot y \ddot x|}{(\dot x^2 + \dot y^2)^{\frac{3}{2}}}
\end{aligned}
$$
其中$ds = \sqrt{1+(y’)^2} dx$可以由弧微分公式得到
This approximation result will be shorter compared wirh actual value. One can apply Simpson's law of Gaussian methond and so on to get integration, if segmentation is not considered.
具体使用方法参照example.cpp
.
Please refer to example.cpp for usage.
Bsplie的基础知识参照:https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/
Fundamental course:
https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/
或者本人对此课程的笔记:http://www.chuxin911.com/CS3621_Introduction_to_Computing_with_Geometry_Notes_2_20211007/
Deboor算法实现clamped uniform Bspline求解程序