3

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). My picture box is sized at 500x500. I also know that the top-left corner has point of (0,0) and bottom right corner has points of (500,500). Obviously the origin should be (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. 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)

EDIT

What I am trying to do is have a curve like these, so those points I have are used in Graphics.DrawCurve:

enter image description here

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

enter image description here

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!!! Thanks all.

Dumbo
  • 13,555
  • 54
  • 184
  • 288

2 Answers2

1

If you want scaling to fit screen multiply each voltage and current value by 50.

All your points lie in third quadrant; you can choose origin (0, 0) on your screen and make all your negative x-axis points positive, i.e. flip along y-axis.

If you don't want scaling, keep multiplication factor unity.

ukhardy
  • 2,084
  • 1
  • 13
  • 12
  • @ukhardy oh no math exam again :( – Dumbo Mar 20 '11 at 12:51
  • @ukhardy Thanks for tip, these sample points I posted are just a few and they could be in all quadrant (but mustly third and first). Do I have to do calculation for each quadrant separatly or just one convertion will do?? – Dumbo Mar 20 '11 at 12:53
  • In that case if your points lie in all quadrants then you can leave cartesian origin (0,0) and apply Euclidean transformations. You can get easy to implement formulas from here http://en.wikipedia.org/wiki/Cartesian_coordinate_system – ukhardy Mar 20 '11 at 13:02
  • To shift origin from (0, 0) to (X, Y) your each point (x, y) becomes (x + X, y + Y). – ukhardy Mar 20 '11 at 13:05
  • Choose the scaling factor M, of order such that max(|ordinate|) * M <= 500. And each (x, y) becomes (Mx, My). – ukhardy Mar 20 '11 at 13:13
  • @ukhardy oh god my brain is halted :( . would you mind giving a number please? sorry to ask by the way I know its my own thing to do. – Dumbo Mar 20 '11 at 13:18
1

To use the entire range of the picture box, with (V,C) = (0, 0) being mapped to the centre, you can use the transformations:

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

Do note that this will make Current increase upward on the Y axis. If you want the reverse, use (1 + Current/10) in the second transformation.

Ani
  • 111,048
  • 26
  • 262
  • 307
  • Hi, I think doing this just made my curve a stright line. please see my edit in orginal post. – Dumbo Mar 20 '11 at 13:35
  • @Sean87: Did you multiply current by `10 ^ 6` before doing this? That would be required. – Ani Mar 20 '11 at 13:38
  • oh yes I forgotted that. it looks like a real curve now! thanks. but it is not scaled yet. so it is very small. how can I make it bigger to fit in my 500x500 box? I will update my post with screen shot. – Dumbo Mar 20 '11 at 13:44