52 double sum_curr = 0, sum_next = 0;
54 double *distances =
lwalloc(npoints *
sizeof(
double));
58 for (iter = 0; iter < max_iter; iter++)
64 for (i = 0; i < npoints; i++)
67 if (distances[i] > DBL_EPSILON)
69 next.
x += points[i].
x / distances[i];
70 next.
y += points[i].
y / distances[i];
71 next.
z += points[i].
z / distances[i];
72 denom += 1.0 / distances[i];
80 if (denom < DBL_EPSILON)
107 double dx = 0, dy = 0, dz = 0;
111 for (i = 0; i < npoints; i++)
113 if (distances[i] > DBL_EPSILON)
115 dx += (points[i].
x - curr->
x) / distances[i];
116 dy += (points[i].
y - curr->
y) / distances[i];
117 dz += (points[i].
z - curr->
z) / distances[i];
121 d_sqr = sqrt(dx*dx + dy*dy + dz*dz);
122 if (d_sqr > DBL_EPSILON)
124 double r_inv =
FP_MAX(0, 1.0 / d_sqr);
125 next.
x = (1.0 - r_inv)*next.
x + r_inv*curr->
x;
126 next.
y = (1.0 - r_inv)*next.
y + r_inv*curr->
y;
127 next.
z = (1.0 - r_inv)*next.
z + r_inv*curr->
z;
133 delta = sum_curr - sum_next;
void * lwalloc(size_t size)
#define LW_TRUE
Return types for functions with status returns.