lib/ruby_on_rays/shapes/sphere.rb
# Returns true if there is an intersection between the ray and the sphere.
# @param ray [Ray3]
# @return [Boolean]
Returns true if there is an intersection between the ray and the sphere.
Returns true if there is an intersection between the ray and the sphere .
def intersection?(ray)
      a = ray.d.dot(ray.d)
      b = 2.0 * ray.d.dot(ray.o.sub(@c))
      c = @c2 - 2.0 * @c.dot(ray.o) - @r2
      d2 = b**2 - 4 * a * c
      return false unless d2 > 0
      t0 = (-b - Math.sqrt(d2)) / (2 * a)
      t1 = (-b + Math.sqrt(d2)) / (2 * a)
      t0, t1 = t1, t0 if t0 > t1
      return false if t1 < ray.tmin || t0 > ray.tmax
      t_hit = t0
      if t_hit < ray.tmin
        t_hit = t1
        return false if t_hit > ray.tmax
      end
      true
    end
def intersection? ( ray ) a = ray . d . dot ( ray . d ) b = 2.0 * ray . d . dot ( ray . o . sub ( @c ) ) c = @c2 - 2.0 * @c . dot ( ray . o ) - @r2 d2 = b ** 2 - 4 * a * c return false unless d2 > 0 t0 = ( - b - Math . sqrt ( d2 ) ) / ( 2 * a ) t1 = ( - b + Math . sqrt ( d2 ) ) / ( 2 * a ) t0 , t1 = t1 , t0 if t0 > t1 return false if t1 < ray . tmin || t0 > ray . tmax t_hit = t0 if t_hit < ray . tmin t_hit = t1 return false if t_hit > ray . tmax end true end
Returns true if there is an intersection between the ray and the sphere.
Returns true if there is an intersection between the ray and the sphere .
None
Boolean
ray
<not_specific>
<not_specific>
None