I have been working with lsq-ellipse package where I get the coordinates of ellipse with the following code below:
from ellipse import LsqEllipse from matplotlib.patches import Ellipse coords_D0 = np.array(coords_D0) reg = LsqEllipse().fit(coords_D0) center_D0, width_D0, height_D0, phi_D0 = reg.as_parameters() print(f'center: {center_D0[0]:.3f}, {center_D0[1]:.3f}') print(f'width: {width_D0:.3f}') print(f'height: {height_D0:.3f}') print(f'phi: {phi_D0:.3f}') However, my coords_D0 variable consists of three coordinates which caused the following error:
ValueError: Received too few samplesGot 3 features, 5 or more required. But, after looking into some packages and online, I found that sympy also can do Ellipse and I understand that you can extract the centre, vradius and hradius from sympy. But, I would like to know how to get the width, height and phi from sympy and will it be the same as the lsq-ellipse package to be used in Ellipse of matplotlib? I use the values from lsq-ellipse package in matplotlib to form the ellipse part and it can be found in the following code line:
Code:
ellipse_D0 = Ellipse(xy=center_D0, width=2*width_D0, height=2*height_D0, angle=np.rad2deg(phi_D0),edgecolor='b', fc='None', lw=2, label='Fit', zorder=2) My coordinates are the following:
coords_D0 = -1.98976 -1.91574 -0.0157721 2.5438 2.00553 -0.628061 # another points coords_D1 = -0.195518 0.0273673 -0.655686 -1.45848 -0.447061 -0.168108 # another points coords_D2 = -2.28529 0.91896 -2.43207 0.446211 -2.23044 0.200087 Side Question:
Is there a way to fit an ellipse to these coordinates (in general, 3 coordinates or more)?

fit. Two crossing ellipses can have 4 points in common, so there is no unique solution giving less than 5. Did you read the docs?LsqEllipse().fit()method takes a list of(x, y)to fit an ellipse. To give a proper unique result, you need 5 or more values. So naturally you get an error.