The code below classifies conic sections, given the coefficients $A, B, C, D, E$ and $F$ on the command line.
import sys
import numpy as np
def classify_conic(A, B, C, D, E, F):
Q = np.array( ((A, B/2, D/2), (B/2, C, E/2), (D/2, E/2, F)) )
Q = np.matrix(Q)
Q33 = Q[:2,:2]
detQ = np.linalg.det(Q)
detQ33 = np.linalg.det(Q33)
if detQ == 0:
if detQ33 < 0:
return 'two intersecting lines'
if detQ33 == 0:
return 'two parallel lines'
return 'a single point'
if detQ33 < 0:
return 'a hyperbola'
if detQ33 == 0:
return 'a parabola'
if A == C and B == 0:
return 'a circle'
return 'an ellipse'
A, B, C, D, E, F = [float(arg) for arg in sys.argv[1:]]
print(classify_conic(A, B, C, D, E, F))