MCPcopy
hub / github.com/fogleman/ln / RandomUnitVector

Function RandomUnitVector

ln/vector.go:12–22  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10}
11
12func RandomUnitVector() Vector {
13 for {
14 x := rand.Float64()*2 - 1
15 y := rand.Float64()*2 - 1
16 z := rand.Float64()*2 - 1
17 if x*x+y*y+z*z > 1 {
18 continue
19 }
20 return Vector{x, y, z}.Normalize()
21 }
22}
23
24func (a Vector) Length() float64 {
25 return math.Sqrt(a.X*a.X + a.Y*a.Y + a.Z*a.Z)

Callers 3

Paths4Method · 0.85
Paths3Method · 0.85
Paths2Method · 0.85

Calls 1

NormalizeMethod · 0.80

Tested by

no test coverage detected