pylinkage.geometry package
Submodules
pylinkage.geometry.core module
Basic geometry features with numba optimization.
- pylinkage.geometry.core.cyl_to_cart(radius: float, theta: float, ori_x: float = 0.0, ori_y: float = 0.0) tuple[float, float]
Convert polar coordinates into cartesian.
- Parameters:
radius – Distance from origin.
theta – Angle starting from abscissa axis.
ori_x – Origin X coordinate (Default value = 0.0).
ori_y – Origin Y coordinate (Default value = 0.0).
- Returns:
Cartesian coordinates (x, y).
- pylinkage.geometry.core.dist(x1: float, y1: float, x2: float, y2: float) float
Distance between two points.
- Parameters:
x1 – X coordinate of first point.
y1 – Y coordinate of first point.
x2 – X coordinate of second point.
y2 – Y coordinate of second point.
- Returns:
Euclidean distance.
- pylinkage.geometry.core.get_nearest_point(ref_x: float, ref_y: float, p1_x: float, p1_y: float, p2_x: float, p2_y: float) tuple[float, float]
Return the point closer to the reference.
- Parameters:
ref_x – X coordinate of reference point.
ref_y – Y coordinate of reference point.
p1_x – X coordinate of first candidate.
p1_y – Y coordinate of first candidate.
p2_x – X coordinate of second candidate.
p2_y – Y coordinate of second candidate.
- Returns:
Coordinates of the nearest point.
- pylinkage.geometry.core.line_from_points(first_x: float, first_y: float, second_x: float, second_y: float) tuple[float, float, float]
A cartesian equation of the line joining two points.
- Parameters:
first_x – X coordinate of first point.
first_y – Y coordinate of first point.
second_x – X coordinate of second point.
second_y – Y coordinate of second point.
- Returns:
A cartesian equation of this line (a, b, c) where ax + by + c = 0.
- pylinkage.geometry.core.norm(x: float, y: float) float
Return the norm of a 2-dimensional vector.
- Parameters:
x – X component.
y – Y component.
- Returns:
Vector magnitude.
- pylinkage.geometry.core.sqr_dist(x1: float, y1: float, x2: float, y2: float) float
Square of the distance between two points.
Faster than dist when only comparing distances.
- Parameters:
x1 – X coordinate of first point.
y1 – Y coordinate of first point.
x2 – X coordinate of second point.
y2 – Y coordinate of second point.
- Returns:
Squared distance.
pylinkage.geometry.secants module
The geometry module provides general geometry functions.
It is used extensively, so each function is optimized with numba.
- pylinkage.geometry.secants.bounding_box(locus: list[tuple[float, float]]) tuple[float, float, float, float]
Compute the bounding box of a locus.
- Parameters:
locus – A list of points or any iterable with the same structure.
- Returns:
Bounding box as (y_min, x_max, y_max, x_min).
- pylinkage.geometry.secants.circle_intersect(x1: float, y1: float, r1: float, x2: float, y2: float, r2: float, tol: float = 0.0) tuple[int, float, float, float, float]
Get the intersections of two circles.
Transcription of a Matt Woodhead program, method provided by Paul Bourke, 1997. http://paulbourke.net/geometry/circlesphere/.
- Parameters:
x1 – X coordinate of first circle center.
y1 – Y coordinate of first circle center.
r1 – Radius of first circle.
x2 – X coordinate of second circle center.
y2 – Y coordinate of second circle center.
r2 – Radius of second circle.
tol – Distance under which two points are considered equal.
- Returns:
Tuple of (n_intersections, x1, y1, x2, y2) where: - n=0: No intersection (other values undefined) - n=1: One intersection at (x1, y1) - n=2: Two intersections at (x1, y1) and (x2, y2) - n=3: Same circle (x1, y1, x2 are center and radius)
- pylinkage.geometry.secants.circle_line_from_points_intersection(cx: float, cy: float, r: float, p1_x: float, p1_y: float, p2_x: float, p2_y: float) tuple[int, float, float, float, float]
Intersection(s) of a circle and a line defined by two points.
- Parameters:
cx – X coordinate of circle center.
cy – Y coordinate of circle center.
r – Circle radius.
p1_x – X coordinate of first point on line.
p1_y – Y coordinate of first point on line.
p2_x – X coordinate of second point on line.
p2_y – Y coordinate of second point on line.
- Returns:
Tuple of (n_intersections, x1, y1, x2, y2) where: - n=0: No intersection - n=1: One intersection (tangent) at (x1, y1) - n=2: Two intersections at (x1, y1) and (x2, y2)
- pylinkage.geometry.secants.circle_line_intersection(cx: float, cy: float, r: float, a: float, b: float, c: float) tuple[int, float, float, float, float]
Return the intersection between a line and a circle.
From https://mathworld.wolfram.com/Circle-LineIntersection.html
- Parameters:
cx – X coordinate of circle center.
cy – Y coordinate of circle center.
r – Circle radius.
a – Line equation coefficient a (ax + by + c = 0).
b – Line equation coefficient b.
c – Line equation coefficient c.
- Returns:
Tuple of (n_intersections, x1, y1, x2, y2).
- pylinkage.geometry.secants.intersection(obj_1: tuple[float, float] | tuple[float, float, float], obj_2: tuple[float, float] | tuple[float, float, float], tol: float = 0.0) tuple[float, float] | tuple[tuple[float, float], ...] | tuple[float, float, float] | None
Intersection of two arbitrary objects.
The input objects should be points or circles.
- Parameters:
obj_1 – First point or circle (as tuple).
obj_2 – Second point or circle (as tuple).
tol – Absolute tolerance to use if provided.
- Returns:
The intersection found, if any.
Module contents
Basic geometry package.
- pylinkage.geometry.circle_intersect(x1: float, y1: float, r1: float, x2: float, y2: float, r2: float, tol: float = 0.0) tuple[int, float, float, float, float]
Get the intersections of two circles.
Transcription of a Matt Woodhead program, method provided by Paul Bourke, 1997. http://paulbourke.net/geometry/circlesphere/.
- Parameters:
x1 – X coordinate of first circle center.
y1 – Y coordinate of first circle center.
r1 – Radius of first circle.
x2 – X coordinate of second circle center.
y2 – Y coordinate of second circle center.
r2 – Radius of second circle.
tol – Distance under which two points are considered equal.
- Returns:
Tuple of (n_intersections, x1, y1, x2, y2) where: - n=0: No intersection (other values undefined) - n=1: One intersection at (x1, y1) - n=2: Two intersections at (x1, y1) and (x2, y2) - n=3: Same circle (x1, y1, x2 are center and radius)
- pylinkage.geometry.circle_line_from_points_intersection(cx: float, cy: float, r: float, p1_x: float, p1_y: float, p2_x: float, p2_y: float) tuple[int, float, float, float, float]
Intersection(s) of a circle and a line defined by two points.
- Parameters:
cx – X coordinate of circle center.
cy – Y coordinate of circle center.
r – Circle radius.
p1_x – X coordinate of first point on line.
p1_y – Y coordinate of first point on line.
p2_x – X coordinate of second point on line.
p2_y – Y coordinate of second point on line.
- Returns:
Tuple of (n_intersections, x1, y1, x2, y2) where: - n=0: No intersection - n=1: One intersection (tangent) at (x1, y1) - n=2: Two intersections at (x1, y1) and (x2, y2)
- pylinkage.geometry.circle_line_intersection(cx: float, cy: float, r: float, a: float, b: float, c: float) tuple[int, float, float, float, float]
Return the intersection between a line and a circle.
From https://mathworld.wolfram.com/Circle-LineIntersection.html
- Parameters:
cx – X coordinate of circle center.
cy – Y coordinate of circle center.
r – Circle radius.
a – Line equation coefficient a (ax + by + c = 0).
b – Line equation coefficient b.
c – Line equation coefficient c.
- Returns:
Tuple of (n_intersections, x1, y1, x2, y2).
- pylinkage.geometry.cyl_to_cart(radius: float, theta: float, ori_x: float = 0.0, ori_y: float = 0.0) tuple[float, float]
Convert polar coordinates into cartesian.
- Parameters:
radius – Distance from origin.
theta – Angle starting from abscissa axis.
ori_x – Origin X coordinate (Default value = 0.0).
ori_y – Origin Y coordinate (Default value = 0.0).
- Returns:
Cartesian coordinates (x, y).
- pylinkage.geometry.get_nearest_point(ref_x: float, ref_y: float, p1_x: float, p1_y: float, p2_x: float, p2_y: float) tuple[float, float]
Return the point closer to the reference.
- Parameters:
ref_x – X coordinate of reference point.
ref_y – Y coordinate of reference point.
p1_x – X coordinate of first candidate.
p1_y – Y coordinate of first candidate.
p2_x – X coordinate of second candidate.
p2_y – Y coordinate of second candidate.
- Returns:
Coordinates of the nearest point.
- pylinkage.geometry.intersection(obj_1: tuple[float, float] | tuple[float, float, float], obj_2: tuple[float, float] | tuple[float, float, float], tol: float = 0.0) tuple[float, float] | tuple[tuple[float, float], ...] | tuple[float, float, float] | None
Intersection of two arbitrary objects.
The input objects should be points or circles.
- Parameters:
obj_1 – First point or circle (as tuple).
obj_2 – Second point or circle (as tuple).
tol – Absolute tolerance to use if provided.
- Returns:
The intersection found, if any.
- pylinkage.geometry.norm(x: float, y: float) float
Return the norm of a 2-dimensional vector.
- Parameters:
x – X component.
y – Y component.
- Returns:
Vector magnitude.
- pylinkage.geometry.sqr_dist(x1: float, y1: float, x2: float, y2: float) float
Square of the distance between two points.
Faster than dist when only comparing distances.
- Parameters:
x1 – X coordinate of first point.
y1 – Y coordinate of first point.
x2 – X coordinate of second point.
y2 – Y coordinate of second point.
- Returns:
Squared distance.