且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

计算两点之间的距离

更新时间:2022-01-17 00:05:13

要计算距离,您必须应用以下函数:
to calculate distance you must apply such this function :
public int Distance2D(int x1, int y1, int x2, int y2)
       {
           //     ______________________
           //d = √ (x2-x1)^2 + (y2-y1)^2
           //

           //Our end result
           int result = 0;
           //Take x2-x1, then square it
           double part1 = Math.Pow((x2 - x1), 2);
           //Take y2-y1, then sqaure it
           double part2 = Math.Pow((y2 - y1), 2);
           //Add both of the parts together
           double underRadical = part1 + part2;
           //Get the square root of the parts
           result = (int)Math.Sqrt(underRadical);
           //Return our result
           return result;
       }


两点之间的距离很容易:这是毕达哥拉斯定理:
dist =平方根(平方(Diff(X1,X2))+平方(Diff(Y1,Y2)))

比率也很容易:彼此除以.

找到要点?交给您-这要困难得多!
看看其中的一些: [
Distance between two points is easy: it''s Pythagorus''s theorem:
dist = Square Root(Square(Diff(X1, X2)) + Square(Diff(Y1, Y2)))

Ratio is also easy: divide one by the other.

Finding the points? Over to you - it''s a lot harder!
Have a look at some of these: Google: "Face Recognition Codeproject"[^]