C# 试图画一个函数

C# 试图画一个函数,c#,C#,我想用c#来画一个图,类似这样的 到目前为止,我已经能够使用绘图线绘制简单的直线,但这本身就非常有限,因为我不仅被迫提供起点和终点,而且还限于直线 正如你所看到的 在表达式的最后一段有一条曲线(一条倒抛物线) 有关于如何在bmp图形中执行此操作的提示吗 我一直在用下面的方法画画 using (Graphics g = Graphics.FromImage(bmp)) { //g.DrawLine and others } 您可以使用图形类DrawCurve中的类似

我想用c#来画一个图,类似这样的

到目前为止,我已经能够使用
绘图线
绘制简单的直线,但这本身就非常有限,因为我不仅被迫提供起点和终点,而且还限于直线

正如你所看到的

在表达式的最后一段有一条曲线(一条倒抛物线)

有关于如何在bmp图形中执行此操作的提示吗

我一直在用下面的方法画画

   using (Graphics g = Graphics.FromImage(bmp))
           { //g.DrawLine and others
}

您可以使用图形类
DrawCurve
中的类似函数。它将一组点作为参数,然后通过它们进行绘制。根据曲线的精度,可以获得起点、终点和转折点


绘制函数的第一步是对其求值并将其保存到点阵列:

        //Create a Point array to store the function's values
        Point[] functionValues = new Point[100];

        //Calculate the function for every Point in the Point array
        for (int x = 0; x < functionValues.Length; x++)
        {
            //Set the every point's X value to the current iteration of the loop. That means that we are evaluating the function in steps of 1
            functionValues[x].X = x;
            //Calculate the Y value of every point. In this exemple I am using the function x^2
            functionValues[x].Y = x * x;
        }

我建议大家参考sinelaw的答案:我会尝试一下,但是用这些函数创建一个点数组。。似乎需要一些修补来补充(正确的)答案:还有一个超负荷,让你控制紧张;非常有帮助给定a、my和两个Tc和Td值,创建十几个点的问题在哪里??
        //Iterate through every point in the array
        for (int i = 1; i < functionValues.Length; i++)
        {
            //Draw a line between every point and the one before it
            //Note that 'g' is your graphics object
            g.DrawLine(Pens.Black, functionValues[i-1], functionValues[i]);
        }
    Point[] functionValues;

    public Form1()
    {
        InitializeComponent();
        this.DoubleBuffered = true;
        this.Paint += Form1_Paint; //Subscribe to the Paint Event

        //Create a Point array to store the function's values
        functionValues = new Point[100];

        //Calculate the function for every Point in the Point array
        for (int x = 0; x < functionValues.Length; x++)
        {
            //Set the every point's X value to the current iteration of the loop. That means that we are evaluating the function in steps of 1
            functionValues[x].X = x;
            //Calculate the Y value of every point. In this exemple I am using the function x^2
            functionValues[x].Y = x * x;
        }
    }

    void Form1_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        //Draw using 'g' or 'e.Graphics'.
        //For exemple:

        //Iterate through every point in the array
        for (int i = 1; i < functionValues.Length; i++)
        {
            //Draw a line between every point and the one before it
            g.DrawLine(Pens.Black, functionValues[i - 1], functionValues[i]);
        }

    }
this.Invalidate();