/// <summary>
/// Refer to : http://www.codeproject.com/KB/graphics/BezierSpline.aspx
/// Solves a tridiagonal system for one of coordinates (x or y) of first Bezier control points.
/// </summary>
/// <param name="rhs">Right hand side vector.</param>
/// <param name="x">Solution vector.</param>
void GetFirstControlPoints(
__in const std::vector<FLOAT>& rhs,
__out std::vector<FLOAT>& x )
{
ATLASSERT(rhs.size()==x.size());
int n = rhs.size();
std::vector<FLOAT> tmp(n); // Temp workspace.
FLOAT b = 2.0f;
x[0] = rhs[0] / b;
for (int i = 1; i < n; i++) // Decomposition and forward substitution.
{
tmp[i] = 1 / b;
b = (i < n-1 ? 4.0f : 3.5f) - tmp[i];
x[i] = (rhs[i] - x[i-1]) / b;
}
for (int i = 1; i < n; i++)
{
x[n-i-1] -= tmp[n-i] * x[n-i]; // Back substitution.
}
}
/// <summary>
/// Refer to : http://www.codeproject.com/KB/graphics/BezierSpline.aspx
/// Get open-ended Bezier Spline Control Points.
/// </summary>
/// <param name="knots">Input Knot Bezier spline points.</param>
/// <param name="firstCtrlPt">Output First Control points array of knots.size()-1 length.</param>
/// <param name="secondCtrlPt">Output Second Control points array of knots.size()-1 length.</param>
void GetCurveControlPoints(
__in const std::vector<D2D1_POINT_2F>& knots,
__out std::vector<D2D1_POINT_2F>& firstCtrlPt,
__out std::vector<D2D1_POINT_2F>& secondCtrlPt )
{
ATLASSERT( (firstCtrlPt.size()==secondCtrlPt.size())
&& (knots.size()==firstCtrlPt.size()+1) );
int n = knots.size()-1;
ATLASSERT(n>=1);
if (n == 1)
{
// Special case: Bezier curve should be a straight line.
// 3P1 = 2P0 + P3
firstCtrlPt[0].x = (2 * knots[0].x + knots[1].x) / 3.0f;
firstCtrlPt[0].y = (2 * knots[0].y + knots[1].y) / 3.0f;
// P2 = 2P1
主站蜘蛛池模板:
防城港市|
湟中县|
塔城市|
奉贤区|
南雄市|
奉节县|
新宁县|
保亭|
新民市|
攀枝花市|
崇礼县|
缙云县|
北海市|
微博|
南平市|
乐业县|
年辖:市辖区|
临湘市|
安仁县|
崇左市|
武定县|
邵阳市|
弋阳县|
马边|
邯郸市|
阿合奇县|
城口县|
承德县|
华宁县|
西充县|
沧源|
三明市|
曲松县|
偏关县|
肃宁县|
彰化市|
青州市|
西畴县|
明水县|
孟州市|
嘉义县|