How to calculate the Euclidean distance between two points in VB.NET

1 Answer

0 votes
' The Euclidean distance is a measure of the straight-line distance 
' between two points in a 2D or 3D space

Imports System

Class EuclideanDistance
    Private Shared Function CalculateEuclideanDistance(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double) As Double
        Return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2))
    End Function

    Public Shared Sub Main()
        Dim x1 As Double = 3.0, y1 As Double = 4.0
        Dim x2 As Double = 5.0, y2 As Double = 9.0
		
        Dim distance As Double = CalculateEuclideanDistance(x1, y1, x2, y2)
		
        Console.WriteLine($"Euclidean Distance: {distance}")
    End Sub
End Class



' run:
'
' Euclidean Distance: 5.385164807134504
'

 



answered Oct 12, 2025 by avibootz
edited Oct 13, 2025 by avibootz
...