代码之家  ›  专栏  ›  技术社区  ›  Futterkiste

函数比例图

  •  0
  • Futterkiste  · 技术社区  · 2 年前

    我正在尝试制作一个Windows窗体应用程序,它将显示函数图。

    enter image description here

    我如何拉伸图表,使其更偏向侧面?

      private void Graphs_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.DrawLine(new Pen(Color.Black), 0, ClientSize.Height / 2, ClientSize.Width, ClientSize.Height / 2);
            e.Graphics.DrawLine(new Pen(Color.Black), ClientSize.Width / 2, 0, ClientSize.Width / 2, ClientSize.Height);
            for (double x = -100; x < 100; x += 0.1)
            {
                double y = x * x * -1;
                //y = x * -1;   
                //y = Math.Sqrt(x) * -1;
                //y = 1 / x;
                try
                {
                    e.Graphics.FillEllipse(new SolidBrush(Color.Red), (ClientSize.Width / 2) - 5 + Convert.ToInt32(x), (ClientSize.Height / 2) - 5 + Convert.ToInt32(y), 10, 10);
    
                }
                catch (Exception)
                {
                
                }
            }
        }
    
    1 回复  |  直到 2 年前
        1
  •  1
  •   Pete Kirkham    2 年前

    为x和y添加单独的比例因子;目前你有y=x²|-100<x<100,所以y在0到10000之间。

    没有1:1的纵横比可以在方形框中显示该曲线,因此可以显示较少的曲线或以不同的方式缩放轴。

    我会修复视口,比如说-100<=x<=100和0<=y<=10000然后根据ClientSize和视口范围计算xScale和yScale。