A Python class to classify, manipulate and visualise conic sections. This class is designed to extend the functionality of polynomial_methods
Conic types are instantiated from a bi-variate polynomial equation by the factory method which is a design pattern in object-oriented programming.
We create objects to represent conic sections without having to specify the type of conic section to create.
In this sense, conic_factory.py
is a classifier of conic sections.
A conic section is a plane algebraic curve of degree two whose coordinates satisfy a quadratic equation in two variables;
with all coefficients
The above equation can be written in matrix notation as
Conic sections described by this equation can be classified in terms of the discriminant
The discriminant is
If the conic is non-degenerate then,
- if
$B^2-4 A C<0$ , the equation represents an ellipse.- if
$A=C$ and$B=0$ , the equation represents a circle, a special case of an ellipse.
- if
- if
$B^2-4 A C=0$ , the equation represents a parabola. - if
$B^2-4 A C>0$ , the equation represents a hyperbola.- if
$\tau=A+C=0$ , the equation represents a rectangular hyperbola.
- if
Conic
takes a string representation of a polynomial expression. Equalities will not be parsed.
For example;
The equation
The equation
Either the ** or ^ operators are accepted for exponentiation. The * operator is required for multiplication.
Parsing relies on the SymPy library to eliminate fractions and multiply the equation by the LCM thus reducing it to the general form of a conic section with integer coefficients.
The poly_dictionary
program then decomposes the equation into a dictionary of the form; {(degree of x, degree of y): coefficient, ...}
mystery_conic = "x^2/4 + x*y/3 + y^2/9 -2*x + 3*y -1"
conic = Conic.create(mystery_conic)
# Type
In [1]: conic.type
Out[1]: Parabola
# Coefficients
In [2]: conic.coeff
Out[2]: {(2, 0): 9, (1, 1): 12, (1, 0): -72, (0, 2): 4, (0, 1): 108, (0, 0): -36}
The input equation represented a parabola and the output dictionary gives the coefficients of the general form equation.
Once a conic object has been instantiated, get_info()
is the first method to call to give an overview of the characteristics along with plot(x_range(min, max), y_range(min, max))
These methods have a common name yet are uniquely defined within each subclass.
get_info()
packages a number of useful methods and returns;
- original input string
self.__repr__()
- type of conic
self.type
- coefficient dictionary
self.coeff
- general form equation
- matrices: full and quadratic
self.print_matrices
- orientation (if applicable)
self.orientation
- axis of symmetry (if applicable)
self.axis
- plot
self.plot
Conic sections can be rotated and translated within the self.print_history()
.
The aim of the transformation is to render the conic to 'standard form' where further attributes can be calculated. Directly calling these attributes is disallowed for a conic not in standard form. The user is directed to first perform a transformation.
Below is a parabola transformed to standard form
Tutorials demonstrating the methods available to each type of conic section are linked below;
Follow these steps to install the Conics
package:
Clone the repository:
git clone https://github.com/pineapple-bois/conic.git
Navigate to the cloned repository:
cd conic
Install the package
pip install .
- Adapting
poly_dictionary
to accept radical coefficients - Additional parameters to the transformation methods to perform arbitrary translation and rotation in
$\mathbb{E}^2$ - Allow scaling and dilation
- Testing is required. I plan to use
unittest
- Writing extensive instruction and documentation
- Eliminating all floating-point error accumulation. Currently, the rotation is performed using the floating point rotation angle in radians albeit to a relatively high precision.
- Two conic objects will be allowed to 'interact' (eventually)