C#,计算几何,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码

C#,计算几何,二维贝塞尔拟合曲线(Bézier Curve)参数点的计算代码_第1张图片

 Pierre Bézier

Bézier 算法用于曲线的拟合与插值。

插值是一个或一组函数计算的数值完全经过给定的点。

拟合是一个或一组函数计算的数值尽量路过给定的点。

这里给出 二维 Bézier 曲线拟合的参数点计算代码。

区别于另外一种读音接近的贝塞耳插值算法Bessel's interpolation)哈!德国,法国。

1 文本格式


class Point
{
    double X;
    double Y;
}

public Point GetBezierPoint(double t, Point p0, Point p1, Point p2, Point
p3)
{
    double cx = 3 * (p1.X - p0.X);
    double bx = 3 * (p2.X - p1.X) - cx;
    double ax = p3.X - p0.X - cx - bx;
    double cy = 3 * (p1.Y - p0.Y);
    double by = 3 * (p2.Y - p1.Y) - cy;
    double ay = p3.Y - p0.Y - cy - by;
    double tCubed = t * t * t;
    double tSquared = t * t;
    double resultX = (ax * tCubed) + (bx * tSquared) + (cx * t) + p0.X;
    double resultY = (ay * tCubed) + (by * tSquared) + (cy * t) + p0.Y;
    return new Point((int)resultX, (int)resultY);
}
 

 ——————————————————————

POWER BY 315SOFT.COM &
TRUFFER.CN

2 代码格式


class Point
{
    double X;
    double Y;
}

public Point GetBezierPoint(double t, Point p0, Point p1, Point p2, Point
p3)
{
    double cx = 3 * (p1.X - p0.X);
    double bx = 3 * (p2.X - p1.X) - cx;
    double ax = p3.X - p0.X - cx - bx;
    double cy = 3 * (p1.Y - p0.Y);
    double by = 3 * (p2.Y - p1.Y) - cy;
    double ay = p3.Y - p0.Y - cy - by;
    double tCubed = t * t * t;
    double tSquared = t * t;
    double resultX = (ax * tCubed) + (bx * tSquared) + (cx * t) + p0.X;
    double resultY = (ay * tCubed) + (by * tSquared) + (cy * t) + p0.Y;
    return new Point((int)resultX, (int)resultY);
}

 

你可能感兴趣的:(C#计算几何,Graphics,Recipes,c#,曲线,插值,拟合)