Parametrization of a curve For a set of 2D or 3D points \$\{\mathbf P_0, \mathbf P_1,\cdots,\mathbf P_n\}\$, their parameters \$\mathbf T = \{t_0,t_1,\cdots,t_n \}\$ could be computed as follow:

$$\begin{align}
t_0&amp;=0\\
t_i&amp;=\frac{\sum_{j=1}^{i}||\mathbf P_j- \mathbf P_{j-1}||}{\sum_{j=1}^{n}||\mathbf P_j-\mathbf P_{j-1}||} \qquad i=1,2,\cdots,n
\end{align}$$

Here is my C implementation:

/********************************************************************
         v1 = {v1(0),v1(1),...,v1(c-1)}  
         v2 = {v2(0),v2(1),...,v2(c-1)}
     compute the 2-norm of the difference of two vector v1 and v2
*********************************************************************/
double vector_norm(double *v1, double *v2, int c) {
    int i;
    double res = 0.0;
    for (i = 0; i &lt; c; i++) {
        res += pow(v1[i] - v2[i], 2);
    }
    return sqrt(res);
}

/********************************************************
 In general, P is a matrix of dimensions {n + 1, c}
 here, it was saved as a vector
********************************************************/
void calc_paras(double *P, int n, int c, double *paras) {
    int i;
    double len = 0.0;
    double chord;
    //compute the length and total length
    paras[0] = 0.0;
    for (i = 0; i &lt; n; i++) {
        chord = vector_norm(P + (i + 1) * c, P + i * c, c);
        len += chord;
        paras[i+1] = len;
    }
    //normalize the paras to [0,1]
    for (i = 0; i &lt;= n; i++) {
        paras[i] /= len;
    }
}


Is a more efficient C implemetation of calc_paras() possible?
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.