'在要绘制的对象上绘制平滑的曲线:
Private Sub Form_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
'定义Point数组
dim ppoints as point() = new point(499){}
'将这500个点值存放到这个ppoints数组中,过程略......
ppoints(0).x=...:ppoints(0).y=...
...........
ppoints(n).x=...:ppoints(n).y=...
...........
ppoints(499).x=...:ppoints(499).y=...
'绘制平滑曲线
e.Grapjocs.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias '消除锯齿
e.Graphics.(Drawing.Pens.Red, ppoints) '用红色绘制此平滑线条
End Sub
实在对不起 我自己记错了 Bezier是不能经过所有的点的 当然自己加一些辅助点能达到目的 但显然麻烦 用Hermite插值方法也可以 但也麻烦
用上边几位提到的DrawCurve 这是Programming Windows with C#中使用DrawCurve的范例
//----------------------------------------------
// CanonicalSpline.cs ?2001 by Charles Petzold
//----------------------------------------------
using System;
using System.Drawing;
using System.Windows.Forms;
class CanonicalSpline: Form
{
protected Point[] apt = new Point[4];
protected float fTension = 0.5f;
public static void Main()
{
Application.Run(new CanonicalSpline());
}
public CanonicalSpline()
{
Text = "Canonical Spline";
BackColor = SystemColors.Window;
ForeColor = SystemColors.WindowText;
ResizeRedraw = true;
比如三次样条插值的公式
v0 = the point before a
v1 = the point a
v2 = the point b
v3 = the point after b
function Cubic_Interpolate(v0, v1, v2, v3,x)
P = (v3 - v2) - (v0 - v1)
Q = (v0 - v1) - P
R = v2 - v0
S = v1
return Px3 + Qx2 + Rx + S
end of function
但是,对于一个点来说,有两个坐标值。
是不是将前后4个点的X坐标代入公式,得到插值得x坐标;
将前后4个点的Y坐标代入公式,得到插值得y坐标;