tags:

views:

283

answers:

4

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!

+2  A: 

Distance formula: sqrt( (x2 - x1)^2 + (y2 - y1)^2 )

hypoxide
thanks! that's what I needed
And high school students wonder when they are EVER going to need such information.
robber.baron
A: 

Pseudocode:

SquareRoot(Square(p1.x - p2.x)+Square(p1.y-p2.y))
Tetsujin no Oni
+1  A: 

If you want to know where the formula that people are giving you comes from, this is generalized as The Pythagorean theorem.

Chad Birch
A: 
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);
Tom