GE Lua Documentation

Press F to search!

cardinalSpline

Definition


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

--MARK: curves

function cardinalSpline(p0, p1, p2, p3, t, s, d1, d2, d3)
  d1, d2, d3 = max(d1 or 1, 1e-30), d2 or 1, max(d3 or 1, 1e-30)
  s = (s or 0.5) * 2
  local sd2, tt, t_1 = s*d2, t*t, t-1
  local t_1sq, c21 = t_1 * t_1, s*t_1*(t*t_1 + tt)
  local m1c, m2c = t*t_1sq*sd2, tt*t_1*sd2
  return (p1 - p0) * (m1c/d1) + (p0 - p2) * (m1c/(d1 + d2))
    + (p1 - p3) * (m2c/(d2 + d3)) + (p3 - p2) * (m2c/d3)
    + (t_1sq*(2*t+1)-c21) * p1 + (c21-tt*(2*t-3)) * p2
end

Callers

@/lua/common/mathlib.lua
function catmullRom(p0, p1, p2, p3, t, s)
  return cardinalSpline(p0, p1, p2, p3, t, s or 0.5, 1, 1, 1)
end
function catmullRomChordal(p0, p1, p2, p3, t, s)
  return cardinalSpline(p0, p1, p2, p3, t, s or 0.5, p0:distance(p1), p1:distance(p2), p2:distance(p3))
end
function catmullRomCentripetal(p0, p1, p2, p3, t, s)
  return cardinalSpline(p0, p1, p2, p3, t, s or 0.5, sqrt(p0:distance(p1)), sqrt(p1:distance(p2)), sqrt(p2:distance(p3)))
end