Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distance between 2 System.Drawing.Point

Tags:

math

distance

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 Answers

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

like image 67
Daniel Avatar answered Jan 31 '26 18:01

Daniel


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);
like image 27
Tom Avatar answered Jan 31 '26 17:01

Tom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!