【问题标题】:Zooming in on quadratic curve line in c#在c#中放大二次曲线线
【发布时间】:2015-04-11 07:37:30
【问题描述】:

我对 c# 比较陌生,我正在尝试使用 X 和 Y 图绘制二次曲线以进行缩放。我画的曲线虽然出现在屏幕的左上角,非常小,几乎看不到。有没有办法放大我的曲线并将其对齐到中间以便正确显示?

protected override void OnPaint(PaintEventArgs e)
    {


        float a = 1, b = -3, c = -4;
        double x1, x2, x3, y1, y2, y3, delta;
        delta = (b * b) - (4 * a * c);
        x1 = ((b * (-1)) + Math.Sqrt(delta)) / (2 * a);
        y1 = a * (x1 * x1) + b * (x1) + c;
        x2 = x1 + 1;
        y2 = a * (x2 * x2) + b * (x2) + c;
        x3 = x1 - 3;
        y3 = a * (x3 * x3) + b * (x3) + c;
        int cx1 = Convert.ToInt32(x1);
        int cx2 = Convert.ToInt32(x2);
        int cx3 = Convert.ToInt32(x3);
        int cy1 = Convert.ToInt32(y1);
        int cy2 = Convert.ToInt32(y2);
        int cy3 = Convert.ToInt32(y3);

        Graphics g = e.Graphics;


        Pen aPen = new Pen(Color.Blue, 1);
        Point point1 = new Point(cx1, cy1);
        Point point2 = new Point(cx2, cy2);
        Point point3 = new Point(cx3, cy3);
        Point[] Points = { point1, point2, point3 };
        g.DrawCurve(aPen, Points);

【问题讨论】:

  • 如果能附上你想要的图片就更好了?

标签: c# zooming bezier


【解决方案1】:

是的使用Graphics.TranslateTransformMatrixGraphics.MultiplyTransform 移动(平移)和放大(缩放)Graphics 结果是可能的,甚至相当简单:

using System.Drawing.Drawing2D;
//..

int deltaX = 100;
int deltaY = 100;
g.TranslateTransform(deltaX, deltaY);

float factor = 2.5f;
Matrix m = new Matrix();
m.Scale(factor, factor);

g.MultiplyTransform(m);

请注意,缩放就像一个镜头,会放大像素。因此,当您扩大 Graphics 时,您可能希望缩小 Pen.Width..

以前用过一个..

    g.DrawEllipse(Pens.Blue, 11, 11, 55, 55);

..和两个转换后..

    g.DrawEllipse(Pens.Red, 11, 11, 55, 55);
    using (Pen pen = new Pen(Color.Green, 1/factor))
        g.DrawEllipse(pen, 11, 11, 44, 44);

..这些调用导致了这个图像:

(我已经改变了绿色圆圈的半径以避免完全覆盖..)

由您决定移动和缩放所需的数字;这可能涉及找到所涉及点的最小值和最大值..

【讨论】:

    【解决方案2】:

    我建议你研究一下Microsoft Chart controls,它有很多有趣的功能,关于如何制作这种曲线以及参数化它们的能力。

    更新版本的链接:here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-03
      • 2019-04-18
      • 2020-04-20
      • 2013-03-31
      • 1970-01-01
      • 2017-04-03
      • 2013-02-02
      相关资源
      最近更新 更多