I want to draw a curve (a diode curve) in a picturebox using imagefrom bitmap. I have a problem now and it is my point data are saved as Double and it is really important to keep the precesion.
for example a point in the plot I have is like this:
Voltage: -0.175 Current: -9.930625E-06
Yes, it is a Double! now how can I have a point to do for example:
Point[] ptarray = new Point[3];
ptarray[0] = new Point(250, 250);
Is there an alternative to Point[] that accepts double values? I have a 500x500 picture box. is there a way to convert those values to valid points that can still save precesion? I am wotking with micro Ampers (10^-6) and Voltages!
The Convert. ToDouble() method in C# converts the specified string representation of a number to an equivalent double-precision floating-point number, using the specified culture-specific formatting information.
floatValue() to Convert Double to Float in Java. Another way to convert a double value into a float data type in Java is by using the wrapper class Double. This class wraps a primitive data type double in an object.
String value can be converted to double using Convert. ToDouble() or Double. Parse() method. These methods take string representation of a number as input and return its equivalent double-precision floating-point number.
Well, if float
is enough precision, then you can use the PointF
struct:
var point = new PointF(3.5f, 7.9f);
If you really need to, you can define your own PointD
struct:
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);
}
}
Equality code originally from here.
The ToPoint()
method lets you convert it to a Point
object, though of course the precision will be truncated.
If it's just for storing these values there's always Tuple
:
Tuple<double, double>[] Points = new Tuple<double, double>[50];
Points[0] = Tuple.Create<double, double>(5.33, 12.45);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With