MCPcopy
hub / github.com/fogleman/ln / Intersect

Method Intersect

ln/sphere.go:32–50  ·  view source on GitHub ↗
(r Ray)

Source from the content-addressed store, hash-verified

30}
31
32func (s *Sphere) Intersect(r Ray) Hit {
33 radius := s.Radius
34 to := r.Origin.Sub(s.Center)
35 b := to.Dot(r.Direction)
36 c := to.Dot(to) - radius*radius
37 d := b*b - c
38 if d > 0 {
39 d = math.Sqrt(d)
40 t1 := -b - d
41 if t1 > 1e-2 {
42 return Hit{s, t1}
43 }
44 t2 := -b + d
45 if t2 > 1e-2 {
46 return Hit{s, t2}
47 }
48 }
49 return NoHit
50}
51
52func (s *Sphere) Paths4() Paths {
53 var paths Paths

Callers

nothing calls this directly

Calls 2

SubMethod · 0.80
DotMethod · 0.80

Tested by

no test coverage detected