MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Distance

Function Distance

math/pythagoras/pythagoras.go:15–18  ·  view source on GitHub ↗

Distance calculates the distance between to vectors with the Pythagoras theorem

(a, b Vector)

Source from the content-addressed store, hash-verified

13
14// Distance calculates the distance between to vectors with the Pythagoras theorem
15func Distance(a, b Vector) float64 {
16 res := math.Pow(b.x-a.x, 2.0) + math.Pow(b.y-a.y, 2.0) + math.Pow(b.z-a.z, 2.0)
17 return math.Sqrt(res)
18}

Callers 1

TestDistanceFunction · 0.70

Calls

no outgoing calls

Tested by 1

TestDistanceFunction · 0.56