Parametrization of a curve
That is basically the same technique that I would use.

My only suggestion is to consistently use

for (i = 1; i &lt;= n; i++)


for both loops, to match the stated definition.