VE Lua Documentation

Press F to search!

intersectsRay_Ellipsoid

Definition


-- @/lua/common/mathlib.lua:1451

function intersectsRay_Ellipsoid(rpos, rdir, c1, x1, y1, z1)
  local invx1, invy1, invz1 = 1 / (x1:squaredLength() + 1e-30), 1 / (y1:squaredLength() + 1e-30), 1 / (z1:squaredLength() + 1e-30)
  tmpv1:setSub2(rpos, c1)
  local pM = vec3(tmpv1:dot(x1)*invx1, tmpv1:dot(y1)*invy1, tmpv1:dot(z1)*invz1)
  local dirM = vec3(rdir:dot(x1)*invx1, rdir:dot(y1)*invy1, rdir:dot(z1)*invz1)

  local a, b, c = dirM:squaredLength(), 2*pM:dot(dirM), pM:squaredLength() - 1
  local d = b*b - 4*a*c
  if d < 0 then return math.huge, math.huge end
  d = -b -sign(b)*sqrt(d)
  local r1, r2 = 0.5*d / a, 2*c / d
  return min(r1, r2), max(r1,r2)
end

Callers