Reputation: 13
In Java, I have the following code snippet:
public static double absoluteBearing(Point2D.Double source, Point2D.Double target) {
return Math.atan2(target.x - source.x, target.y - source.y);
}
I would like to know how to work with "Point2D.Double" in C #.
Upvotes: 1
Views: 2421
Reputation:
If you use WPF then you can get a double-precision Point
which much more closely matches the original Java Point2D.Double
.
public static double absoluteBearing(Point source, Point target)
{
return Math.atan2(target.X - source.X, target.Y - source.Y);
}
This does not necessarily mean your app has to be converted to WPF.
Upvotes: 0
Reputation: 14153
In Windows Forms, you can use the PointF
struct. (Note, that this uses a float
internally as the name suggests, but is usually enough precision.)
In WPF, you can use the Point
struct.
Assuming you are using WinForms (As it is most similar to Swing in Java), your code would translate to:
public static double absoluteBearing(PointF source, PointF target) {
return Math.Atan2(target.Y - source.Y, target.X - source.X);
}
Note that X and Y are inverted in C#'s Atan2
.
Upvotes: 2