我想使用imagefrom位图在图片框中绘制一条曲线(二极管曲线).我现在遇到一个问题,我的点数据被保存为Double,保持这种状态非常重要.
例如,我的情节中的一个点是这样的:
电压:-0.175电流:-9.930625E-06
是的,这是一个双倍!现在我怎么能有一点要做的例子:
Point[] ptarray = new Point[3];
ptarray[0] = new Point(250, 250);
Run Code Online (Sandbox Code Playgroud)
是否有一个替代Point []接受双值?我有一个500x500的图片框.有没有办法将这些值转换为仍可以节省成本的有效点?我正在使用微安培(10 ^ -6)和电压!
Cam*_*ron 15
好吧,如果float足够精确,那么你可以使用PointF结构:
var point = new PointF(3.5f, 7.9f);
Run Code Online (Sandbox Code Playgroud)
如果你真的需要,你可以定义自己的PointD结构:
public struct PointD {
public double X;
public double Y;
public PointD(double x, double y) {
X = x;
Y = y;
}
public Point ToPoint() {
return new Point((int)X, (int)Y);
}
public override bool Equals(object obj) {
return obj is PointD && this == (PointD)obj;
}
public override int GetHashCode() {
return X.GetHashCode() ^ Y.GetHashCode();
}
public static bool operator ==(PointD a, PointD b) {
return a.X == b.X && a.Y == b.Y;
}
public static bool operator !=(PointD a, PointD b) {
return !(a == b);
}
}
Run Code Online (Sandbox Code Playgroud)
平等代码最初来自这里.
该ToPoint()方法允许您将其转换为Point对象,但当然精度将被截断.
| 归档时间: |
|
| 查看次数: |
15347 次 |
| 最近记录: |