在C#中使用贝塞尔曲线编写名称 [英] Writing Name Using Bezier Curves In C#

查看:265
本文介绍了在C#中使用贝塞尔曲线编写名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个程序,该程序使用C#生成的图形来复制我在草书中写的名字.扭曲是,我必须使用贝塞尔曲线.我已经调用了使用4点和重力概念制作贝塞尔曲线的函数.我想问的是,制作10条曲线的最简单方法是什么.

I have to make a program that uses C# Generated Graphics to make a replica of my name that I wrote in cursive. Twist is, I have to use Bezier Curves. I've already called a function to make Bezier Curves using 4 points and a gravity concept. My question to you is, What would be the easiest way to make around 10 curves.

这是我的贝塞尔曲线的功能.

Here is my function for a Bezier Curve.

public static void bezierCurve(
     Graphics g, 
     double p1x, double p1y, 
     double p2x, double p2y, 
     double p3x, double p3y, 
     double p4x, double p4y)
{
    double t, r1x, r4x, r1y, r4y;
    float x, y;

    Pen black = new Pen(Color.Black);

    r1x = 3 * (p2x - p1x);
    r4x = 3 * (p4x - p3x);

    r1y = 3 * (p2y - p1y);
    r4y = 3 * (p4y - p3y);

    t = 0;
    while (t <= 1)
    {
        x = (float) ((2 * Math.Pow(t, 3) - 3 * Math.Pow(t, 2) + 1) * p1x
            + (-2 * Math.Pow(t, 3) + 3 * Math.Pow(t, 2)) * p4x
            + (Math.Pow(t, 3) - 2 * Math.Pow(t, 2) + t) * r1x
            + (Math.Pow(t, 3) - Math.Pow(t, 2)) * r4x);
        y = (float) ((2 * Math.Pow(t, 3) - 3 * Math.Pow(t, 2) + 1) * p1y
            + (-2 * Math.Pow(t, 3) + 3 * Math.Pow(t, 2)) * p1y
            + (Math.Pow(t, 3) - 2 * Math.Pow(t, 2) + t) * r1y
            + (Math.Pow(t, 3) - Math.Pow(t, 2)) * r4y);

        g.DrawRectangle(black, x, y, 1, 1);

        t = t + 0.01;
    }
}

推荐答案

我建议您使用一些矢量编辑软件,例如InkScape或Corel,使用该软件使用贝塞尔曲线绘制您的名字,然后另存为.SVG. SVG格式易于理解,此处是对贝塞尔曲线进行编码的示例.将坐标从路径复制到程序中.或者,使用一张方格纸手动获取坐标.

I would suggest taking some vector editing software, e.g. InkScape or Corel, draw your name with beziers using that software, then save as .SVG. The SVG format is easy to understand, here is an example of encoding a bezier path. Copy the coordinates from the path into your program. Alternatively, use a piece of graph paper to get the coordinates by hand.

C#已经具有绘制贝塞尔曲线的功能,请参见 Graphics.DrawBezier ,这将比您的实施效率更高(并产生更好的外观).

C# already has a function for drawing Beziers, see Graphics.DrawBezier, that is going to be much more efficient (and producing better-looking results) than your implementation.

这篇关于在C#中使用贝塞尔曲线编写名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆