the dx2 and dy2 may be wrong, d/dx of cos = - sin you have + sin
also check num_points as the cast to int might drop precision, or have other issues when it rounds up and down.
is "duration" defined in scope? as it is not listed on this page?
check your parametric equation and that your trig identities are correct.
best luck