To the second question, I am also struggling to follow the step "Let’s move the multiplications by cos β_i into a separate loop".
The recursive construction of `c` doesn't allow the betas to be pulled out. The i-th term is multiplied by beta_i to beta_n, but not beta_0 to beta_{i-1}.
Clearly the method must work, but I'm not sure what I'm missing.
Edit: ignoring `direction`, I can prove this step by induction for both c(i) and s(i) together. At least to me though, this it isn't a simple algebraic simplification.