/// <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
主站蜘蛛池模板:
鹰潭市|
普陀区|
惠水县|
永和县|
报价|
普陀区|
府谷县|
垫江县|
麻江县|
阳泉市|
永福县|
都匀市|
韶关市|
隆子县|
高台县|
乌鲁木齐市|
遂川县|
凌云县|
尼玛县|
津市市|
东至县|
馆陶县|
珠海市|
宜宾市|
清徐县|
三门县|
九龙县|
丹江口市|
金昌市|
福海县|
宁武县|
民和|
湟中县|
沿河|
寻甸|
哈尔滨市|
诏安县|
通辽市|
临城县|
修水县|
铜陵市|