function C = lp_curve(a, nlobe, t) % LP_CURVE A smooth closed curve and its first two derivatives. % % r(t) = 1 + a cos(nlobe t), x = r cos t, y = r sin t % % Returned as one matrix with columns [x y x' y' x'' y''] rather than as six % outputs, because the drivers call this from inside timing loops and numbl % compiles a multiple-output call in a loop through its slow path. % % The curve is analytic and traversed counterclockwise, which is what makes the % trapezoid rule spectrally accurate on it and fixes the sign of the outward % normal (y', -x')/|(x', y')|. t = t(:); r = 1 + a * cos(nlobe * t); rp = -a * nlobe * sin(nlobe * t); rpp = -a * nlobe^2 * cos(nlobe * t); c = cos(t); s = sin(t); C = [r .* c, ... r .* s, ... rp .* c - r .* s, ... rp .* s + r .* c, ... rpp .* c - 2*rp .* s - r .* c, ... rpp .* s + 2*rp .* c - r .* s]; end