From 19124e8c21b86dccb9e9d874c614aacb05c0fd4a Mon Sep 17 00:00:00 2001 From: Martin Lehoux Date: Sat, 4 Apr 2020 15:30:25 -0700 Subject: feat - Display sphere --- hitable.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 hitable.go (limited to 'hitable.go') diff --git a/hitable.go b/hitable.go new file mode 100644 index 0000000..a44026d --- /dev/null +++ b/hitable.go @@ -0,0 +1,19 @@ +package main + +type Hitable interface { + Hit(ray Ray) bool +} + +type Sphere struct { + center Vec3D + radius float64 +} + +func (sphere Sphere) Hit(ray Ray) bool { + oc := SubVec3D(ray.origin, sphere.center) + a := DotProduct(ray.direction, ray.direction) + b := 2.0 * DotProduct(oc, ray.direction) + c := DotProduct(oc, oc) - sphere.radius*sphere.radius + discriminant := b*b - 4*a*c + return discriminant > 0 +} -- cgit v1.3