API documentation

pygeosolve.constraints module

Constraints.

class pygeosolve.constraints.Constraint(primitives)[source]

Bases: object

A constraint between primitives.

A constraint is defined between one or more Primitive objects. This class defines the interface for concrete constraints to determine their error in the current problem using these primitives.

Parameters
primitivessequence

The primitives associated with this constraint.

abstract error()[source]

The error function for this constraint.

property params

The parameters associated with the points within this constraint.

property points

The points associated with the primitives associated with this constraint.

abstract value()[source]

The current value of the constrained parameter(s).

class pygeosolve.constraints.LineAngleConstraint(line_a, line_b, angle)[source]

Bases: pygeosolve.constraints.Constraint

Constraint on the angle between two lines.

Parameters
line_a, line_bLine

The lines to constrain.

anglefloat

The angle (in degrees) to constrain the lines to.

property angle
error()[source]

The current angle constraint error.

Returns
float

The error.

property line_a
property line_b
value()[source]

The current value of the constrained parameter(s).

class pygeosolve.constraints.LineLengthConstraint(line, length)[source]

Bases: pygeosolve.constraints.Constraint

Constraint on the length of a line.

Parameters
lineLine

The line to constrain.

lengthfloat

The length to constrain the line to.

error()[source]

The current length constraint error.

Returns
float

The error.

property length

The constraint length.

property line
value()[source]

The current value of the constrained parameter(s).

class pygeosolve.constraints.PointToPointDistanceConstraint(point_a, point_b, distance)[source]

Bases: pygeosolve.constraints.Constraint

Constraint on the distance between two points.

Parameters
point_a, point_bPoint

The points to constrain.

distancefloat

The distance to constrain the points’ separation to.

error()[source]

The current distance constraint error.

Returns
float

The error.

property point_a
property point_b

pygeosolve.geometry module

Geometry.

class pygeosolve.geometry.Invalid(primitive, reason)[source]

Bases: object

class pygeosolve.geometry.Line(name, start, end)[source]

Bases: pygeosolve.geometry.Primitive

A line formed between two 2D points in Euclidean space.

Parameters
start, endtuple containg two floats or

points

angle()[source]

The angle of the vector formed by this line translated to the origin.

Returns
float

The angle, in degrees, in the range (-180, 180].

angle_to(other)[source]

The angle to other line with respect to this one.

The angle is defined as the clockwise rotation from the direction of self to get to the direction of other.

Parameters
otherLine

The other line.

Returns
float

The angle, in degrees, in the range (-180, 180].

dx()[source]

The difference between the end and start x-coordinates.

Returns
float

The difference.

dy()[source]

The difference between the end and start y-coordinates.

Returns
float

The difference.

property end
length()[source]

The line length.

Returns
float

The length.

property start
validate()[source]
class pygeosolve.geometry.Point(name, x, y)[source]

Bases: pygeosolve.geometry.Primitive

A 2D point in Euclidean space.

Normally points should not be instantiated directly, but via primitives.

Parameters
namestr

The name of this point.

x, yfloat

The x and y coordinates.

norm()[source]
property x
property y
class pygeosolve.geometry.Primitive(name, points)[source]

Bases: object

A primitive shape.

Parameters
namestr

The name.

pointssequence

The points that make up the primitive.

validate()[source]

pygeosolve.plot module

Plotting.

pygeosolve.plot.pairwise(iterable)[source]
pygeosolve.plot.plot_problem(problem)[source]
pygeosolve.plot.show()[source]

pygeosolve.problem module

Constraint problems.

class pygeosolve.problem.Problem[source]

Bases: object

add_line(*args, **kwargs)[source]
add_point(*args, **kwargs)[source]
constrain_angle_between_lines(line_a, line_b, angle)[source]

Add a constraint on the angle between two lines.

Parameters
line_a, line_bstr

The names of the lines to constrain.

:class:`float`

The angle (in degrees) to target.

constrain_line_length(name, length)[source]

Add a constraint on the length of a line.

Parameters
namestr

The name of the line to constrain.

lengthfloat

The line length to target.

constrain_position(name)[source]

Fix the current position of a primitive.

Parameters
namestr

The name of the primitive to fix.

error()[source]

Calculate the current free parameter values’ total error.

Returns
float

The total error.

property free_params

Free parameter names in this problem.

property free_values
plot(show=True)[source]
property points
solve(**kwargs)[source]

Solve the problem.

This attempts to minimise the error function given the defined constraints. A successful minimisation results in the new, optimised parameter values being assigned.

Returns
scipy.optimize.OptimizeResult

The optimisation result.

Other Parameters
kwargs

Keyword arguments supported by scipy.optimize.basinhopping().

validate()[source]

Validate the problem.

This checks that primitives in the problem are valid, e.g. that lines have nonzero length.

pygeosolve.util module

Utilities.

pygeosolve.util.map_angle_about_zero(angle)[source]

Map angle to be in the range (-180, 180]°.