Java 点2D。C中的双精度#

Java 点2D。C中的双精度#,java,c#,Java,C#,在Java中,我有以下代码片段: public static double absoluteBearing(Point2D.Double source, Point2D.Double target) { return Math.atan2(target.x - source.x, target.y - source.y); } 我想知道如何使用C#中的“Point2D.Double”。在Windows窗体中,可以使用结构。(注意,顾名思义,这在内部使用了一个浮点,但通常足够精确。) 在

在Java中,我有以下代码片段:

public static double absoluteBearing(Point2D.Double source, Point2D.Double target) {
    return Math.atan2(target.x - source.x, target.y - source.y);
}

我想知道如何使用C#中的“Point2D.Double”。在Windows窗体中,可以使用结构。(注意,顾名思义,这在内部使用了一个
浮点
,但通常足够精确。)

在WPF中,可以使用struct

假设您正在使用WinForms(因为它与Java中的Swing最为相似),您的代码将转换为:

public static double absoluteBearing(PointF source, PointF target) {
    return Math.Atan2(target.Y - source.Y, target.X - source.X);
}

请注意,X和Y在C#的
Atan2

中反转,如果使用WPF,则可以得到一个双精度
,该点与原始Java
点2D.double
更接近

public static double absoluteBearing(Point source, Point target) 
{
    return Math.atan2(target.X - source.X, target.Y - source.Y);
}
这并不一定意味着您的应用程序必须转换为WPF


我不是C#专家,但这个问题最好通过搜索一个API来解决,我认为C#的API就是MSDN。可能是链接?当然,但在另一种方法中,我返回一个
Point2D.Double
,如下所示(所有参数都通过Double传递):
返回新的Point2D.Double(loc.x+distance*Math.sin(heading),loc.y+distance*Math.cos(heading))
点F
的参数分别为
int
float
。强制转换类型将是唯一的解决方案?是的,WinForms没有双版本,尽管自己编写一个会很容易。