sorbetto.geometry package

class sorbetto.geometry.AbstractGeometricObject2D(name=None)[source]

Bases: ABC

abstract draw(fig: Figure, ax: Axes, extent, **plt_kwargs) None[source]
property name: str
class sorbetto.geometry.BilinearCurve(Kxy, Kx, Ky, K, name: str | None = None)[source]

Bases: Conic

This class is used to represent bilinear curves: \(K_{xy} x y + K_x x + K_y y + K = 0\). These are particular cases of conic sections. \(a x^2 + b x y + c y^2 + d x + e y + f = 0\) where \(a=0\), \(b=K_{xy}\), \(c=0\), \(d=K_x\), \(e=K_y\), and \(f=K\).

draw(fig: Figure, ax: Axes, extent, **plt_kwargs)[source]

Draws the part of the bilinear curve that is within some axis-aligned box in some given Pyplot axes.

Parameters:
  • fig (_type_) – a Pyplot Figure object

  • ax (_type_) – a Pyplot Axes object

  • extent (_type_) – the axis-aligned box \((x_{min}, x_{max}, y_{min}, y_{max})\)

  • plt_kwargs – options for Pyplot’s plot command.

getX(y)[source]

Computes the value of \(x\), for any given \(y\).

Parameters:

y (_type_) – \(y\)

Returns:

the value of \(x\), for the given \(y\).

Return type:

_type_

getY(x)[source]

Computes the value of \(y\), for any given \(x\).

Parameters:

x (_type_) – \(x\)

Returns:

the value of \(y\), for the given \(x\).

Return type:

_type_

class sorbetto.geometry.Conic(a, b, c, d, e, f, name: str | None = None)[source]

Bases: AbstractGeometricObject2D

This class is used to represent conic sections. \(a x^2 + b x y + c y^2 + d x + e y + f = 0\) See https://en.wikipedia.org/wiki/Conic_section

property a: float

The coefficient \(a\) that multiplies \(x^2 y^0\) in the equation of the conic section.

Returns:

The paramater \(a\) of the conic section.

Return type:

float

property b: float

The coefficient \(b\) that multiplies \(x^1 y^1\) in the equation of the conic section.

Returns:

The paramater \(b\) of the conic section.

Return type:

float

property c: float

The coefficient \(c\) that multiplies \(x^0 y^2\) in the equation of the conic section.

Returns:

The paramater \(c\) of the conic section.

Return type:

float

classify(tol: float = 1e-08) str[source]

Classify the conic section.

Parameters:

tol (float, optional) – the numerical tolerance, positive. Defaults to 1e-8.

Returns:

a name, in english, for the conic section type

Return type:

str

property d: float

The coefficient \(d\) that multiplies \(x^1 y^0\) in the equation of the conic section.

Returns:

The paramater \(d\) of the conic section.

Return type:

float

draw(fig: Figure, ax: Axes, extent, **plt_kwargs)[source]

Draws the part of the conic section that is within some axis-aligned box in some given Pyplot axes.

Parameters:
  • fig (_type_) – a Pyplot Figure object

  • ax (_type_) – a Pyplot Axes object

  • extent (_type_) – the axis-aligned box \((x_{min}, x_{max}, y_{min}, y_{max})\)

  • plt_kwargs – options for Pyplot’s plot command.

property e: float

The coefficient \(e\) that multiplies \(x^0 y^1\) in the equation of the conic section.

Returns:

The paramater \(e\) of the conic section.

Return type:

float

property f: float

The coefficient \(a\) that multiplies \(x^0 y^0\) in the equation of the conic section.

Returns:

The paramater \(f\) of the conic section.

Return type:

float

getLargestX(y)[source]

Computes the largest value of \(x\), for any given \(y\).

Parameters:

y (_type_) – \(y\)

Returns:

the largest value of \(x\), for the given \(y\).

Return type:

_type_

getLargestY(x)[source]

Computes the largest value of \(y\), for any given \(x\).

Parameters:

x (_type_) – \(x\)

Returns:

the largest value of \(y\), for the given \(x\).

Return type:

_type_

getMatrixRepresentation() ndarray[source]

Computes the 3 by 3 matrix representation of the conic section. See https://en.wikipedia.org/wiki/Matrix_representation_of_conic_sections

Returns:

the matrix representation

Return type:

np.nparray

getSmallestX(y)[source]

Computes the smallest value of \(x\), for any given \(y\).

Parameters:

y (_type_) – \(y\)

Returns:

the smallest value of \(x\), for the given \(y\).

Return type:

_type_

getSmallestY(x)[source]

Computes the smallest value of \(y\), for any given \(x\).

Parameters:

x (_type_) – \(x\)

Returns:

the smallest value of \(y\), for the given \(x\).

Return type:

_type_

isCircle(tol: float = 1e-08) bool[source]

Test if the conic section is a circle.

Parameters:

tol (float, optional) – the numerical tolerance, positive. Defaults to 1e-8.

Returns:

True if the conic section is a circle; False otherwise

Return type:

bool

isDegenerate(tol: float = 1e-08) bool[source]

See https://en.wikipedia.org/wiki/Degenerate_conic

Parameters:

tol (float, optional) – the numerical tolerance, positive. Defaults to 1e-8.

Returns:

True if the conic section is degenerate; False otherwise

Return type:

bool

isEllipse(tol: float = 1e-08) bool[source]

Test if the conic section is an ellipse.

Parameters:

tol (float, optional) – the numerical tolerance, positive. Defaults to 1e-8.

Returns:

True if the conic section is an ellipse; False otherwise

Return type:

bool

isHyperbola(tol: float = 1e-08) bool[source]

Test if the conic section is a hyperbola.

Parameters:

tol (float, optional) – the numerical tolerance, positive. Defaults to 1e-8.

Returns:

True if the conic section is a hyperbola; False otherwise

Return type:

bool

isParabola(tol: float = 1e-08) bool[source]

Test if the conic section is a parabola.

Parameters:

tol (float, optional) – the numerical tolerance, positive. Defaults to 1e-8.

Returns:

True if the conic section is a parabola; False otherwise

Return type:

bool

isRectangularHyperbola(tol: float = 1e-08) bool[source]

Test if the conic section is a rectangular hyperbola.

Parameters:

tol (float, optional) – the numerical tolerance, positive. Defaults to 1e-8.

Returns:

True if the conic section is a rectangular hyperbola; False otherwise

Return type:

bool

class sorbetto.geometry.Line(a: float, b: float, c: float, name: str | None = None)[source]

Bases: AbstractGeometricObject2D

This class is used to represent a line. \(a x + b y + c = 0\) See https://en.wikipedia.org/wiki/Line_(geometry)

property a: float

The parameter \(a\) of the line \(a x + b y + c = 0\)

Returns:

\(a\)

Return type:

float

property b: float

The parameter \(b\) of the line \(a x + b y + c = 0\)

Returns:

\(b\)

Return type:

float

property c: float

The parameter \(c\) of the line \(a x + b y + c = 0\)

Returns:

\(c\)

Return type:

float

draw(fig: Figure, ax: Axes, extent, **plt_kwargs)[source]

Draws the part of the line that is within some axis-aligned box in some given Pyplot axes.

Parameters:
  • fig (_type_) – a Pyplot Figure object

  • ax (_type_) – a Pyplot Axes object

  • extent (_type_) – the axis-aligned box \((x_{min}, x_{max}, y_{min}, y_{max})\)

  • plt_kwargs – options for Pyplot’s plot command.

getIntersectionWithAxisAlignedBox(extent) LineSegment | Point | None[source]

Computes the intersection of the line with any given axis-aligned box.

Parameters:

extent (_type_) – the axis-aligned box \((x_{min}, x_{max}, y_{min}, y_{max})\)

Returns:

the intersection, or None if there is no intersection.

Return type:

LineSegment | Point | None

getIntersectionWithLine(other: Self) Self | Point | None[source]

Computes the intersection of the line with another one.

Parameters:

other (Self) – the other line

Returns:

the intersection.

Return type:

Self | Point | None

getNormalized() Self[source]

Computes the normalized form of the line, that is \(a' x + b' y + c' = 0\) such that \(a'^2 + b'^2 = 1\) and \((a',b',c') \propto (a,b,c)\).

Returns:

the line \(a' x + b' y + c' = 0\)

Return type:

Line

getX(y) float[source]
getY(x) float[source]
class sorbetto.geometry.LineSegment(p1: Point, p2: Point, name: str | None = None)[source]

Bases: AbstractGeometricObject2D

This class is used to represent line segments. See https://en.wikipedia.org/wiki/Line_segment

draw(fig: Figure, ax: Axes, extent, **plt_kwargs)[source]

Plots the line segment in some given Pyplot axes. TODO: extent is currently ignored.

Parameters:
  • fig (_type_) – a Pyplot Figure object

  • ax (_type_) – a Pyplot Axes object

  • extent (_type_) – the axis-aligned box \((x_{min}, x_{max}, y_{min}, y_{max})\)

  • plt_kwargs – options for Pyplot’s plot command.

property p1: Point

The first endpoint.

Returns:

\(p_1\)

Return type:

Point

property p2: Point

The second endpoint.

Returns:

\(p_2\)

Return type:

Point

class sorbetto.geometry.LinearFractionalTransformation(a: float, b: float, c: float, d: float)[source]

Bases: object

This class is used to represent linear fractional transformations. \(x \mapsto \frac{ a x + b }{ c x + d }\) https://en.wikipedia.org/wiki/Linear_fractional_transformation

property a: float

The coefficient \(a\).

Returns:

The paramater \(a\) of the linear fractional transformation.

Return type:

float

property b: float

The coefficient \(b\).

Returns:

The paramater \(b\) of the linear fractional transformation.

Return type:

float

property c: float

The coefficient \(c\).

Returns:

The paramater \(c\) of the linear fractional transformation.

Return type:

float

property d: float

The coefficient \(d\).

Returns:

The paramater \(d\) of the linear fractional transformation.

Return type:

float

getInverse() Self[source]

Computes the inverse of this linear fractional transformation.

Returns:

the inverse linear fractional transformation

Return type:

Self

class sorbetto.geometry.PencilOfLines(line_1: Line, line_2: Line, name: str | None = None)[source]

Bases: AbstractGeometricObject2D

This class is used to represent pencils of lines. \(\lambda_1 ( a_1 x + b_1 y + c_1 ) + \lambda_2 ( a_2 x + b_2 y + c_2 ) = 0\) See https://en.wikipedia.org/wiki/Pencil_(geometry)

draw(fig: Figure, ax: Axes, extent, **plt_kwargs)[source]

Draws the part of the pencil of lines that is within some axis-aligned box in some given Pyplot axes.

Parameters:
  • fig (_type_) – a Pyplot Figure object

  • ax (_type_) – a Pyplot Axes object

  • extent (_type_) – the axis-aligned box \((x_{min}, x_{max}, y_{min}, y_{max})\)

  • plt_kwargs – options for Pyplot’s plot command.

getLine(lambda_1: float, lambda_2: float) Line[source]

The line corresponding to \((\lambda_1, \lambda_2)\).

Parameters:
  • lambda_1 (float) – the value of \(\lambda_1\)

  • lambda_2 (float) – the value of \(\lambda_2\)

Returns:

the chosen line of the pixel

Return type:

Line

getVertex() Point[source]

Compute the pencil’s vertex.

Returns:

the vertex

Return type:

Point

property line_1: Line

The line corresponding to \((\lambda_1, \lambda_2)=(1, 0)\)

Returns:

\(a_1 x + b_1 y + c_1 = 0\)

Return type:

Line

property line_2: Line

The line corresponding to \((\lambda_1, \lambda_2)=(0, 1)\)

Returns:

\(a_2 x + b_2 y + c_2 = 0\)

Return type:

Line

class sorbetto.geometry.Point(x: float, y: float, name: str | None = None)[source]

Bases: AbstractGeometricObject2D

This class is used to represent points. See https://en.wikipedia.org/wiki/Point_(geometry)

draw(fig: Figure, ax: Axes, extent, **plt_kwargs)[source]

If the point is withing some axis-aligned box, then plots it in some given Pyplot axes.

Parameters:
  • fig (_type_) – a Pyplot Figure object

  • ax (_type_) – a Pyplot Axes object

  • extent (_type_) – the axis-aligned box \((x_{min}, x_{max}, y_{min}, y_{max})\)

  • plt_kwargs – options for Pyplot’s plot command.

property x: float

The first coordinate, \(x\), of the point \((x,y)\).

Returns:

\(x\)

Return type:

float

property y: float

The second coordinate, \(y\), of the point \((x,y)\).

Returns:

\(y\)

Return type:

float

Submodules