绘制二次曲线

发布于 2024-08-05 08:44:46 字数 49 浏览 3 评论 0原文

如何使用 C# System.Drawing 命名空间绘制经过 3 个点的二次曲线?

How can I draw Quadratic Curve through 3 points by using C# System.Drawing namespace?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆消瘦 2024-08-12 08:44:46

您想要绘制一条通过三个给定点的二次曲线,还是想要绘制二次贝塞尔曲线使用三个给定点?

如果你想要的是贝塞尔曲线,试试这个:

private void AddBeziersExample(PaintEventArgs e)
{

    // Adds a Bezier curve.
    Point[] myArray =
             {
                 new Point(100, 50),
                 new Point(120, 150),
                 new Point(140, 100)
             };

    // Create the path and add the curves.
    GraphicsPath myPath = new GraphicsPath();
    myPath.AddBeziers(myArray);

    // Draw the path to the screen.
    Pen myPen = new Pen(Color.Black, 2);
    e.Graphics.DrawPath(myPen, myPath);
}

我刚刚无耻地从 GraphicsPath.AddBeziers() 的 MSDN 文档

编辑:如果您真正想要的是拟合二次曲线,那么您需要执行 曲线拟合多项式插值对你的点。也许这个答案来自询问博士数学会有所帮助。

Do you want to draw a quadratic curve that goes through three given points, or do you want to draw a quadratic Bézier curve that uses three given points?

If what you want is a Bézier curve, try this:

private void AddBeziersExample(PaintEventArgs e)
{

    // Adds a Bezier curve.
    Point[] myArray =
             {
                 new Point(100, 50),
                 new Point(120, 150),
                 new Point(140, 100)
             };

    // Create the path and add the curves.
    GraphicsPath myPath = new GraphicsPath();
    myPath.AddBeziers(myArray);

    // Draw the path to the screen.
    Pen myPen = new Pen(Color.Black, 2);
    e.Graphics.DrawPath(myPen, myPath);
}

Which I just shamelessly lifted from the MSDN documentation for GraphicsPath.AddBeziers().

Edit: If what you really want is to fit a quadratic curve, then you need to do a curve fitting or polynomial interpolation on your points. Perhaps this answer from Ask Dr. Math will help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文