gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 17:18:50 34 4
gpt4 key购买 nike

我的问题更多是数学!我有一对值,代表我想使用 fromImage(Bitmap) 在图片框上绘制的曲线点。我的图片框大小为 500x500。我也知道左上角有 (0,0) 点,右下角有 (500,500) 点。显然原点应该是(250,250)。现在我想知道如何将自己的值转换为这种格式?

我的样本点如下:

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

您会看到 X 轴上应该有电压值,Y 轴上应该有电流值。我知道为了让它们更好一点,我必须将它们乘以更大的数字,也可能乘以倒数或其他东西。但我仍然不知道如何在我的图片框上表示它们。这些点通常从第三象限开始,到第一象限结束。请协助!

只是补充一点,我的 X 轴最小值和最大值是 -2V 和 +2V,对于 Y 轴,我会有 -10uA 到 +10uA(即 10*10^-6)

编辑

我想要做的是有一条像这样的曲线,所以我在 Graphics.DrawCurve 中使用了这些点:

enter image description here

更新这是我的代码的样子:

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

进度更新

好的,现在使用曲线下方的代码如下所示:

            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

我认为现在的问题是扩展它。 已解决 我不得不乘以 10^6 但我用了 ^5 不,没关系!!!谢谢大家。

最佳答案

要使用图片框的整个范围,将 (V,C) = (0, 0) 映射到中心,您可以使用转换:

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

请注意,这将使电流在 Y 轴上向上增加。如果您想要反转,请在第二个转换中使用 (1 + Current/10)

关于c# - 将笛卡尔坐标转换为图片框坐标 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5368548/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com