我想检查两组坐标是否相近。我看过这个答案,它建议使用勾股定理计算两点之间的距离。
我要比较的两组坐标是鼠标当前位置和变量
变量
我正在使用
我要比较的两组坐标是鼠标当前位置和变量
point
下预设的坐标。if(Math.Sqrt(Math.Pow(point.X - this.PointToClient(Cursor.Position.X), 2) + Math.Pow(point.Y - this.PointToClient(Cursor.Position.Y), 2) < 50))
{
Console.WriteLine("Distance between the points is less than 50");
}
变量
point
具有点(point)数据类型。我正在使用
this.PointToClient(Cursor.Position)
而不是Cursor.Position
,因为我想获取相对于窗体的坐标,而不是相对于屏幕。然而,使用此方法会出现以下错误:
无法从
int
转换为System.Drawing.Point
无法将布尔值转换为双精度浮点数
。 - The Codesee<50
也放错位置了,请看我的修改。 - Dmitry Bychenko