geometry#

Library for (numerical) geometry.

This module provides basic geometric primitives—circles, circular arcs, lines, line segments, polylines—and common operations on them (intersection, orientation, bisectors, perpendicular constructs, circle packing helpers, etc.). All coordinates are represented as complex numbers.

Functions

angle_between(z1, z2, z3)

Return the absolute angle at z2 between vectors (z1 - z2) and (z3 - z2) in radians.

antipode(circle, point)

Return the antipodal point: reflection of point through the circle's center.

arc_from_circle_and_points(circle, point1, ...)

Return the circular arc on circle from point1 to point2.

arc_from_diameter(point1, point2)

Return the circular arc determined by the diameter endpoints point1, point2.

bisect(g)

Split a Segment/CircularArc into two equal halves.

bisector(s)

Return the perpendicular bisector line of the segment.

bounding_box(g)

Axis-aligned bounding box for a geometry or iterable of geometries.

circle_through_points(A, B, C)

Return a circle through three non-collinear points A, B, C.

inverse_point_through_circle(circle, point)

Perform inversion of a point with respect to a circle.

is_angle_between(theta1, theta2, theta3)

Check whether angle theta2 lies between theta1 and theta3 on the circle (mod 2π).

middle(g)

Return the geometric center of a segment or arc (or the point if already complex).

orient_arc(g[, start_point, end_point])

From an unoriented arc/segment, return an oriented one so that:

perpendicular_arc(circle, circle1, circle2)

Return the circular arc inside circle that starts at circle ∩ circle1 and ends at circle ∩ circle2, and is perpendicular to all three circles.

perpendicular_arc_through_point(circle, ...)

Return an arc that is:

perpendicular_line(l, p)

Return a line through p perpendicular to line l.

split(g, point)

Split an arc/segment g at point (which must lie on g).

tangent_line(c, p)

Return the line tangent to circle c at point p.

translate(element, displacement)

Translate a geometric element by a complex displacement.

weighted_circle_center_mean(circle1, circle2)

Compute a weighted mean of centers so that intersections scale proportionally.

Classes

BoundingBox([g])

Axis-aligned bounding box (legacy/limited use).

Circle(center, radius)

Representation of a geometric circle in the complex plane.

CircularArc(center, radius, theta1, theta2)

A circular arc defined by a center, radius, and two angles (theta1 → theta2).

Line(A, B)

An infinite line determined by two points A and B.

OrientedCircularArc(center, radius, theta1, ...)

Circular arc with an orientation flag for start/end selection.

PolySegment(points)

A polyline segment defined by a list of complex points.

Segment(A, B)

A finite line segment from A to B.

class Circle(center, radius)#

Bases: object

Representation of a geometric circle in the complex plane.

Parameters:
  • center (complex)

  • radius (float)

center#

The center of the circle (complex number).

radius#

The radius of the circle (float).

length()#

Return the circumference of the circle.

class CircularArc(center, radius, theta1, theta2)#

Bases: Circle

A circular arc defined by a center, radius, and two angles (theta1 → theta2).

angle()#

Angular span of the arc in radians (in [0, 2π)).

length()#

Arc length (radius × angle).

property A#

Start point of the arc.

property B#

End point of the arc.

class Line(A, B)#

Bases: object

An infinite line determined by two points A and B.

parameter_from_point(point)#

For the line T = A + t(B-A), return t such that T = point (if on the line).

static length(self)#

Infinite line has infinite length.

class Segment(A, B)#

Bases: Line

A finite line segment from A to B.

length()#

Length of the segment (|B - A|).

set_orientation(start_point, end_point)#

Set orientation so that A is closer to start_point and B closer to end_point.

shorten(length, side, inplace=False)#

Shorten by length on side ‘A’ or ‘B’.

sample(n)#

Split the segment into n evenly spaced complex points (inclusive).

class BoundingBox(g=None)#

Bases: object

Axis-aligned bounding box (legacy/limited use).

make_square()#

Expand to the larger side to make the box square (centered).

add_padding(units=None, fraction=None)#

Add absolute (units) or proportional (fraction) padding to the box.

class PolySegment(points)#

Bases: object

A polyline segment defined by a list of complex points.

length()#

Total length of the polyline.

sample(n)#

Sample n points along the polyline at (approximately) equal arc-length spacing, including endpoints.

antipode(circle, point)#

Return the antipodal point: reflection of point through the circle’s center.

arc_from_diameter(point1, point2)#

Return the circular arc determined by the diameter endpoints point1, point2.

perpendicular_line(l, p)#

Return a line through p perpendicular to line l.

Parameters:
  • l (Line)

  • p (complex)

bisect(g)#

Split a Segment/CircularArc into two equal halves.

tangent_line(c, p)#

Return the line tangent to circle c at point p.

If p is not on the circle, this returns the line perpendicular to the radius through the center and p.

Parameters:
middle(g)#

Return the geometric center of a segment or arc (or the point if already complex).

Return type:

complex

bisector(s)#

Return the perpendicular bisector line of the segment.

Parameters:

s (Segment)

Return type:

Line

is_angle_between(theta1, theta2, theta3)#

Check whether angle theta2 lies between theta1 and theta3 on the circle (mod 2π).

Parameters:
  • theta1 (float)

  • theta2 (float)

  • theta3 (float)

Return type:

bool

perpendicular_arc_through_point(circle, circle_point, point)#
Return an arc that is:
  • perpendicular to circle at circle_point,

  • starts at circle_point and goes through point,

  • and (if point lies on the circle) is perpendicular there as well.

perpendicular_arc(circle, circle1, circle2)#

Return the circular arc inside circle that starts at circle ∩ circle1 and ends at circle ∩ circle2, and is perpendicular to all three circles.

Circles are given by (center, radius) pairs. The arc is constructed by inverting the midpoint of the endpoints through circle, which yields the center of the perpendicular circle; the shorter arc is returned. If the arc degenerates to a diameter, a segment is returned.

circle_through_points(A, B, C)#

Return a circle through three non-collinear points A, B, C.

weighted_circle_center_mean(circle1, circle2)#

Compute a weighted mean of centers so that intersections scale proportionally.

Parameters:
split(g, point)#

Split an arc/segment g at point (which must lie on g).