如何绘制基数样条

基数样条是一条曲线,通过给定的一组点平滑经过。 若要绘制基数样条,请创建一个 Graphics 对象并将点数组的地址传递给 DrawCurve 该方法。

绘制 Bell-Shaped 基样线

  • 以下示例绘制一个通过五个指定点的钟形基数样条曲线。 插图显示了曲线和五个点。

    显示钟形样条的图表。

Point[] points = {
   new Point(0, 100),
   new Point(50, 80),
   new Point(100, 20),
   new Point(150, 80),
   new Point(200, 100)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points);
Dim points As Point() = { _
   New Point(0, 100), _
   New Point(50, 80), _
   New Point(100, 20), _
   New Point(150, 80), _
   New Point(200, 100)}

Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points)

绘制封闭的基数样线

  • 使用Graphics类的DrawClosedCurve方法绘制封闭的基样线。 在封闭的基数样条曲线中,曲线通过序列中的最后一个点延续,并与序列中的第一个点连接。 以下示例绘制一个通过六个指定点的封闭基样线。 下方插图显示了封闭的样条以及六个点:

显示闭合基样线的关系图。

Point[] points = {
   new Point(60, 60),
   new Point(150, 80),
   new Point(200, 40),
   new Point(180, 120),
   new Point(120, 100),
   new Point(80, 160)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawClosedCurve(pen, points);
Dim points As Point() = { _
   New Point(60, 60), _
   New Point(150, 80), _
   New Point(200, 40), _
   New Point(180, 120), _
   New Point(120, 100), _
   New Point(80, 160)}

Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawClosedCurve(pen, points)

更改基数样条曲线的弯度

  • 通过将张力参数传递给 DrawCurve 方法来更改基数样条的弯曲方式。 以下示例绘制了三条基数样条曲线,并且这些曲线通过相同的一组点。 以下图示显示了三个样条及其张力值。 请注意,当紧张度为 0 时,点通过直线连接。

显示三个基数样条的图表。

Point[] points = {
   new Point(20, 50),
   new Point(100, 10),
   new Point(200, 100),
   new Point(300, 50),
   new Point(400, 80)};

Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points, 0.0f);
e.Graphics.DrawCurve(pen, points, 0.6f);
e.Graphics.DrawCurve(pen, points, 1.0f);
Dim points As Point() = { _
   New Point(20, 50), _
   New Point(100, 10), _
   New Point(200, 100), _
   New Point(300, 50), _
   New Point(400, 80)}

Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points, 0.0F)
e.Graphics.DrawCurve(pen, points, 0.6F)
e.Graphics.DrawCurve(pen, points, 1.0F)

编译代码

前面的示例旨在与 Windows 窗体一起使用,并且它们需要 PaintEventArgse,这是事件处理程序的参数 Paint

另请参阅