Reference
Cline Class
- class cline.Cline(c=0.0, alpha=0j, d=0.0)[source]
Class representing a circle or line in the complex plane using the general equation.
The equation is:
\[cz\bar{z} + \alpha z + \bar{\alpha}\bar{z} + d = 0\]where c and d are real numbers and alpha is complex.
- __init__(c=0.0, alpha=0j, d=0.0)[source]
Initialize a cline with its equation parameters.
- Parameters:
c (float) – Real coefficient of \(z\bar{z}\)
alpha (complex) – Complex coefficient of z
d (float) – Real constant term
- Mathematical Formulation:
A cline is determined by the general equation:
\[cz\bar{z} + \alpha z + \bar{\alpha}\bar{z} + d = 0\]where:
\(c\) and \(d\) are real numbers
\(\alpha\) is a complex number
The discriminant of the cline is defined as:
\[\Delta = |\alpha|^2 - c \cdot d\]Based on the parameters, the cline represents:
A circle if \(\Delta > 0\) and \(c \neq 0\)
A point if \(\Delta = 0\) and \(c \neq 0\)
A line if \(c = 0\)
An invalid geometric object (no solutions) if \(\Delta < 0\) and \(c \neq 0\)
For a circle (\(\Delta > 0\) and \(c \neq 0\)):
Center: \(z_0 = -\frac{\alpha}{c} = -\frac{\text{Re}(\alpha) + i\cdot\text{Im}(\alpha)}{c}\)
Radius: \(r = \frac{\sqrt{\Delta}}{|c|} = \frac{\sqrt{|\alpha|^2 - c \cdot d}}{|c|}\)
For a point (\(\Delta = 0\) and \(c \neq 0\)):
Point location: \(z_0 = -\frac{\alpha}{c}\)
For a line (\(c = 0\)):
Normal vector: \(\alpha = a + bi\)
Direction vector: \(v = b - ai\) (perpendicular to normal)
Cartesian form: \(ax - by + \frac{d}{2} = 0\)
Distance from origin: \(\frac{|d|}{2|\alpha|}\)
Parametric form: \(z(t) = z_0 + t \cdot v\) where \(z_0\) is a point on the line
- Algorithm:
Calculate the discriminant \(\Delta = |\alpha|^2 - c \cdot d\)
Determine the type of cline: * If \(|c| < \epsilon\) (near zero): Line * If \(|c| \geq \epsilon\) and \(\Delta > \epsilon\): Circle * If \(|c| \geq \epsilon\) and \(|\Delta| < \epsilon\): Point * If \(|c| \geq \epsilon\) and \(\Delta < -\epsilon\): Invalid object
For a circle, calculate: * Center: \(z_0 = -\frac{\text{Re}(\alpha)}{c} - i\frac{\text{Im}(\alpha)}{c}\) * Radius: \(r = \frac{\sqrt{\Delta}}{|c|}\)
For a point, calculate: * Point location: same as circle center
For a line, calculate: * Normal vector: \(\alpha\) * Direction vector: \(v = \text{Im}(\alpha) - i \cdot \text{Re}(\alpha)\) * Distance from origin: \(\frac{|d|}{2|\alpha|}\) * A point on the line by setting either x=0 or y=0 in the Cartesian form
- __repr__()[source]
Return a string representation for debugging.
- __str__()[source]
Return a string representation of the cline.
- classmethod from_circle(center, radius)[source]
Construct a cline representing a circle with specified center and radius.
- Parameters:
center (complex or tuple) – Center of the circle,
tuple (either complex number or)
radius (float) – Radius of the circle (must be positive)
- Returns:
A cline representing the circle with given center and radius
- Return type:
Cline
- For a circle, we set \(c = 1\), and the parameters are calculated as:
\(\alpha = -\text{center}\)
\(d = |\text{center}|^2 - \text{radius}^2\)
- classmethod from_line(z0, z1)[source]
Construct a cline representing a line through two points.
- Parameters:
z0 (complex or tuple) – First point, either complex number or tuple (real, imag)
z1 (complex or tuple) – Second point, either complex number or tuple (real, imag)
- Returns:
A cline representing the line through z0 and z1
- Return type:
Cline
- For a line, we set \(c = 0\), and the parameters are calculated as:
\(\alpha = i \cdot (z_1 - z_0)\) (perpendicular to the line direction)
\(d = -2 \cdot \text{Re}(\alpha \cdot z_0)\)
- classmethod from_three_points(z0, z1, z2)[source]
Construct a cline from three points in the complex plane.
- Parameters:
z0 (complex or tuple) – First point, either complex number or tuple (real, imag)
z1 (complex or tuple) – Second point, either complex number or tuple (real, imag)
z2 (complex or tuple) – Third point, either complex number or tuple (real, imag)
- Returns:
A cline passing through the three points
- Return type:
Cline
- Mathematical Derivation:
Substituting three points into the general cline equation:
\[c|z|^2 + \alpha z + \bar{\alpha}\bar{z} + d = 0\]For each point \(z_i\), we get:
\[c|z_i|^2 + \alpha z_i + \bar{\alpha}\bar{z_i} + d = 0, \qquad i=0,1,2.\]With three points, we have three equations with four unknowns (\(c\), \(\alpha = \alpha_1+i*\alpha_2\), and \(d\)).
We know already that the case \(c=0\) represents a line, so when the three points are collinear we can set c=0 and solve for the rest. Otherwise since the equation is overdetermined, we can set \(c=1\) and solve for the circle case.
To determine which value of \(c\) to use, we check if the points are collinear:
When the points are collinear:
Set \(c=0\) (representing a line)
Calculate \(\alpha = i(z_1 - z_0)\) perpendicular to the line direction
Solve for \(d = -2\text{Re}(\alpha z_0)\)
When the points are not collinear:
Set \(c=1\) (representing a circle)
Solve a system of linear equations for the remaining parameters
To check collinearity, we compute:
\[\text{Im}\left(\frac{z_2 - z_0}{z_1 - z_0}\right) = 0\]When the points are not collinear, we set \(c=1\) and solve a system of linear equations. We can subtract the equation for \(z_0\) from the equations for \(z_1\) and \(z_2\):
\[\begin{split}c(|z_1|^2 - |z_0|^2) + \alpha(z_1 - z_0) + \bar{\alpha}(\bar{z_1} - \bar{z_0}) &= 0 \\ c(|z_2|^2 - |z_0|^2) + \alpha(z_2 - z_0) + \bar{\alpha}(\bar{z_2} - \bar{z_0}) &= 0\end{split}\]With \(c=1\), \(\Delta_1 = z_1 - z_0\), \(\Delta_2 = z_2 - z_0\), \(S_1 = |z_1|^2 - |z_0|^2\), and \(S_2 = |z_2|^2 - |z_0|^2\), we get:
\[\begin{split}S_1 + \alpha\Delta_1 + \bar{\alpha}\bar{\Delta_1} &= 0 \\ S_2 + \alpha\Delta_2 + \bar{\alpha}\bar{\Delta_2} &= 0\end{split}\]This can be rewritten as:
\[\begin{split}S_1 + 2\text{Re}(\alpha\Delta_1) &= 0 \\ S_2 + 2\text{Re}(\alpha\Delta_2) &= 0\end{split}\]Leading to:
\[\begin{split}\text{Re}(\alpha\Delta_1) &= -\frac{S_1}{2} \\ \text{Re}(\alpha\Delta_2) &= -\frac{S_2}{2}\end{split}\]Expanding \(\alpha = a + bi\) and \(\Delta_j = x_j + y_j i\), we get:
\[\begin{split}a x_1 - b y_1 &= -\frac{S_1}{2} \\ a x_2 - b y_2 &= -\frac{S_2}{2}\end{split}\]This 2×2 system is solved for \(a\) and \(b\) to find \(\alpha\). Finally, we compute \(d\) using the original equation and the value of \(z_0\).
- Algorithm:
Check if the points are collinear by testing \(\text{Im}((z_2 - z_0)/(z_1 - z_0)) = 0\)
If collinear:
Set \(c = 0\)
Calculate \(\alpha = i(z_1 - z_0)\)
Calculate \(d = -2\text{Re}(\alpha z_0)\)
If not collinear:
Set \(c = 1\)
Calculate \(\Delta_1 = z_1 - z_0, \Delta_2 = z_2 - z_0\)
Calculate \(S_1 = |z_1|^2 - |z_0|^2, S_2 = |z_2|^2 - |z_0|^2\)
Calculate \(\alpha\) by solving the linear system:
\[\begin{split}\begin{pmatrix} \text{Re}(\Delta_1) & -\text{Im}(\Delta_1) \\ \text{Re}(\Delta_2) & -\text{Im}(\Delta_2) \end{pmatrix} \begin{pmatrix} \text{Re}(\alpha) \\ \text{Im}(\alpha) \end{pmatrix} = \begin{pmatrix} -S_1/2 \\ -S_2/2 \end{pmatrix}\end{split}\]The solution is:
\[\begin{split}\begin{pmatrix} \text{Re}(\alpha) \\ \text{Im}(\alpha) \end{pmatrix} = \begin{pmatrix} \text{Re}(\Delta_1) & -\text{Im}(\Delta_1) \\ \text{Re}(\Delta_2) & -\text{Im}(\Delta_2) \end{pmatrix}^{-1} \begin{pmatrix} -S_1/2 \\ -S_2/2 \end{pmatrix}\end{split}\]Calculate \(d = -(|z_0|^2 + 2\text{Re}(\alpha z_0))\)
- plot(ax=None, figsize=(8, 8), xlim=None, ylim=None, color='blue', point_color='red', label=None, show_points=True, num_points=100, precision=4, **kwargs)[source]
Plot the cline in the complex plane.
- Parameters:
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, a new figure is created.
figsize (tuple, optional) – Figure size if creating a new figure. Defaults to (8, 8).
xlim (tuple, optional) – x-axis limits. If None, automatically calculated.
ylim (tuple, optional) – y-axis limits. If None, automatically calculated.
color (str, optional) – Color of the cline. Defaults to ‘blue’.
point_color (str, optional) – Color of the points. Defaults to ‘red’.
label (str, optional) – Label for the cline in the legend. Defaults to None.
show_points (bool, optional) – Whether to show the points used to create the cline. Defaults to True.
num_points (int, optional) – Number of points to use when plotting a circle. Defaults to 100.
precision (int, optional) – Number of decimal places to round to. Defaults to 4.
**kwargs – Additional keyword arguments passed to the plot function.
- Returns:
The axes containing the plot.
- Return type:
matplotlib.axes.Axes