简体   繁体   English

将笛卡尔坐标转换为图片框坐标c#

[英]convert cartesian coordinate to picturebox coordinates c#

The question I have is more of mathematics! 我的问题更多的是数学! I have some pair of values that reperesent points of a curve that I want to draw on a picturebox using fromImage(Bitmap). 我有一些值可以使用fromImage(Bitmap)在一个图片框上绘制曲线的重复点。 My picture box is sized at 500x500. 我的图片框大小为500x500。 I also know that the top-left corner has point of (0,0) and bottom right corner has points of (500,500). 我也知道左上角有点(0,0),右下角有点(500,500)。 Obviously the origin should be (250,250). 显然原点应该是(250,250)。 Now I am wondering how can I convert my own values to this format? 现在我想知道如何将我自己的值转换为这种格式?

A sample points that I have are like: 我有一个样本点是:

Voltage: -0.175         Current: -9.930625E-06
Voltage: -0.171875      Current: -9.53375E-06
Voltage: -0.16875       Current: -9.136875E-06
Voltage: -0.16875       Current: -8.74E-06
Voltage: -0.165625      Current: -8.343125E-06
Voltage: -0.1625        Current: -7.94625E-06
Voltage: -0.1625        Current: -7.549375E-06
Voltage: -0.159375      Current: -7.152188E-06
Voltage: -0.15625       Current: -6.755312E-06

You see there are Voltage values which should be on X axis and Current on Y axis. 您会看到电压值应该在X轴上,电流在Y轴上。 I know that to make them a bit better I have to multiply them in a bigger number and also maybe multiply by an inverse or something. 我知道为了使它们更好一点,我必须将它们乘以更大的数字,也可以乘以反转或其他东西。 but I still cant figure out how to represent them on my picturebox. 但我仍然无法弄清楚如何在我的图片框上代表它们。 These points are usually start from 3rd quadrant and end up in first quadrant. 这些点通常从第三象限开始,最终在第一象限。 Please assist! 请协助!

Just to add that my X axis min and max are -2V and +2V and for Y Axis I would have -10uA to +10uA (that is 10*10^-6) 只是补充一点,我的X轴最小和最大值是-2V和+ 2V,对于Y轴我会有-10uA到+ 10uA(即10 * 10 ^ -6)

EDIT 编辑

What I am trying to do is have a curve like these, so those points I have are used in Graphics.DrawCurve: 我想要做的是有这样的曲线,所以我在Graphics.DrawCurve中使用了这些点:

在此输入图像描述

UPDATE This is how my code looks like: 更新这是我的代码的样子:

            g.DrawLine(penAxis, 250, 0, 250, 500); // Y AXIS 
        g.DrawLine(penAxis, 0, 250, 500, 250); // X AXIS          

        PointF[] p = new PointF[pinData.GetLength(0)];   //pinData is AboutBoxForm double[,] array

        for (int i = 0; i < pinData.GetLength(0); i++)
        {
            p[i] = new PointF(250 * ((1 + (float)pinData[i, 0]) / 2), 250 * ((1 + (float)pinData[i, 1] )/ 10));  
        }

        Pen pengraph = new Pen(pinColor, 2.0F);
        g.DrawCurve(pengraph, p);

PROGRESS UPDATE 进展更新

ok now using the code below my curve looks like: 好了,现在使用我的曲线下方的代码如下:

            g.DrawLine(penAxis, 250, 0, 250, 500); // Y AXIS 
        g.DrawLine(penAxis, 0, 250, 500, 250); // X AXIS          

        PointF[] p = new PointF[pinData.GetLength(0)];   //pinData is AboutBoxForm double[,] array

        for (int i = 0; i < pinData.GetLength(0); i++)
        {
            p[i] = new PointF(250 * (1 - ((float)pinData[i, 1] *100000) / 10), 250 * (1 + (((float)pinData[i, 0]))/ 2));  
        }

        Pen pengraph = new Pen(pinColor, 2.0F);
        g.DrawCurve(pengraph, p);

在此输入图像描述

I think now the problem is scaling it. 我认为现在的问题是缩放它。 SOLVED I had to multiply by 10^6 but I did with ^5 no it is ok!!! 已经解决了我不得不乘以10 ^ 6,但我做了^ 5没有它是好的! Thanks all. 谢谢大家。

If you want scaling to fit screen multiply each voltage and current value by 50 . 如果要缩放以适合屏幕,则将每个电压和电流值乘以50

All your points lie in third quadrant ; 你的所有要点都在third quadrant ; you can choose origin (0, 0) on your screen and make all your negative x-axis points positive, ie flip along y-axis . 您可以在屏幕上选择原点(0, 0)并使所有negative x-axis点为正,即沿y-axis翻转。

If you don't want scaling, keep multiplication factor unity. 如果您不想缩放,请保持乘法因子一致。

To use the entire range of the picture box, with (V,C) = (0, 0) being mapped to the centre, you can use the transformations: 要使用图片框的整个范围,将(V,C) = (0, 0)映射到中心,您可以使用转换:

X = 250 * (1 + Voltage/2)
Y = 250 * (1 - Current/10)

Do note that this will make Current increase upward on the Y axis. 请注意,这将使电流在Y轴上向上增加。 If you want the reverse, use (1 + Current/10) in the second transformation. 如果您想要反向,请在第二次转换中使用(1 + Current/10)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM