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:
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!!! Thanks all.
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.
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.
精彩评论