说明:Spline类就是Cardinal样条曲线了,这个类里面记录了4个控制点:m_startControlPoint, m_startPoint, m_endPoint, m_endControlPoint, 分别按顺序对应Pk-1, Pk, Pk+1, Pk+2, 由于Cardinal是用多个线段去模拟曲线,所以我们在这里取20个点,这样,在Pk 和 Pk+1之间,有20个样本点,用画直线的方法将这些点按顺序连起来,连成的曲线段就是我们所要的Cardinal 曲线了
|
using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace CardinalTest
{
/// <summary>
/// the declaration of the Spline, each spline contains 4 control points
/// </summary>
public class Spline
{
// it's the "Pk-1" point
private Point3D m_startControlPoint;
// it's the "Pk" point
private Point3D m_startPoint;
// it's the "Pk+1" point
private Point3D m_endPoint;
// it's the "Pk+2" point
private Point3D m_endControlPoint;
// that means we'll generate 20 sample points between Pk & Pk+1, so "u" will start from 0.00F
// and the increase step is 0.05F
private static readonly int m_sampleCount = 20;
// the "t" in Cardinal altorithm
private static readonly float m_tension = 0.0F;
// store the result sample points
private Point3D[] m_ctrlPoints;
// indicate whether this spline is the first, if it is,
//the m_startControlPoint & m_startPoint will be the same
// because the 4 points can just determine the spline between Pk &