Note
Go to the end to download the full example code.
Constraining a conic to a parabola¶
A conic fitted using the direct linear transform (DLT) is not guaranteed to be of a specific type. This example conditions a DLT-fitted conic to be a parabola and compares the result against a parabola fitted directly using the Nievergelt method.
from conics.fitting import fit_dlt
from conics.fitting import fit_nievergelt
import matplotlib.pyplot as plt
import numpy as np
x = [-1, -0.5, 0, 0.5, 1, 0.5, 0, -0.5]
y = [0, +0.5, 1, 0.5, 1, -0.5, -1, -0.5]
pts = np.column_stack((x, y))
C1 = fit_dlt(pts)
C2 = C1.constrain(pts)
C3 = fit_nievergelt(pts)
X, Y = np.meshgrid(
np.linspace(np.min(x) - 1, np.max(x) + 1),
np.linspace(-1 + np.min(y), np.max(y) + 1),
)
Z1 = C1(np.dstack([X, Y]))
Z2 = C2(np.dstack([X, Y]))
Z3 = C3(np.dstack([X, Y]))
plt.figure()
plt.contour(X, Y, Z1, levels=0)
plt.contour(X, Y, Z2, levels=0)
plt.contour(X, Y, Z3, levels=0)
plt.scatter(*pts.T)
plt.show()
Total running time of the script: (0 minutes 0.180 seconds)