Geometry helpers

Points, lines and polygon geometry helpers (BOSL2 geometry.scad).

pybosl2.geometry.circle_circle_tangents(radius1=None, center1=None, radius2=None, center2=None, diameter1=None, diameter2=None)[source]

Tangent lines between two circles.

Computes up to four common tangent lines: two external tangents plus, when the circles do not overlap, two internal (crossing) tangents.

Parameters:
radius1 : float | None

Radius of the first circle (mutually exclusive with diameter1).

center1 : Point | None

Centre point of the first circle.

radius2 : float | None

Radius of the second circle (mutually exclusive with diameter2).

center2 : Point | None

Centre point of the second circle.

diameter1 : float | None

Diameter of the first circle.

diameter2 : float | None

Diameter of the second circle.

Returns:

A list of (point_on_circle1, point_on_circle2) Point tuples. Returns up to 4 entries (2 external + 2 internal), 2 entries when only external tangents exist, or an empty list when no tangent can be drawn.

Return type:

list[tuple[Point, Point]]

pybosl2.geometry.general_line_intersection(line1, line2, eps=1e-09)[source]

Intersection point of two infinite lines.

Computes the intersection of the lines through line1 and line2. Returns parametric positions so the caller can check segment bounds.

Parameters:
line1 : tuple[Point, Point]

A (start, end) pair of Point objects.

line2 : tuple[Point, Point]

A (start, end) pair of Point objects.

eps : float

Epsilon for parallel-line detection.

Returns:

(point, t, u) where point is the intersection Point, t and u are the parametric positions along line1 and line2 (0 at the first endpoint, 1 at the second). Returns None for parallel or coincident lines.

Return type:

tuple[Point, float, float] | None

pybosl2.geometry.is_collinear(point1, point2, point3, eps=1e-09)[source]

Return True if three points lie on a common line (works in 2-D or 3-D).

Parameters:
point1 : Point

First point.

point2 : Point

Second point.

point3 : Point

Third point.

eps : float

Epsilon for collinearity tolerance.

Returns:

True if the three points are collinear within eps.

Return type:

bool

pybosl2.geometry.line_closest_point(segment, query_point)[source]

Closest point on a bounded segment to a query point.

Projects query_point onto the infinite line through the segment and then clamps the parameter to the segment’s bounds using numpy.clip().

Parameters:
segment : tuple[Point, Point]

A (start, end) pair of Point objects.

query_point : Point

The point to project onto the segment.

Returns:

The closest point on the segment as an ndarray.

Return type:

NDArray[np.float64]

pybosl2.geometry.line_normal(point1, point2)[source]

Return the unit 2-D normal vector perpendicular to the line direction, pointing left.

Returns a Point of length 2, perpendicular to the line from point1 to point2.

Parameters:
point1 : Point

First endpoint.

point2 : Point

Second endpoint.

Returns:

A unit-length Point normal to the line.

Return type:

Point