2 System.Drawing.Point之间的距离

时间:2009-05-11 19:41:48

标签: math distance

如何找到2 System.Drawing.Point?

之间的距离

我用Google搜索并没有找到它......

Dim p1 As New Point(0, 10)
Dim p2 As New Point(10, 10)
Dim distance = ??

在这种情况下,它应该是10,但是这里呢?

Dim p1 As New Point(124, 942)
Dim p2 As New Point(34, 772)
Dim distance = ??

谢谢!

4 个答案:

答案 0 :(得分:5)

距离公式: sqrt((x2 - x1)^ 2 +(y2 - y1)^ 2)

答案 1 :(得分:3)

Point p1 = new Point(7, 5);
Point p2 = new Point(26, 29);
double distance = Math.Round(Math.Sqrt(Math.Pow((p2.X - p1.X), 2) + Math.Pow((p2.Y - p1.Y), 2)), 1);

答案 2 :(得分:2)

如果您想知道人们给您的公式来自何处,则将其概括为The Pythagorean theorem

答案 3 :(得分:0)

伪代码:

SquareRoot(Square(p1.x - p2.x)+Square(p1.y-p2.y))