gpt4 book ai didi

c# - 确定两点是否接近

转载 作者:太空狗 更新时间:2023-10-29 22:05:13 27 4
gpt4 key购买 nike

我有以下内容:

bool AreNear(Point Old, Point Current)
{
int x1 = Convert.ToInt32(Old.X);
int x2 = Convert.ToInt32(Current.X);
int y1 = Convert.ToInt32(Old.Y);
int y2 = Convert.ToInt32(Current.Y);
if (x1 == x2) {
if (y1 == y2) {
return true;
}
}
return false;
}

如果当前点在旧点的 25 像素半径内,我想在函数中返回 true。谁能告诉我该怎么做?

最佳答案

您可以使用 the Pythagorean formula来计算两点之间的距离。在 C# 中:

var d = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2)) 

为什么会这样?看看下图,记住 a^2 + b^2 = c^2 对直角三角形成立:

Pythagoras

关于c# - 确定两点是否接近,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13032331/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com