放大C#中的二次曲线 [英] Zooming in on quadratic curve line in c#

查看:118
本文介绍了放大C#中的二次曲线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am relatively new to c# and i am trying to draw the quadratic curve with an X and Y graph to scale with. The i drew curve although appears at the upper left corner of the screen which is very small and barely noticeable. Is there possible way to enlarge my curve line and align it to the middle so it can be shown properly?

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);

推荐答案

可以甚至非常简单地通过移动(翻译)和放大(缩放)Graphics结果 Graphics.TranslateTransform 矩阵

Yes it is possible and even rather simple to both move (Translate) and enlarge (Scale) the Graphics results by using Graphics.TranslateTransform and Matrix and Graphics.MultiplyTransform:

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.

Note that the scaling works like a lens and will enlarge the pixels. So you may want to scale down the Pen.Width when you scale up the Graphics..

以前使用过一个.

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

..以及转换后的两个..

..and two after the transformations..

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

..这些调用产生以下图像:

..these calls result in this image:

(为了避免完全覆盖,我更改了绿色圆圈的半径.)

(I have changed the green circle's radius to avoid complete overlaying..)

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

It will be up to you to find the desired numbers for the moving and scaling; this will probably involve finding the minimum and maximum values for points involved..

这篇关于放大C#中的二次曲线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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