(r Ray)
| 30 | } |
| 31 | |
| 32 | func (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 | |
| 52 | func (s *Sphere) Paths4() Paths { |
| 53 | var paths Paths |