Files
sjy01-image-proc/vendor/github.com/paulmach/orb/planar/distance.go
2024-10-24 15:46:01 +08:00

22 lines
484 B
Go

package planar
import (
"math"
"github.com/paulmach/orb"
)
// Distance returns the distance between two points in 2d euclidean geometry.
func Distance(p1, p2 orb.Point) float64 {
d0 := (p1[0] - p2[0])
d1 := (p1[1] - p2[1])
return math.Sqrt(d0*d0 + d1*d1)
}
// DistanceSquared returns the square of the distance between two points in 2d euclidean geometry.
func DistanceSquared(p1, p2 orb.Point) float64 {
d0 := (p1[0] - p2[0])
d1 := (p1[1] - p2[1])
return d0*d0 + d1*d1
}