When fitting a curve into another, the following line is called:
error = np.dot(np.moveaxis(ctrlpoints, 0, -1), np.dot(materror, ctrlpoints))
Basically it's equivalent to
$$\text{error} = C^T \cdot \left[M\right] \cdot C = \sum_i \sum_j C_{i} \cdot M_{ij} \cdot C_{j}$$
This line supposes the control points are numpy.ndarray instances to move the first axis to the last one.
It works well when C has a shape of (n, ) or (n, m), but it breaks for custom control points that supports only linear operations:
- Adding two points: $C_0 + C_1$
- Multiplication by scalar: $a \cdot C_0$
The correction is to compute
$$\text{error} = \sum_i \sum_j M_{ij} \langle C_{i}, C_{j} \rangle$$
In python, it would be translated to:
error = sum(sum(matval * (pi @ pj)
for matval, pj in zip(line, ctrlpoints))
for line, pj in zip(materror, ctrlpoints))
When fitting a curve into another, the following line is called:
Basically it's equivalent to
This line supposes the control points are
numpy.ndarrayinstances to move the first axis to the last one.It works well when
Chas a shape of(n, )or(n, m), but it breaks for custom control points that supports only linear operations:The correction is to compute
In python, it would be translated to: