pylinkage.geometry package

Submodules

pylinkage.geometry.core module

Basic geometry features.

pylinkage.geometry.core.cyl_to_cart(radius, theta, ori=(0, 0))

Convert polar coordinates into cartesian.

Parameters:
  • radius – distance from ori

  • theta – angle is the angle starting from abscissa axis

  • ori – origin point (Default value = (0)).

pylinkage.geometry.core.dist_builtin(point1, point2)

Euclidian distance between two 2D points.

Legacy built-in unoptimized equivalent of math.dist in Python 3.8.

Parameters:
  • point1 (tuple[float, float]) – First point

  • point2 (tuple[float, float]) – Second point

pylinkage.geometry.core.get_nearest_point(reference_point, first_point, second_point)

Return the point closer to the reference.

Parameters:
  • reference_point (tuple[float, float]) – Point to compare to

  • first_point (tuple[float, float]) – First point candidate

  • second_point (tuple[float, float]) – Second point candidate

Return tuple[float, float]:

Either first point or second point

pylinkage.geometry.core.line_from_points(first_point, second_point)

A cartesian equation of the line joining two points.

Parameters:
  • first_point (tuple[float, float]) – One point of the line.

  • second_point (tuple[float, float]) – Another point on the line.

Return tuple[float, float, float]:

A cartesian equation of this line.

pylinkage.geometry.core.norm(vec)

Return the norm of a 2-dimensional vector.

Parameters:

vec (tuple[float, float]) – Vector to get norm from

pylinkage.geometry.core.sqr_dist(point1, point2)

Square of the distance between two points.

Faster than dist.

Parameters:
  • point1 (tuple[float, float]) – First point to compare

  • point2 (tuple[float, float]) – Second point

Return float:

Computed distance

pylinkage.geometry.secants module

The geometry module provides general geometry functions.

It is used extensively, so each function should be highly optimized.

pylinkage.geometry.secants.bounding_box(locus)

Compute the bounding box of a locus.

Parameters

locuslist[tuple[float]]

A list of point or any iterable with the same structure.

Returns

tuple[float]

Bounding box as (y_min, x_max, y_max, x_min).

pylinkage.geometry.secants.circle_intersect(circle1, circle2, tol=0.0)

Get the intersections of two circles.

Transcription of a Matt Woodhead program, method provided by Paul Bourke, 1997. http://paulbourke.net/geometry/circlesphere/.

Parameters:
  • circle1 (tuple[float, float, float]) – first circle

  • circle2 (tuple[float, float, float]) – second circle

  • tol (float) – distance under which two points are considered equal (Default value = 0.0)

Returns:

the intersections of two circles. Can be: - (0, ) when no intersection. - (1, (float, float)) if the intersection is one point. - (2, (float, float), (float, float)) for two points of intersection. - (3, (float, float, float)) if the intersection is a circle.

Return type:

tuple[int] | tuple[int, tuple[float, float]] |

tuple[int, tuple[float, float], tuple[float, float]] | tuple[int, tuple[float, float, float]]

pylinkage.geometry.secants.circle_line_from_points_intersection(circle, first_point, second_point)

Intersection(s) of a circle and a line defined by two points.

Parameters:
  • circle (tuple[float, float, float]) – Sequence of (abscissa, ordinate, radius)

  • first_point (tuple[float, float]) – One point of the line.

  • second_point (tuple[float, float]) – Another point on the line.

Returns:

Either 0, 1 or two intersection points, the first elements indicates the intersection type.

Return type:

tuple | tuple[tuple[float, float]] | tuple[tuple[float, float], tuple[float, float]]

pylinkage.geometry.secants.circle_line_intersection(circle, line)

Return the intersection between a line and a circle.

From https://mathworld.wolfram.com/Circle-LineIntersection.html

Circle((x0,y0), r).intersection(Line(a*x+b*y+c)) # sympy

Parameters:
  • circle (tuple[float, float, float]) – Sequence of (abscissa, ordinate, radius)

  • line (tuple[float, float, float]) – Cartesian equation of a line.

Returns:

Nothing, one or two intersections. The length of the tuple gives the intersection type.

Return type:

tuple | tuple[tuple[float, float]] | tuple[tuple[float, float], tuple[float, float]]

pylinkage.geometry.secants.intersection(obj_1, obj_2, tol=0.0)

Intersection of two arbitrary objects.

The input objects should be points or circles.

Parameters:
  • obj_1 (tuple[float, float] | tuple[float, float, float]) – First point or circle

  • obj_2 (tuple[float, float] | tuple[float, float, float]) – Second point or circle

  • tol (float) – absolute tolerance to use if provided. (Default value = 0.0)

Returns:

The intersection found, if any

Return type:

tuple[float, float] | tuple[float, float, float] | None

pylinkage.geometry.secants.secant_circles_intersections(distance, dist_x, dist_y, mid_dist, radius1, projected)

Return the TWO intersections of secant circles.

Module contents

Basic geometry package.