-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdistance.go
57 lines (44 loc) · 1.84 KB
/
distance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package govec
import (
"math"
)
// V2F
// Distance returns the norm of the difference between the two vectors.
func (v V2F[T]) Distance(v2 V2F[T]) float64 {
return math.Sqrt(float64((v.X-v2.X)*(v.X-v2.X) + (v.Y-v2.Y)*(v.Y-v2.Y)))
}
// DistanceComp returns the norm of the difference between
// the specified vector and the vector V2F[T]{X: x, Y: y}.
func (v V2F[T]) DistanceComp(x T, y T) float64 {
return math.Sqrt(float64((v.X-x)*(v.X-x) + (v.Y-y)*(v.Y-y)))
}
// V3F
// Distance returns the norm of the difference between the two vectors.
func (v V3F[T]) Distance(v2 V3F[T]) float64 {
return math.Sqrt(float64((v.X-v2.X)*(v.X-v2.X) + (v.Y-v2.Y)*(v.Y-v2.Y) + (v.Z-v2.Z)*(v.Z-v2.Z)))
}
// DistanceComp returns the norm of the difference between
// the specified vector and the vector V3F[T]{X: x, Y: y, z: Z}.
func (v V3F[T]) DistanceComp(x T, y T, z T) float64 {
return math.Sqrt(float64((v.X-x)*(v.X-x) + (v.Y-y)*(v.Y-y) + (v.Z-z)*(v.Z-z)))
}
// V2I
// Distance returns the norm of the difference between the two vectors.
func (v V2I[T]) Distance(v2 V2I[T]) float64 {
return math.Sqrt(float64((v.X-v2.X)*(v.X-v2.X) + (v.Y-v2.Y)*(v.Y-v2.Y)))
}
// DistanceComp returns the norm of the difference between
// the specified vector and the vector V2I[T]{X: x, Y: y}.
func (v V2I[T]) DistanceComp(x T, y T) float64 {
return math.Sqrt(float64((v.X-x)*(v.X-x) + (v.Y-y)*(v.Y-y)))
}
// V3I
// Distance returns the norm of the difference between the two vectors.
func (v V3I[T]) Distance(v2 V3I[T]) float64 {
return math.Sqrt(float64((v.X-v2.X)*(v.X-v2.X) + (v.Y-v2.Y)*(v.Y-v2.Y) + (v.Z-v2.Z)*(v.Z-v2.Z)))
}
// DistanceComp returns the norm of the difference between
// the specified vector and the vector V3I[T]{X: x, Y: y, Z: z}.
func (v V3I[T]) DistanceComp(x T, y T, z T) float64 {
return math.Sqrt(float64((v.X-x)*(v.X-x) + (v.Y-y)*(v.Y-y) + (v.Z-z)*(v.Z-z)))
}