()
| 10 | } |
| 11 | |
| 12 | func 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 | |
| 24 | func (a Vector) Length() float64 { |
| 25 | return math.Sqrt(a.X*a.X + a.Y*a.Y + a.Z*a.Z) |