diff options
| author | Martin Lehoux <martin@lehoux.net> | 2020-04-04 15:30:25 -0700 |
|---|---|---|
| committer | Martin Lehoux <martin@lehoux.net> | 2020-04-04 15:30:25 -0700 |
| commit | 19124e8c21b86dccb9e9d874c614aacb05c0fd4a (patch) | |
| tree | dfa93ca17be594f1e12f375918c3a85203ffebab /hitable.go | |
| parent | 4fbf7c999dd9aabd19a8b66d32461ad4c2722dc3 (diff) | |
feat - Display sphere
Diffstat (limited to 'hitable.go')
| -rw-r--r-- | hitable.go | 19 |
1 files changed, 19 insertions, 0 deletions
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 +} |
