diff options
| author | Martin Lehoux <martin@lehoux.net> | 2020-04-04 19:07:33 -0700 |
|---|---|---|
| committer | Martin Lehoux <martin@lehoux.net> | 2020-04-04 19:07:33 -0700 |
| commit | ba7682a761343302fd65f315b0406abc470c482f (patch) | |
| tree | fc801fa01510ed5d9205e0b254147d1366601087 | |
| parent | 3eebd8a349152726808ce83eaec1e83f53eb55e4 (diff) | |
feat - RandomInUnitSphere
| -rw-r--r-- | vec3d.go | 14 |
1 files changed, 13 insertions, 1 deletions
@@ -1,6 +1,9 @@ package main -import "math" +import ( + "math" + "math/rand" +) type Vec3D struct { x, y, z float64 @@ -45,3 +48,12 @@ func CrossProduct(vec1 Vec3D, vec2 Vec3D) Vec3D { vec1.x*vec2.y - vec1.y*vec2.x, } } + +func RandomInUnitSphere() Vec3D { + for { + point := Vec3D{2*rand.Float64() - 1, 2*rand.Float64() - 1, 2*rand.Float64() - 1} + if point.Length() < 1.0 { + return point + } + } +} |
