Converting double values ​​to create a point type

I want to draw a curve (diode curve) in a frame using an image from a bitmap. I have a problem right now and my point data is saved as Double, and it is really important to keep precesion.

For example, the point in the graph that I have is as follows:

Voltage: -0.175 Current: -9.930625E-06

Yes, it's Double! now how can i do this for example:

Point[] ptarray = new Point[3]; ptarray[0] = new Point(250, 250); 

Is there an alternative to Point [] that takes double values? I have a 500x500 camera. is there any way to convert these values ​​to real points that precesion can still save? I'm wotking with micro ampers (10 ^ -6) and voltage!

+8
double c # point
source share
2 answers

Well, if the float is high enough precision, you can use PointF struct :

 var point = new PointF(3.5f, 7.9f); 

If you really need to, you can define your own PointD structure:

 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 aX == bX && aY == bY; } public static bool operator !=(PointD a, PointD b) { return !(a == b); } } 

The equality code is from here .

The ToPoint() method allows you to convert it to a Point object, although, of course, the accuracy will be truncated.

+13
source share

If it's easy to save these values, always Tuple :

 Tuple<double, double>[] Points = new Tuple<double, double>[50]; Points[0] = Tuple.Create<double, double>(5.33, 12.45); 
+1
source share

All Articles