aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vec3d.go14
1 files changed, 13 insertions, 1 deletions
diff --git a/vec3d.go b/vec3d.go
index a94ebbd..fcf5b1c 100644
--- a/vec3d.go
+++ b/vec3d.go
@@ -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
+ }
+ }
+}