Distance between 2 System.Drawing.Point
Question
How can I find the distance between 2 System.Drawing.Point?
I googled and didn't find it...
Dim p1 As New Point(0, 10)
Dim p2 As New Point(10, 10)
Dim distance = ??
In this case, it should be 10, but what about here?
Dim p1 As New Point(124, 942)
Dim p2 As New Point(34, 772)
Dim distance = ??
Thanks!
Solution
Distance formula: sqrt( (x2 - x1)^2 + (y2 - y1)^2 )
OTHER TIPS
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);
If you want to know where the formula that people are giving you comes from, this is generalized as The Pythagorean theorem.
Pseudocode:
SquareRoot(Square(p1.x - p2.x)+Square(p1.y-p2.y))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow