simetri.geometry package

Submodules

simetri.geometry.bezier module

Functions for working with Bezier curves. https://pomax.github.io/bezierinfo is a good resource for understanding Bezier curves.

class simetri.geometry.bezier.Bezier(control_points: Sequence[Sequence[float]], xform_matrix: array | None = None, n_points=None, **kwargs)[source]

Bases: Shape

A Bezier curve defined by control points.

For cubic Bezier curves: [V1, CP1, CP2, V2] For quadratic Bezier curves: [V1, CP, V2] Like all other geometry in simetri.graphics, bezier curves are represented as a sequence of points. Both quadratic and cubic bezier curves are supported. Number of control points determines the type of Bezier curve. A cubic Bezier curve has 4 control points, while a quadratic Bezier curve has 3. curve.subtype reflects this as Types.BEZIER or Types.Q_BEZIER.

control_points

Control points of the Bezier curve.

Type:

Sequence[Point]

cubic

True if the Bezier curve is cubic, False if quadratic.

Type:

bool

matrix

Polynomial matrix for the Bezier curve.

Type:

array

property control_points: Sequence[Sequence[float]]

Return the control points of the Bezier curve.

Returns:

Control points of the Bezier curve.

Return type:

Sequence[Point]

copy() Shape[source]

Return a copy of the Bezier curve.

Returns:

Copy of the Bezier curve.

Return type:

Shape

derivative(t: float)[source]

Return the derivative of the Bezier curve at t.

Parameters:

t (float) – Parameter t, where 0 <= t <= 1.

Returns:

Derivative of the Bezier curve at t.

Return type:

list

normal(t: float)[source]

Return the normal of the Bezier curve at t.

Parameters:

t (float) – Parameter t, where 0 <= t <= 1.

Returns:

Normal of the Bezier curve at t.

Return type:

list

point(t: float)[source]

Return the point on the Bezier curve at t.

Parameters:

t (float) – Parameter t, where 0 <= t <= 1.

Returns:

Point on the Bezier curve at t.

Return type:

list

point2(t: float)[source]

Return the point on the Bezier curve at t.

Parameters:

t (float) – Parameter t, where 0 <= t <= 1.

Returns:

Point on the Bezier curve at t.

Return type:

list

tangent(t: float)[source]

Draw a unit tangent vector at t.

Parameters:

t (float) – Parameter t, where 0 <= t <= 1.

Returns:

Unit tangent vector at t.

Return type:

list

class simetri.geometry.bezier.BezierPoints(control_points: Sequence[Sequence[float]], n_points: int = 10, **kwargs)[source]

Bases: Shape

Points of a Bezier curve defined by the given control points.

These points are spaced evenly along the curve (unlike parametric points). Normal and tangent unit vectors are also available at these points.

control_points

Control points of the Bezier curve.

Type:

Sequence[Point]

param_points

Parametric points on the Bezier curve.

Type:

list

tangents

Tangent vectors at the points.

Type:

list

normals

Normal vectors at the points.

Type:

list

n_points

Number of points on the curve.

Type:

int

offsets(offset: float, double: bool = False)[source]

Return the points on the offset curve.

Parameters:
  • offset (float) – Offset distance.

  • double (bool, optional) – If True, return double offset points. Defaults to False.

Returns:

Points on the offset curve.

Return type:

list

simetri.geometry.bezier.bezier_points(p0, p1: Sequence[float], p2: Sequence[float], p3: Sequence[float], n_points=10)[source]

Return the points on a cubic Bezier curve.

Parameters:
  • p0 (list) – First control point.

  • p1 (list) – Second control point.

  • p2 (list) – Third control point.

  • p3 (list) – Fourth control point.

  • n_points (int, optional) – Number of points. Defaults to 10.

Returns:

Points on the cubic Bezier curve.

Return type:

list

Raises:

ValueError – If n_points is less than 5.

simetri.geometry.bezier.curve(v1: Sequence[float], c1: Sequence[float], c2: Sequence[float], v2: Sequence[float], *args, **kwargs)[source]

Return a cubic Bezier curve/s.

Parameters:
  • v1 (list) – First vertex.

  • c1 (list) – First control point.

  • c2 (list) – Second control point.

  • v2 (list) – Second vertex.

  • *args – Additional control points and vertices.

  • **kwargs – Additional keyword arguments.

Returns:

List of cubic Bezier curves.

Return type:

list

Raises:

ValueError – If the number of control points is invalid.

simetri.geometry.bezier.equidistant_points(p0: Sequence[float], p1: Sequence[float], p2: Sequence[float], p3: Sequence[float], n_points=10)[source]

Return the points on a Bezier curve with equidistant spacing.

Parameters:
  • p0 (list) – First control point.

  • p1 (list) – Second control point.

  • p2 (list) – Third control point.

  • p3 (list) – Fourth control point.

  • n_points (int, optional) – Number of points. Defaults to 10.

Returns:

Points on the Bezier curve, equidistant points, tangents, and normals.

Return type:

tuple

simetri.geometry.bezier.get_cubic_derivative(t: float, points: Sequence[Sequence[float]])[source]

Return the derivative of a cubic Bezier curve at t.

Parameters:
  • t (float) – Parameter t, where 0 <= t <= 1.

  • points (list) – Control points of the Bezier curve.

Returns:

Derivative of the cubic Bezier curve at t.

Return type:

list

simetri.geometry.bezier.get_normal(d: Sequence[float])[source]

Return the normal of a given line.

Parameters:

d (list) – Derivative of the line.

Returns:

Normal of the line.

Return type:

list

simetri.geometry.bezier.get_quadratic_derivative(t: float, points: Sequence[Sequence[float]])[source]

Return the derivative of a quadratic Bezier curve at t.

Parameters:
  • t (float) – Parameter t, where 0 <= t <= 1.

  • points (list) – Control points of the Bezier curve.

Returns:

Derivative of the quadratic Bezier curve at t.

Return type:

list

simetri.geometry.bezier.mirror_point(cp: Sequence[float], vertex: Sequence[float])[source]

Return the mirror of cp about vertex.

Parameters:
  • cp (list) – Control point to be mirrored.

  • vertex (list) – Vertex point.

Returns:

Mirrored control point.

Return type:

list

simetri.geometry.bezier.offset_points(controls, offset, n_points, double=False)[source]

Return the points on the offset curve.

Parameters:
  • controls (list) – Control points of the Bezier curve.

  • offset (float) – Offset distance.

  • n_points (int) – Number of points on the curve.

  • double (bool, optional) – If True, return double offset points. Defaults to False.

Returns:

Points on the offset curve.

Return type:

list

simetri.geometry.bezier.q_bezier_points(p0: Sequence[float], p1: Sequence[float], p2: Sequence[float], n_points: int)[source]

Return the points on a quadratic Bezier curve.

Parameters:
  • p0 (list) – First control point.

  • p1 (list) – Second control point.

  • p2 (list) – Third control point.

  • n_points (int) – Number of points.

Returns:

Points on the quadratic Bezier curve.

Return type:

list

Raises:

ValueError – If n_points is less than 5.

simetri.geometry.bezier.q_curve(v1: Sequence[float], c: Sequence[float], v2: Sequence[float], *args, **kwargs)[source]

Return a quadratic Bezier curve/s.

Parameters:
  • v1 (list) – First vertex.

  • c (list) – Control point.

  • v2 (list) – Second vertex.

  • *args – Additional control points and vertices.

  • **kwargs – Additional keyword arguments.

Returns:

List of quadratic Bezier curves.

Return type:

list

Raises:

ValueError – If the number of control points is invalid.

simetri.geometry.bezier.split_bezier(p0: Sequence[float], p1: Sequence[float], p2: Sequence[float], p3: Sequence[float], z: float, n_points=10)[source]

Split a cubic Bezier curve at t=z.

Parameters:
  • p0 (list) – First control point.

  • p1 (list) – Second control point.

  • p2 (list) – Third control point.

  • p3 (list) – Fourth control point.

  • z (float) – Parameter z, where 0 <= z <= 1.

  • n_points (int, optional) – Number of points. Defaults to 10.

Returns:

Two Bezier curves split at t=z.

Return type:

tuple

simetri.geometry.bezier.split_q_bezier(p0: Sequence[float], p1: Sequence[float], p2: Sequence[float], z: float, n_points=10)[source]

Split a quadratic Bezier curve at t=z.

Parameters:
  • p0 (list) – First control point.

  • p1 (list) – Second control point.

  • p2 (list) – Third control point.

  • z (float) – Parameter z, where 0 <= z <= 1.

  • n_points (int, optional) – Number of points. Defaults to 10.

Returns:

Two Bezier curves split at t=z.

Return type:

tuple

simetri.geometry.circle module

class simetri.geometry.circle.Circle_(center: tuple, radius: float)[source]

Bases: object

A simple circle class.

center: tuple
radius: float
simetri.geometry.circle.apollonius(r1, r2, r3, z1, z2, z3, plus_minus=1)[source]

Solves the Problem of Apollonius using Descartes’ Theorem.

Parameters:
  • r1 (float) – Radius of the first circle.

  • r2 (float) – Radius of the second circle.

  • r3 (float) – Radius of the third circle.

  • z1 (complex) – Center of the first circle.

  • z2 (complex) – Center of the second circle.

  • z3 (complex) – Center of the third circle.

  • plus_minus (int, optional) – +1 for outer tangent circle, -1 for inner tangent circle. Defaults to 1.

Returns:

Radius and center coordinates (x, y) of the tangent circle, or None if no solution is found.

Return type:

tuple

simetri.geometry.circle.circle_area(rad)[source]

Given the radius of a circle, return the area of the circle.

Parameters:

rad (float) – Radius of the circle.

Returns:

Area of the circle.

Return type:

float

simetri.geometry.circle.circle_circumference(rad)[source]

Given the radius of a circle, return the circumference of the circle.

Parameters:

rad (float) – Radius of the circle.

Returns:

Circumference of the circle.

Return type:

float

simetri.geometry.circle.circle_flower(n, radius=25, layers=6, ratio=None)[source]

Steiner chain. Return a list of circles that form a flower-like pattern.

Parameters:
  • n (int) – Number of circles.

  • radius (float, optional) – Radius of the circles. Defaults to 25.

  • layers (int, optional) – Number of layers. Defaults to 6.

  • ratio (float, optional) – Ratio for scaling. Defaults to None.

Returns:

List of circles forming a flower-like pattern.

Return type:

list

Raises:

ValueError – If n is less than 8.

simetri.geometry.circle.circle_tangent_to_2_circles(c1, r1, c2, r2, r)[source]

Given the centers and radii of 2 circles, return the center of a circle with radius r that is tangent to both circles.

Parameters:
  • c1 (tuple) – Center of the first circle.

  • r1 (float) – Radius of the first circle.

  • c2 (tuple) – Center of the second circle.

  • r2 (float) – Radius of the second circle.

  • r (float) – Radius of the tangent circle.

Returns:

Centers (x1, y1) and (x2, y2) of the tangent circle.

Return type:

tuple

simetri.geometry.circle.circle_tangent_to_3_circles(c1, r1, c2, r2, c3, r3, s1=-1, s2=-1, s3=-1)[source]

Given the centers and radii of 3 circles, return the center and radius of a circle that is tangent to all 3 circles.

Parameters:
  • c1 (tuple) – Center of the first circle.

  • r1 (float) – Radius of the first circle.

  • c2 (tuple) – Center of the second circle.

  • r2 (float) – Radius of the second circle.

  • c3 (tuple) – Center of the third circle.

  • r3 (float) – Radius of the third circle.

  • s1 (int, optional) – Sign for the first circle. Defaults to -1.

  • s2 (int, optional) – Sign for the second circle. Defaults to -1.

  • s3 (int, optional) – Sign for the third circle. Defaults to -1.

Returns:

Center (x, y) and radius of the tangent circle.

Return type:

tuple

simetri.geometry.circle.flower_angle(r1, r2, r3)[source]

Given the radii of 3 circles forming an interstice, return the angle between the lines connecting circles’ centers to center of the circle with r1 radius.

Parameters:
  • r1 (float) – Radius of the first circle.

  • r2 (float) – Radius of the second circle.

  • r3 (float) – Radius of the third circle.

Returns:

Angle between the lines connecting circles’ centers.

Return type:

float

simetri.geometry.circle.tangent_points(center1, radius, center2, radius2, cross=False)[source]

Returns the tangent points (p1, p2, p3, p4) in world coordinates.

Parameters:
  • center1 (tuple) – Center of the first circle.

  • radius (float) – Radius of the first circle.

  • center2 (tuple) – Center of the second circle.

  • radius2 (float) – Radius of the second circle.

  • cross (bool, optional) – Whether to calculate crossing tangents. Defaults to False.

Returns:

Tangent points (p1, p2, p3, p4) in world coordinates.

Return type:

tuple

simetri.geometry.ellipse module

Functions for working with ellipses.

class simetri.geometry.ellipse.Arc(center: Sequence[float], start_angle: float, span_angle: float, radius: float, radius2: float, n_points: int | None = None, rot_angle: float = 0, xform_matrix: ndarray | None = None, **kwargs)[source]

Bases: Shape

A circular or elliptic arc defined by a center, radius, radius2, start angle, and end angle. If radius2 is not provided, the arc is a circular arc.

class simetri.geometry.ellipse.Ellipse(center: Sequence[float], width: float, height: float, angle: float = 0, xform_matrix: ndarray | None = None, **kwargs)[source]

Bases: Shape

An ellipse defined by center, width, and height.

property closed

Return True ellipse is always closed.

Returns:

Always returns True.

Return type:

bool

copy()[source]

Return a copy of the ellipse.

Returns:

A copy of the ellipse.

Return type:

Ellipse

simetri.geometry.ellipse.arc2(start, start_angle, end_angle, radius1, radius2)[source]

Return the vertices of an elliptic arc.

Parameters:
  • start (tuple) – Starting point of the arc.

  • start_angle (float) – Starting angle of the arc.

  • end_angle (float) – Ending angle of the arc.

  • radius1 (float) – First radius of the arc.

  • radius2 (float) – Second radius of the arc.

Returns:

Vertices of the elliptic arc.

Return type:

list

simetri.geometry.ellipse.central_to_parametric_angle(a, b, phi)[source]

Converts a central angle to a parametric angle on an ellipse.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • phi (float) – Angle of the line intersecting the center and the point.

Returns:

Parametric angle (in radians).

Return type:

float

simetri.geometry.ellipse.ellipse_central_angle(t, a, b)[source]

Calculates the central angle of an ellipse for a given parameter t.

Parameters:
  • t (float) – The parameter value.

  • a (float) – The semi-major axis of the ellipse.

  • b (float) – The semi-minor axis of the ellipse.

Returns:

The central angle in radians.

Return type:

float

simetri.geometry.ellipse.ellipse_line_intersection(a, b, point)[source]

Return the intersection points of an ellipse and a line segment connecting the given point to the ellipse center at (0, 0).

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • point (tuple) – Point coordinates (x, y).

Returns:

Intersection points.

Return type:

list

simetri.geometry.ellipse.ellipse_param_point(a, b, t)[source]

Return a point on an ellipse with the given a=width/2, b=height/2, and parametric angle. t is the parametric angle and in radians.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • t (float) – Parametric angle in radians.

Returns:

Coordinates of the point on the ellipse.

Return type:

tuple

simetri.geometry.ellipse.ellipse_point(a, b, angle)[source]

Return a point on an ellipse with the given a=width/2, b=height/2, and angle. angle is the central-angle and in radians.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • angle (float) – Central angle in radians.

Returns:

Coordinates of the point on the ellipse.

Return type:

tuple

simetri.geometry.ellipse.ellipse_points(center, a, b, num_points)[source]

Generate points on an ellipse. These are generated from the parametric equations of the ellipse. They are not evenly spaced.

Parameters:
  • center (tuple) – (x, y) coordinates of the ellipse center.

  • a (float) – Length of the semi-major axis.

  • b (float) – Length of the semi-minor axis.

  • num_points (int) – Number of points to generate.

Returns:

Array of (x, y) coordinates of the ellipse points.

Return type:

numpy.ndarray

simetri.geometry.ellipse.ellipse_tangent(a, b, x, y, tol=0.001)[source]

Calculates the angle of the tangent line to an ellipse at the point (x, y).

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • x (float) – x-coordinate of the point.

  • y (float) – y-coordinate of the point.

  • tol (float, optional) – Tolerance for point on ellipse check. Defaults to .001.

Returns:

Angle of the tangent line in radians.

Return type:

float

simetri.geometry.ellipse.elliptic_arc_points(center, rx, ry, start_angle, span_angle, num_points)[source]

Generate points on an elliptic arc. These are generated from the parametric equations of the ellipse. They are not evenly spaced.

Parameters:
  • center (tuple) – (x, y) coordinates of the ellipse center.

  • rx (float) – Length of the semi-major axis.

  • ry (float) – Length of the semi-minor axis.

  • start_angle (float) – Starting angle of the arc.

  • span_angle (float) – Span angle of the arc.

  • num_points (int) – Number of points to generate.

Returns:

Array of (x, y) coordinates of the ellipse points.

Return type:

numpy.ndarray

simetri.geometry.ellipse.elliptic_arclength(t_0, t_1, a, b)[source]

Return the arclength of an ellipse between the given parametric angles. The ellipse has semi-major axis a and semi-minor axis b.

Parameters:
  • t_0 (float) – Starting parametric angle.

  • t_1 (float) – Ending parametric angle.

  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

Returns:

Arclength of the ellipse.

Return type:

float

simetri.geometry.ellipse.get_ellipse_t_for_angle(angle, a, b)[source]

Calculates the parameter t for a given angle on an ellipse.

Parameters:
  • angle (float) – The angle in radians.

  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

Returns:

The parameter t.

Return type:

float

simetri.geometry.ellipse.parametric_to_central_angle(a, b, t)[source]

Converts a parametric angle on an ellipse to a central angle.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • t (float) – Parametric angle (in radians).

Returns:

Angle of the line intersecting the center and the point.

Return type:

float

simetri.geometry.ellipse.r_central(a, b, theta)[source]

Return the radius (distance between the center and the intersection point) of the ellipse at the given angle.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • theta (float) – Angle in radians.

Returns:

Radius at the given angle.

Return type:

float

simetri.geometry.geometry module

Geometry related utilities. These functions are used to perform geometric operations. They are not documented. Some of the are one off functions that are not used in the main codebase or tested.

class simetri.geometry.geometry.Edge(start_point: Sequence[float] | Vertex, end_point: Sequence[float] | Vertex)[source]

Bases: object

A 2D edge.

property angle

Line angle. Angle between the line and the x-axis.

property array

Homogeneous coordinates as a numpy array.

property inclination

Inclination angle. Angle between the line and the x-axis converted to a value between zero and pi.

property length

Length of the line segment.

property points

Start and end

property slope

Line slope. The slope of the line passing through the start and end points.

property vertices

Start and end vertices.

property x1

x-coordinate of the start point.

property x2

x-coordinate of the end point.

property y1

y-coordinate of the start point.

property y2

y-coordinate of the end point.

class simetri.geometry.geometry.Vertex(x, y, z=0)[source]

Bases: list

A 3D vertex.

above(other)[source]

This is for 2D points only

Parameters:

other (Vertex) – Other vertex.

Returns:

True if this vertex is above the other vertex, False otherwise.

Return type:

bool

property array

Homogeneous coordinates as a numpy array.

below(other)[source]

This is for 2D points only

Parameters:

other (Vertex) – Other vertex.

Returns:

True if this vertex is below the other vertex, False otherwise.

Return type:

bool

property coords

Return the coordinates as a tuple.

copy()[source]

Return a shallow copy of the list.

v_tuple()[source]

Return the vertex as a tuple.

simetri.geometry.geometry.all_close_points(points: Sequence[Sequence], dist_tol: float | None = None, with_dist: bool = False) dict[int, list[tuple[Sequence[float], int]]][source]

Find all close points in a list of points along with their ids.

Parameters:
  • points (Sequence[Sequence]) – List of points with ids [[x1, y1, id1], [x2, y2, id2], …].

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

  • with_dist (bool, optional) – Whether to include distances in the result. Defaults to False.

Returns:

Dictionary of the form {id1: [id2, id3, …], …}.

Return type:

dict

simetri.geometry.geometry.all_intersections(segments: Sequence[Sequence[Sequence]], rtol: float | None = None, atol: float | None = None, use_intersection3: bool = False) dict[int, list[tuple[Sequence[float], int]]][source]

Find all intersection points of the given list of segments (sweep line algorithm variant)

Parameters:
  • segments (Sequence[Line]) – List of line segments [[[x1, y1], [x2, y2]], [[x1, y1], [x2, y2]], …].

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

  • use_intersection3 (bool, optional) – Whether to use intersection3 function. Defaults to False.

Returns:

Dictionary of the form {segment_id: [[id1, (x1, y1)], [id2, (x2, y2)]], …}.

Return type:

dict

simetri.geometry.geometry.angle_between_lines2(point1: Sequence[float], point2: Sequence[float], point3: Sequence[float]) float[source]

Given line1 as point1 and point2, and line2 as point3 and point2 return the angle between two lines (point2 is the corner point)

Parameters:
  • point1 (Point) – First point of the first line.

  • point2 (Point) – Second point of the first line and first point of the second line.

  • point3 (Point) – Second point of the second line.

Returns:

Angle between the two lines in radians.

Return type:

float

simetri.geometry.geometry.angle_between_two_lines(line1, line2)[source]

Return the angle between two lines in radians.

Parameters:
  • line1 (Line) – First line.

  • line2 (Line) – Second line.

Returns:

Angle between the two lines in radians.

Return type:

float

simetri.geometry.geometry.angled_line(line: Sequence[Sequence], theta: float) Sequence[Sequence][source]

Given a line find another line with theta radians between them.

Parameters:
  • line (Line) – Input line.

  • theta (float) – Angle in radians.

Returns:

New line with the given angle.

Return type:

Line

simetri.geometry.geometry.angled_vector(angle: float) Sequence[float][source]

Return a vector with the given angle

Parameters:

angle (float) – Angle in radians.

Returns:

Vector with the given angle.

Return type:

Sequence[float]

simetri.geometry.geometry.area(a, b, c)[source]

Return the area of a triangle given its vertices.

Parameters:
  • a (Point) – First vertex.

  • b (Point) – Second vertex.

  • c (Point) – Third vertex.

Returns:

Area of the triangle.

Return type:

float

simetri.geometry.geometry.bbox_overlap(min_x1: float, min_y1: float, max_x2: float, max_y2: float, min_x3: float, min_y3: float, max_x4: float, max_y4: float) bool[source]

Given two bounding boxes, return True if they overlap.

Parameters:
  • min_x1 (float) – Minimum x-coordinate of the first bounding box.

  • min_y1 (float) – Minimum y-coordinate of the first bounding box.

  • max_x2 (float) – Maximum x-coordinate of the first bounding box.

  • max_y2 (float) – Maximum y-coordinate of the first bounding box.

  • min_x3 (float) – Minimum x-coordinate of the second bounding box.

  • min_y3 (float) – Minimum y-coordinate of the second bounding box.

  • max_x4 (float) – Maximum x-coordinate of the second bounding box.

  • max_y4 (float) – Maximum y-coordinate of the second bounding box.

Returns:

True if the bounding boxes overlap, False otherwise.

Return type:

bool

simetri.geometry.geometry.between(a, b, c)[source]

Return True if c is between a and b.

Parameters:
  • a (Point) – First point.

  • b (Point) – Second point.

  • c (Point) – Third point.

Returns:

True if c is between a and b, False otherwise.

Return type:

bool

simetri.geometry.geometry.bisector_line(a: Sequence[float], b: Sequence[float], c: Sequence[float]) Sequence[Sequence][source]

Given three points that form two lines [a, b] and [b, c] return the bisector line between them.

Parameters:
  • a (Point) – First point.

  • b (Point) – Second point.

  • c (Point) – Third point.

Returns:

Bisector line.

Return type:

Line

simetri.geometry.geometry.calc_area(points)[source]

Calculate the area of a simple polygon (given by a list of its vertices).

Parameters:

points (list[Point]) – List of points representing the polygon.

Returns:

Area of the polygon and whether it is clockwise.

Return type:

tuple

simetri.geometry.geometry.cart_to_tri(points)[source]

Convert a list of points from cartesian to triangular coordinates.

Parameters:

points (list[Point]) – List of points in cartesian coordinates.

Returns:

List of points in triangular coordinates.

Return type:

np.ndarray

simetri.geometry.geometry.cartesian_to_polar(x, y)[source]

Convert cartesian coordinates to polar coordinates.

Parameters:
  • x (float) – x-coordinate.

  • y (float) – y-coordinate.

Returns:

Polar coordinates (r, theta).

Return type:

tuple

simetri.geometry.geometry.central_to_parametric_angle(a, b, phi)[source]

Converts a central angle to a parametric angle on an ellipse.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • phi (float) – Central angle in radians.

Returns:

Parametric angle in radians.

Return type:

float

simetri.geometry.geometry.circle_3point(point1, point2, point3)[source]

Given three points, returns the center point and radius

Parameters:
  • point1 (Point) – First point.

  • point2 (Point) – Second point.

  • point3 (Point) – Third point.

Returns:

Center point and radius of the circle.

Return type:

tuple

simetri.geometry.geometry.circle_circle_intersections(x0, y0, r0, x1, y1, r1)[source]

Return the intersection points of two circles.

Parameters:
  • x0 (float) – x-coordinate of the center of the first circle.

  • y0 (float) – y-coordinate of the center of the first circle.

  • r0 (float) – Radius of the first circle.

  • x1 (float) – x-coordinate of the center of the second circle.

  • y1 (float) – y-coordinate of the center of the second circle.

  • r1 (float) – Radius of the second circle.

Returns:

Intersection points of the two circles.

Return type:

tuple

simetri.geometry.geometry.circle_inversion(point, center, radius)[source]

Inverts a point with respect to a circle.

Parameters:
  • point (tuple) – The point to invert, represented as a tuple (x, y).

  • center (tuple) – The center of the circle, represented as a tuple (x, y).

  • radius (float) – The radius of the circle.

Returns:

The inverted point, represented as a tuple (x, y).

Return type:

tuple

simetri.geometry.geometry.circle_line_intersection(c, p1, p2)[source]

Return the intersection points of a circle and a line segment.

Parameters:
  • c (Circle) – Input circle.

  • p1 (Point) – First point of the line segment.

  • p2 (Point) – Second point of the line segment.

Returns:

Intersection points of the circle and the line segment.

Return type:

tuple

simetri.geometry.geometry.circle_poly_intersection(circle, polygon)[source]

Return True if the circle and the polygon intersect.

Parameters:
  • circle (Circle) – Input circle.

  • polygon (Polygon) – Input polygon.

Returns:

True if the circle and the polygon intersect, False otherwise.

Return type:

bool

simetri.geometry.geometry.circle_segment_intersection(circle, p1, p2)[source]

Return True if the circle and the line segment intersect.

Parameters:
  • circle (Circle) – Input circle.

  • p1 (Point) – First point of the line segment.

  • p2 (Point) – Second point of the line segment.

Returns:

True if the circle and the line segment intersect, False otherwise.

Return type:

bool

simetri.geometry.geometry.circle_tangent_to2lines(line1, line2, intersection_, radius)[source]

Given two lines, their intersection point and a radius, return the center of the circle tangent to both lines and with the given radius.

Parameters:
  • line1 (Line) – First line.

  • line2 (Line) – Second line.

  • intersection (Point) – Intersection point of the lines.

  • radius (float) – Radius of the circle.

Returns:

Center of the circle, start and end points of the tangent lines.

Return type:

tuple

simetri.geometry.geometry.clockwise(p: Sequence[float], q: Sequence[float], r: Sequence[float]) bool[source]

Return 1 if the points p, q, and r are in clockwise order, return -1 if the points are in counter-clockwise order, return 0 if the points are collinear

Parameters:
  • p (Point) – First point.

  • q (Point) – Second point.

  • r (Point) – Third point.

Returns:

1 if the points are in clockwise order, -1 if counter-clockwise, 0 if collinear.

Return type:

int

simetri.geometry.geometry.close_angles(angle1: float, angle2: float, angtol=None) bool[source]

Return True if two angles are close to each other.

Parameters:
  • angle1 (float) – First angle in radians.

  • angle2 (float) – Second angle in radians.

  • angtol (float, optional) – Angle tolerance. Defaults to None.

Returns:

True if the angles are close to each other, False otherwise.

Return type:

bool

simetri.geometry.geometry.close_points2(p1: Sequence[float], p2: Sequence[float], dist2: float = 0.01) bool[source]

Return True if two points are close to each other.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

  • dist2 (float, optional) – Square of the threshold distance. Defaults to 0.01.

Returns:

True if the points are close to each other, False otherwise.

Return type:

bool

simetri.geometry.geometry.collinear(a, b, c, area_rtol=None, area_atol=None)[source]

Return True if a, b, and c are collinear.

Parameters:
  • a (Point) – First point.

  • b (Point) – Second point.

  • c (Point) – Third point.

  • area_rtol (float, optional) – Relative tolerance for area. Defaults to None.

  • area_atol (float, optional) – Absolute tolerance for area. Defaults to None.

Returns:

True if the points are collinear, False otherwise.

Return type:

bool

simetri.geometry.geometry.collinear_segments(segment1, segment2, tol=None, atol=None)[source]

Checks if two line segments (a1, b1) and (a2, b2) are collinear.

Parameters:
  • segment1 (Line) – First line segment.

  • segment2 (Line) – Second line segment.

  • tol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

True if the segments are collinear, False otherwise.

Return type:

bool

simetri.geometry.geometry.congruent_polygons(polygon1: list[Sequence[float]], polygon2: list[Sequence[float]], dist_tol: float | None = None, area_tol: float | None = None, side_length_tol: float | None = None, angle_tol: float | None = None) bool[source]

Return True if two polygons are congruent. They can be translated, rotated and/or reflected.

Parameters:
  • polygon1 (list[Point]) – First polygon.

  • polygon2 (list[Point]) – Second polygon.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

  • area_tol (float, optional) – Area tolerance. Defaults to None.

  • side_length_tol (float, optional) – Side length tolerance. Defaults to None.

  • angle_tol (float, optional) – Angle tolerance. Defaults to None.

Returns:

True if the polygons are congruent, False otherwise.

Return type:

bool

simetri.geometry.geometry.connect2(poly_point1: list[Sequence[float]], poly_point2: list[Sequence[float]], dist_tol: float | None = None, rtol: float | None = None) list[Sequence[float]][source]

Connect two polypoints together.

Parameters:
  • poly_point1 (list[Point]) – First list of points.

  • poly_point2 (list[Point]) – Second list of points.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

Returns:

Connected list of points.

Return type:

list[Point]

simetri.geometry.geometry.connected_pairs(items)[source]

Return a list of connected pair tuples corresponding to the items. [a, b, c] -> [(a, b), (b, c)]

Parameters:

items (list) – List of items.

Returns:

List of connected pair tuples.

Return type:

list[tuple]

simetri.geometry.geometry.convex_hull(points)[source]

Return the convex hull of a set of 2D points.

Parameters:

points (list[Point]) – List of 2D points.

Returns:

Convex hull of the points.

Return type:

list[Point]

simetri.geometry.geometry.cross(p1, p2, p3)[source]

Return the cross product of vectors p1p2 and p1p3.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

  • p3 (Point) – Third point.

Returns:

Cross product of the vectors.

Return type:

float

simetri.geometry.geometry.cross_product2(a: Sequence[float], b: Sequence[float], c: Sequence[float]) float[source]

Return the cross product of two vectors: BA and BC.

Parameters:
  • a (Point) – First point, creating vector BA

  • b (Point) – Second point, common point for both vectors

  • c (Point) – Third point, creating vector BC

Returns:

The z-component of cross product between vectors BA and BC

Return type:

float

Note

This gives the signed area of the parallelogram formed by the vectors BA and BC. The sign indicates the orientation (positive for counter-clockwise, negative for clockwise). It is useful for determining the orientation of three points and calculating angles.

vec1 = b - a vec2 = c - b

simetri.geometry.geometry.cross_product_sense(a: Sequence[float], b: Sequence[float], c: Sequence[float]) int[source]

Return the cross product sense of vectors a and b.

Parameters:
  • a (Point) – First point.

  • b (Point) – Second point.

  • c (Point) – Third point.

Returns:

Cross product sense.

Return type:

int

simetri.geometry.geometry.damping_function(amplitude, duration, sample_rate)[source]

Generates a damping function based on the given amplitude, duration, and sample rate.

Parameters:
  • amplitude (float) – The initial amplitude of the damping function.

  • duration (float) – The duration over which the damping occurs, in seconds.

  • sample_rate (float) – The number of samples per second.

Returns:

A list of float values representing the damping function over time.

Return type:

list

simetri.geometry.geometry.direction(p, q, r)[source]

Checks the orientation of three points (p, q, r).

Parameters:
  • p (Point) – First point.

  • q (Point) – Second point.

  • r (Point) – Third point.

Returns:

0 if collinear, >0 if counter-clockwise, <0 if clockwise.

Return type:

int

simetri.geometry.geometry.distance(p1: Sequence[float], p2: Sequence[float]) float[source]

Return the distance between two points.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

Returns:

Distance between the two points.

Return type:

float

simetri.geometry.geometry.distance2(p1: Sequence[float], p2: Sequence[float]) float[source]

Return the squared distance between two points. Useful for comparing distances without the need to compute the square root.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

Returns:

Squared distance between the two points.

Return type:

float

simetri.geometry.geometry.dot_product2(a: Sequence[float], b: Sequence[float], c: Sequence[float]) float[source]

Dot product of two vectors. AB and BC :param a: First point, creating vector BA :type a: Point :param b: Second point, common point for both vectors :type b: Point :param c: Third point, creating vector BC :type c: Point

Returns:

The dot product of vectors BA and BC

Return type:

float

Note

The function calculates (a-b)·(c-b) which is the dot product of vectors BA and BC. This is useful for finding angles between segments that share a common point.

simetri.geometry.geometry.double_offset_lines(line: Sequence[Sequence], offset: float = 1) tuple[Sequence[Sequence], Sequence[Sequence]][source]

Return two offset lines to a given line segment with the given offset amount.

Parameters:
  • line (Line) – Input line segment.

  • offset (float, optional) – Offset distance. Defaults to 1.

Returns:

Two offset lines.

Return type:

tuple[Line, Line]

simetri.geometry.geometry.double_offset_polygons(polygon: list[Sequence[float]], offset: float = 1, dist_tol: float | None = None, **kwargs) list[Sequence[float]][source]

Return a list of double offset lines from a list of lines.

Parameters:
  • polygon (list[Point]) – List of points representing the polygon.

  • offset (float, optional) – Offset distance. Defaults to 1.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

List of double offset lines.

Return type:

list[Point]

simetri.geometry.geometry.double_offset_polylines(lines: list[Sequence[float]], offset: float = 1, rtol: float | None = None, atol: float | None = None) list[Sequence[float]][source]

Return a list of double offset lines from a list of lines.

Parameters:
  • lines (list[Point]) – List of points representing the lines.

  • offset (float, optional) – Offset distance. Defaults to 1.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

List of double offset lines.

Return type:

list[Point]

simetri.geometry.geometry.ellipse_line_intersection(a, b, point)[source]

Return the intersection points of an ellipse and a line segment connecting the given point to the ellipse center at (0, 0).

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • point (Point) – Point on the line segment.

Returns:

Intersection points of the ellipse and the line segment.

Return type:

list[Point]

simetri.geometry.geometry.ellipse_point(a, b, angle)[source]

Return a point on an ellipse with the given a=width/2, b=height/2, and angle.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • angle (float) – Angle in radians.

Returns:

Point on the ellipse.

Return type:

Point

simetri.geometry.geometry.ellipse_points(center, a, b, num_points)[source]

Generate points on an ellipse.

Parameters:
  • center (tuple) – (x, y) coordinates of the ellipse center.

  • a (float) – Length of the semi-major axis.

  • b (float) – Length of the semi-minor axis.

  • num_points (int) – Number of points to generate.

Returns:

Array of (x, y) coordinates of the ellipse points.

Return type:

np.ndarray

simetri.geometry.geometry.ellipse_tangent(a, b, x, y, tol=0.001)[source]

Calculates the slope of the tangent line to an ellipse at the point (x, y). If point is not on the ellipse, return False.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • x (float) – x-coordinate of the point.

  • y (float) – y-coordinate of the point.

  • tol (float, optional) – Tolerance. Defaults to 0.001.

Returns:

Slope of the tangent line, or False if the point is not on the ellipse.

Return type:

float

simetri.geometry.geometry.elliptic_arclength(t_0, t_1, a, b)[source]

Return the arclength of an ellipse between the given parametric angles. The ellipse has semi-major axis a and semi-minor axis b.

Parameters:
  • t_0 (float) – Start parametric angle in radians.

  • t_1 (float) – End parametric angle in radians.

  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

Returns:

Arclength of the ellipse between the given parametric angles.

Return type:

float

simetri.geometry.geometry.equal_lines(line1: Sequence[Sequence], line2: Sequence[Sequence], dist_tol: float | None = None) bool[source]

Return True if two lines are close enough.

Parameters:
  • line1 (Line) – First line.

  • line2 (Line) – Second line.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

True if the lines are close enough, False otherwise.

Return type:

bool

simetri.geometry.geometry.equal_polygons(poly1: Sequence[Sequence[float]], poly2: Sequence[Sequence[float]], dist_tol: float | None = None) bool[source]

Return True if two polygons are close enough.

Parameters:
  • poly1 (Sequence[Point]) – First polygon.

  • poly2 (Sequence[Point]) – Second polygon.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

True if the polygons are close enough, False otherwise.

Return type:

bool

simetri.geometry.geometry.extended_line(dist: float, line: Sequence[Sequence], extend_both=False) Sequence[Sequence][source]

Given a line ((x1, y1), (x2, y2)) and a distance, the given line is extended by distance units. Return a new line ((x1, y1), (x2’, y2’)).

Parameters:
  • dist (float) – Distance to extend the line.

  • line (Line) – Input line.

  • extend_both (bool, optional) – Whether to extend both ends of the line. Defaults to False.

Returns:

Extended line.

Return type:

Line

simetri.geometry.geometry.fillet(a: Sequence[float], b: Sequence[float], c: Sequence[float], radius: float) tuple[Sequence[Sequence], Sequence[Sequence], Sequence[float]][source]

Given three points that form two lines [a, b] and [b, c] return the clipped lines [a, d], [e, c], center point of the radius circle (tangent to both lines), and the arc angle of the formed fillet.

Parameters:
  • a (Point) – First point.

  • b (Point) – Second point.

  • c (Point) – Third point.

  • radius (float) – Radius of the fillet.

Returns:

Clipped lines [a, d], [e, c], center point of the radius circle, and the arc angle.

Return type:

tuple

simetri.geometry.geometry.fix_degen_points(points: list[Sequence[float]], loop=False, closed=False, dist_tol: float | None = None, area_rtol: float | None = None, area_atol: float | None = None, check_collinear=True) list[Sequence[float]][source]

Return a list of points with duplicate points removed. Remove the middle point from the collinear points.

Parameters:
  • points (list[Point]) – List of points.

  • loop (bool, optional) – Whether to loop the points. Defaults to False.

  • closed (bool, optional) – Whether the points form a closed shape. Defaults to False.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

  • area_rtol (float, optional) – Relative tolerance for area. Defaults to None.

  • area_atol (float, optional) – Absolute tolerance for area. Defaults to None.

  • check_collinear (bool, optional) – Whether to check for collinear points. Defaults to True.

Returns:

List of points with duplicate and collinear points removed.

Return type:

list[Point]

simetri.geometry.geometry.flat_points(connected_segments)[source]

Return a list of points from a list of connected pairs of points.

Parameters:

connected_segments (list[tuple]) – List of connected pairs of points.

Returns:

List of points.

Return type:

list[Point]

simetri.geometry.geometry.get_interior_points(start, end, n_points)[source]

Given start and end points and number of interior points returns the positions of the interior points

Parameters:
  • start (Point) – Start point.

  • end (Point) – End point.

  • n_points (int) – Number of interior points.

Returns:

List of interior points.

Return type:

list[Point]

simetri.geometry.geometry.get_polygon_grid_point(n, line1, line2, circumradius=100)[source]

See chapter ??? for explanation of this function.

Parameters:
  • n (int) – Number of sides.

  • line1 (Line) – First line.

  • line2 (Line) – Second line.

  • circumradius (float, optional) – Circumradius of the polygon. Defaults to 100.

Returns:

Grid point of the polygon.

Return type:

Point

simetri.geometry.geometry.get_polygons(nested_points: Sequence[Sequence[float]], n_round_digits: int = 2, dist_tol: float | None = None) list[source]

Convert points to clean polygons. Points are vertices of polygons.

Parameters:
  • nested_points (Sequence[Point]) – List of nested points.

  • n_round_digits (int, optional) – Number of decimal places to round to. Defaults to 2.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

List of clean polygons.

Return type:

list

simetri.geometry.geometry.get_quadrant(x: float, y: float) int[source]

quadrants: +x, +y = 1st +x, -y = 2nd -x, -y = 3rd +x, -y = 4th

Parameters:
  • x (float) – x-coordinate.

  • y (float) – y-coordinate.

Returns:

Quadrant number.

Return type:

int

simetri.geometry.geometry.get_quadrant_from_deg_angle(deg_angle: float) int[source]

quadrants: (0, 90) = 1st (90, 180) = 2nd (180, 270) = 3rd (270, 360) = 4th

Parameters:

deg_angle (float) – Angle in degrees.

Returns:

Quadrant number.

Return type:

int

simetri.geometry.geometry.global_to_local(x: float, y: float, xi: float, yi: float, theta: float = 0) Sequence[float][source]

Given a point(x, y) in global coordinates and local CS position and orientation, return a point(ksi, eta) in local coordinates

Parameters:
  • x (float) – Global x-coordinate.

  • y (float) – Global y-coordinate.

  • xi (float) – Local x-coordinate.

  • yi (float) – Local y-coordinate.

  • theta (float, optional) – Angle in radians. Defaults to 0.

Returns:

Local coordinates (ksi, eta).

Return type:

Point

simetri.geometry.geometry.homogenize(points: Sequence[Sequence[float]]) ndarray[source]

Convert a list of points to homogeneous coordinates.

Parameters:

points (Sequence[Point]) – List of points.

Returns:

Homogeneous coordinates.

Return type:

np.ndarray

simetri.geometry.geometry.inclination_angle(start_point: Sequence[float], end_point: Sequence[float]) float[source]

Return the inclination angle (in radians) of a line given by start and end points. Inclination angle is always between zero and pi. Order makes no difference.

Parameters:
  • start_point (Point) – Start point of the line.

  • end_point (Point) – End point of the line.

Returns:

Inclination angle of the line in radians.

Return type:

float

simetri.geometry.geometry.intersect(line1: Sequence[Sequence], line2: Sequence[Sequence]) Sequence[float][source]

Return the intersection point of two lines. line1: [(x1, y1), (x2, y2)] line2: [(x3, y3), (x4, y4)] To find the intersection point of two line segments use the “intersection” function

Parameters:
  • line1 (Line) – First line.

  • line2 (Line) – Second line.

Returns:

Intersection point of the two lines.

Return type:

Point

simetri.geometry.geometry.intersect2(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, x4: float, y4: float, rtol: float | None = None, atol: float | None = None) Sequence[float][source]

Return the intersection point of two lines. line1: (x1, y1), (x2, y2) line2: (x3, y3), (x4, y4) To find the intersection point of two line segments use the “intersection” function

Parameters:
  • x1 (float) – x-coordinate of the first point of the first line.

  • y1 (float) – y-coordinate of the first point of the first line.

  • x2 (float) – x-coordinate of the second point of the first line.

  • y2 (float) – y-coordinate of the second point of the first line.

  • x3 (float) – x-coordinate of the first point of the second line.

  • y3 (float) – y-coordinate of the first point of the second line.

  • x4 (float) – x-coordinate of the second point of the second line.

  • y4 (float) – y-coordinate of the second point of the second line.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

Intersection point of the two lines.

Return type:

Point

simetri.geometry.geometry.intersection(line1: Sequence[Sequence], line2: Sequence[Sequence], rtol: float | None = None) int[source]

return the intersection point of two line segments. segment1: ((x1, y1), (x2, y2)) segment2: ((x3, y3), (x4, y4)) if line segments do not intersect return -1 if line segments are parallel return 0 if line segments are connected (share a point) return 1 To find the intersection point of two lines use the “intersect” function

Parameters:
  • line1 (Line) – First line segment.

  • line2 (Line) – Second line segment.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

Returns:

Intersection type.

Return type:

int

simetri.geometry.geometry.intersection2(x1, y1, x2, y2, x3, y3, x4, y4, rtol=None, atol=None)[source]

Check the intersection of two line segments. See the documentation

Parameters:
  • x1 (float) – x-coordinate of the first point of the first line segment.

  • y1 (float) – y-coordinate of the first point of the first line segment.

  • x2 (float) – x-coordinate of the second point of the first line segment.

  • y2 (float) – y-coordinate of the second point of the first line segment.

  • x3 (float) – x-coordinate of the first point of the second line segment.

  • y3 (float) – y-coordinate of the first point of the second line segment.

  • x4 (float) – x-coordinate of the second point of the second line segment.

  • y4 (float) – y-coordinate of the second point of the second line segment.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

Connection type and intersection point.

Return type:

tuple

simetri.geometry.geometry.intersection3(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, x4: float, y4: float, rtol: float | None = None, atol: float | None = None, dist_tol: float | None = None, area_atol: float | None = None) tuple[Connection, list][source]

Check the intersection of two line segments. See the documentation for more details.

Parameters:
  • x1 (float) – x-coordinate of the first point of the first line segment.

  • y1 (float) – y-coordinate of the first point of the first line segment.

  • x2 (float) – x-coordinate of the second point of the first line segment.

  • y2 (float) – y-coordinate of the second point of the first line segment.

  • x3 (float) – x-coordinate of the first point of the second line segment.

  • y3 (float) – y-coordinate of the first point of the second line segment.

  • x4 (float) – x-coordinate of the second point of the second line segment.

  • y4 (float) – y-coordinate of the second point of the second line segment.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

  • area_atol (float, optional) – Absolute tolerance for area. Defaults to None.

Returns:

Connection type and intersection result.

Return type:

tuple

simetri.geometry.geometry.intersects(seg1, seg2)[source]

Checks if the line segments intersect. If they are chained together, they are considered as intersecting. Returns True if the segments intersect, False otherwise.

Parameters:
  • seg1 (Line) – First line segment.

  • seg2 (Line) – Second line segment.

Returns:

True if the segments intersect, False otherwise.

Return type:

bool

simetri.geometry.geometry.invert(p, center, radius)[source]

Inverts p about a circle at the given center and radius

Parameters:
  • p (Point) – Point to invert.

  • center (Point) – Center of the circle.

  • radius (float) – Radius of the circle.

Returns:

Inverted point.

Return type:

Point

simetri.geometry.geometry.is_chained(seg1, seg2)[source]

Checks if the line segments are chained together.

Parameters:
  • seg1 (Line) – First line segment.

  • seg2 (Line) – Second line segment.

Returns:

True if the segments are chained together, False otherwise.

Return type:

bool

simetri.geometry.geometry.is_convex(points)[source]

Return True if the polygon is convex.

Parameters:

points (list[Point]) – List of points representing the polygon.

Returns:

True if the polygon is convex, False otherwise.

Return type:

bool

simetri.geometry.geometry.is_horizontal(line: Sequence[Sequence], eps: float = 0.0001) bool[source]

Return True if the line is horizontal.

Parameters:
  • line (Line) – Input line.

  • eps (float, optional) – Tolerance. Defaults to 0.0001.

Returns:

True if the line is horizontal, False otherwise.

Return type:

bool

simetri.geometry.geometry.is_line(line_: Any) bool[source]

Return True if the input is a line.

Parameters:

line (Any) – Input value.

Returns:

True if the input is a line, False otherwise.

Return type:

bool

simetri.geometry.geometry.is_number(x: Any) bool[source]

Return True if x is a number.

Parameters:

x (Any) – The input value to check.

Returns:

True if x is a number, False otherwise.

Return type:

bool

simetri.geometry.geometry.is_point(pnt: Any) bool[source]

Return True if the input is a point.

Parameters:

pnt (Any) – Input value.

Returns:

True if the input is a point, False otherwise.

Return type:

bool

simetri.geometry.geometry.is_simple(polygon, rtol: float | None = None, atol: float | None = None) bool[source]

Return True if the polygon is simple.

Parameters:
  • polygon (list) – List of points representing the polygon.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

True if the polygon is simple, False otherwise.

Return type:

bool

simetri.geometry.geometry.is_vertical(line: Sequence[Sequence], eps: float = 0.0001) bool[source]

Return True if the line is vertical.

Parameters:
  • line (Line) – Input line.

  • eps (float, optional) – Tolerance. Defaults to 0.0001.

Returns:

True if the line is vertical, False otherwise.

Return type:

bool

simetri.geometry.geometry.law_of_cosines(a: float, b: float, c: float) float[source]

Return the angle of a triangle given the three sides. Returns the angle of A in radians. A is the angle between sides b and c. cos(A) = (b^2 + c^2 - a^2) / (2 * b * c)

Parameters:
  • a (float) – Length of side a.

  • b (float) – Length of side b.

  • c (float) – Length of side c.

Returns:

Angle of A in radians.

Return type:

float

simetri.geometry.geometry.left_turn(p1, p2, p3)[source]

Return True if p1, p2, p3 make a left turn.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

  • p3 (Point) – Third point.

Returns:

True if the points make a left turn, False otherwise.

Return type:

bool

simetri.geometry.geometry.length(line: Sequence[Sequence]) float[source]

Return the length of a line.

Parameters:

line (Line) – Input line.

Returns:

Length of the line.

Return type:

float

simetri.geometry.geometry.lerp_point(p1: Sequence[float], p2: Sequence[float], t: float) Sequence[float][source]

Linear interpolation of two points.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

  • t (float) – Interpolation parameter. t = 0 => p1, t = 1 => p2.

Returns:

Interpolated point.

Return type:

Point

simetri.geometry.geometry.line2vector(line: Sequence[Sequence]) Sequence[float][source]

Return the vector representation of a line

Parameters:

line (Line) – Input line.

Returns:

Vector representation of the line.

Return type:

VecType

simetri.geometry.geometry.line_angle(start_point: Sequence[float], end_point: Sequence[float]) float[source]

Return the orientation angle (in radians) of a line given by start and end points. Order makes a difference.

Parameters:
  • start_point (Point) – Start point of the line.

  • end_point (Point) – End point of the line.

Returns:

Orientation angle of the line in radians.

Return type:

float

simetri.geometry.geometry.line_by_point_angle_length(point, angle, length_)[source]

Given a point, an angle, and a length, return the line that starts at the point and has the given angle and length.

Parameters:
  • point (Point) – Start point of the line.

  • angle (float) – Angle of the line in radians.

  • length (float) – Length of the line.

Returns:

Line with the given angle and length.

Return type:

Line

simetri.geometry.geometry.line_segment_bbox(x1: float, y1: float, x2: float, y2: float) tuple[float, float, float, float][source]

Return the bounding box of a line segment.

Parameters:
  • x1 (float) – Segment start point x-coordinate.

  • y1 (float) – Segment start point y-coordinate.

  • x2 (float) – Segment end point x-coordinate.

  • y2 (float) – Segment end point y-coordinate.

Returns:

Bounding box as (min_x, min_y, max_x, max_y).

Return type:

tuple

simetri.geometry.geometry.line_segment_bbox_check(seg1: Sequence[Sequence], seg2: Sequence[Sequence]) bool[source]

Given two line segments, return True if their bounding boxes overlap.

Parameters:
  • seg1 (Line) – First line segment.

  • seg2 (Line) – Second line segment.

Returns:

True if the bounding boxes overlap, False otherwise.

Return type:

bool

simetri.geometry.geometry.line_through_point_and_angle(point: Sequence[float], angle: float, length_: float = 100) Sequence[Sequence][source]

Return a line through the given point with the given angle and length

Parameters:
  • point (Point) – Point through which the line passes.

  • angle (float) – Angle of the line in radians.

  • length (float, optional) – Length of the line. Defaults to 100.

Returns:

Line passing through the given point with the given angle and length.

Return type:

Line

simetri.geometry.geometry.line_through_point_angle(point: Sequence[float], angle: float, length_: float, both_sides=False) Sequence[Sequence][source]

Return a line that passes through the given point with the given angle and length. If both_side is True, the line is extended on both sides by the given length.

Parameters:
  • point (Point) – Point through which the line passes.

  • angle (float) – Angle of the line in radians.

  • length (float) – Length of the line.

  • both_sides (bool, optional) – Whether to extend the line on both sides. Defaults to False.

Returns:

Line passing through the given point with the given angle and length.

Return type:

Line

simetri.geometry.geometry.line_vector(line: Sequence[Sequence]) Sequence[float][source]

Return the vector representation of a line.

Parameters:

line (Line) – Input line.

Returns:

Vector representation of the line.

Return type:

VecType

simetri.geometry.geometry.merge_consecutive_collinear_edges(points, closed=False, area_rtol=None, area_atol=None)[source]

Remove the middle points from collinear edges.

Parameters:
  • points (list[Point]) – List of points.

  • closed (bool, optional) – Whether the points form a closed shape. Defaults to False.

  • area_rtol (float, optional) – Relative tolerance for area. Defaults to None.

  • area_atol (float, optional) – Absolute tolerance for area. Defaults to None.

Returns:

List of points with collinear points removed.

Return type:

list[Point]

simetri.geometry.geometry.merge_segments(seg1: Sequence[Sequence[float]], seg2: Sequence[Sequence[float]]) Sequence[Sequence[float]][source]

Merge two segments into one segment if they are connected. They need to be overlapping or simply connected to each other, otherwise they will not be merged. Order doesn’t matter.

Parameters:
  • seg1 (Sequence[Point]) – First segment.

  • seg2 (Sequence[Point]) – Second segment.

Returns:

Merged segment.

Return type:

Sequence[Point]

simetri.geometry.geometry.mid_point(p1: Sequence[float], p2: Sequence[float]) Sequence[float][source]

Return the mid point of two points.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

Returns:

Mid point of the two points.

Return type:

Point

simetri.geometry.geometry.ndarray_to_xy_list(arr: ndarray) Sequence[Sequence[float]][source]

Convert a numpy array to a list of points.

Parameters:

arr (np.ndarray) – Input numpy array.

Returns:

List of points.

Return type:

Sequence[Point]

simetri.geometry.geometry.norm(vec: Sequence[float]) float[source]

Return the norm (vector length) of a vector.

Parameters:

vec (VecType) – Input vector.

Returns:

Norm of the vector.

Return type:

float

simetri.geometry.geometry.normal(point1, point2)[source]

Return the normal vector of a line.

Parameters:
  • point1 (Point) – First point of the line.

  • point2 (Point) – Second point of the line.

Returns:

Normal vector of the line.

Return type:

VecType

simetri.geometry.geometry.normalize(vec: Sequence[float]) Sequence[float][source]

Return the normalized vector.

Parameters:

vec (VecType) – Input vector.

Returns:

Normalized vector.

Return type:

VecType

simetri.geometry.geometry.offset_line(line: Sequence[Sequence[float]], offset: float) Sequence[Sequence[float]][source]

Return an offset line from a given line.

Parameters:
  • line (Sequence[Point]) – Input line.

  • offset (float) – Offset distance.

Returns:

Offset line.

Return type:

Sequence[Point]

simetri.geometry.geometry.offset_lines(polylines: Sequence[Sequence[Sequence]], offset: float = 1) list[Sequence[Sequence]][source]

Return a list of offset lines from a list of lines.

Parameters:
  • polylines (Sequence[Line]) – List of input lines.

  • offset (float, optional) – Offset distance. Defaults to 1.

Returns:

List of offset lines.

Return type:

list[Line]

simetri.geometry.geometry.offset_point(point: Sequence[float], dx: float = 0, dy: float = 0) Sequence[float][source]

Return an offset point from a given point.

Parameters:
  • point (Point) – Input point.

  • dx (float, optional) – Offset distance in x-direction. Defaults to 0.

  • dy (float, optional) – Offset distance in y-direction. Defaults to 0.

Returns:

Offset point.

Return type:

Point

simetri.geometry.geometry.offset_point_from_start(p1, p2, offset)[source]

p1, p2: points on a line offset: distance from p1 return the point on the line at the given offset

Parameters:
  • p1 (Point) – First point on the line.

  • p2 (Point) – Second point on the line.

  • offset (float) – Distance from p1.

Returns:

Point on the line at the given offset.

Return type:

Point

simetri.geometry.geometry.offset_point_on_line(point: Sequence[float], line: Sequence[Sequence], offset: float) Sequence[float][source]

Return a point on a line that is offset from the given point.

Parameters:
  • point (Point) – Input point.

  • line (Line) – Input line.

  • offset (float) – Offset distance.

Returns:

Offset point on the line.

Return type:

Point

simetri.geometry.geometry.offset_polygon(polygon: list[Sequence[float]], offset: float = -1, dist_tol: float | None = None) list[Sequence[float]][source]

Return a list of offset lines from a list of lines.

Parameters:
  • polygon (list[Point]) – List of points representing the polygon.

  • offset (float, optional) – Offset distance. Defaults to -1.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

List of offset lines.

Return type:

list[Point]

simetri.geometry.geometry.offset_polygon_points(polygon: list[Sequence[float]], offset: float = 1, dist_tol: float | None = None) list[Sequence[float]][source]

Return a list of double offset lines from a list of lines.

Parameters:
  • polygon (list[Point]) – List of points representing the polygon.

  • offset (float, optional) – Offset distance. Defaults to 1.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

List of double offset lines.

Return type:

list[Point]

simetri.geometry.geometry.parallel_line(line: Sequence[Sequence], point: Sequence[float]) Sequence[Sequence][source]

Return a parallel line to the given line that goes through the given point

Parameters:
  • line (Line) – Input line.

  • point (Point) – Point through which the parallel line passes.

Returns:

Parallel line.

Return type:

Line

simetri.geometry.geometry.parametric_to_central_angle(a, b, t)[source]

Converts a parametric angle on an ellipse to a central angle.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • t (float) – Parametric angle in radians.

Returns:

Central angle in radians.

Return type:

float

simetri.geometry.geometry.perp_offset_point(point: Sequence[float], line: Sequence[Sequence], offset: float) Sequence[float][source]

Return a point that is offset from the given point in the perpendicular direction to the given line.

Parameters:
  • point (Point) – Input point.

  • line (Line) – Input line.

  • offset (float) – Offset distance.

Returns:

Perpendicular offset point.

Return type:

Point

simetri.geometry.geometry.perp_unit_vector(line: Sequence[Sequence]) Sequence[float][source]

Return the perpendicular unit vector to a line

Parameters:

line (Line) – Input line.

Returns:

Perpendicular unit vector.

Return type:

VecType

simetri.geometry.geometry.point_in_quad(point: Sequence[float], quad: list[Sequence[float]]) bool[source]

Return True if the point is inside the quad.

Parameters:
  • point (Point) – Input point.

  • quad (list[Point]) – List of points representing the quad.

Returns:

True if the point is inside the quad, False otherwise.

Return type:

bool

simetri.geometry.geometry.point_on_line(point: Sequence[float], line: Sequence[Sequence], rtol: float | None = None, atol: float | None = None) bool[source]

Return True if the given point is on the given line

Parameters:
  • point (Point) – Input point.

  • line (Line) – Input line.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

True if the point is on the line, False otherwise.

Return type:

bool

simetri.geometry.geometry.point_on_line_segment(point: Sequence[float], line: Sequence[Sequence], rtol: float | None = None, atol: float | None = None) bool[source]

Return True if the given point is on the given line segment

Parameters:
  • point (Point) – Input point.

  • line (Line) – Input line segment.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

True if the point is on the line segment, False otherwise.

Return type:

bool

simetri.geometry.geometry.point_to_circle_distance(point, center, radius)[source]

Given a point, center point, and radius, returns distance between the given point and the circle

Parameters:
  • point (Point) – Input point.

  • center (Point) – Center of the circle.

  • radius (float) – Radius of the circle.

Returns:

Distance between the point and the circle.

Return type:

float

simetri.geometry.geometry.point_to_line_distance(point: Sequence[float], line: Sequence[Sequence]) float[source]

Return the vector from a point to a line

Parameters:
  • point (Point) – Input point.

  • line (Line) – Input line.

Returns:

Distance from the point to the line.

Return type:

float

simetri.geometry.geometry.point_to_line_seg_distance(p, lp1, lp2)[source]

Given a point p and a line segment defined by boundary points lp1 and lp2, returns the distance between the line segment and the point. If the point is not located in the perpendicular area between the boundary points, returns False.

Parameters:
  • p (Point) – Input point.

  • lp1 (Point) – First boundary point of the line segment.

  • lp2 (Point) – Second boundary point of the line segment.

Returns:

Distance between the point and the line segment, or False if the point is not in the perpendicular area.

Return type:

float

simetri.geometry.geometry.point_to_line_vec(point: Sequence[float], line: Sequence[Sequence], unit: bool = False) Sequence[float][source]

Return the perpendicular vector from a point to a line

Parameters:
  • point (Point) – Input point.

  • line (Line) – Input line.

  • unit (bool, optional) – Whether to return a unit vector. Defaults to False.

Returns:

Perpendicular vector from the point to the line.

Return type:

VecType

simetri.geometry.geometry.polar_to_cartesian(r, theta)[source]

Convert polar coordinates to cartesian coordinates.

Parameters:
  • r (float) – Radius.

  • theta (float) – Angle in radians.

Returns:

Cartesian coordinates.

Return type:

Point

simetri.geometry.geometry.polygon_area(polygon: Sequence[Sequence[float]], dist_tol=None) float[source]

Calculate the area of a polygon.

Parameters:
  • polygon (Sequence[Point]) – List of points representing the polygon.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

Area of the polygon.

Return type:

float

simetri.geometry.geometry.polygon_center(polygon_points: list[Sequence[float]]) Sequence[float][source]

Given a list of points that define a polygon, return the center point.

Parameters:

polygon_points (list[Point]) – List of points representing the polygon.

Returns:

Center point of the polygon.

Return type:

Point

simetri.geometry.geometry.polygon_center2(polygon_points: list[Sequence[float]]) Sequence[float][source]

Given a list of points that define a polygon, return the center point.

Parameters:

polygon_points (list[Point]) – List of points representing the polygon.

Returns:

Center point of the polygon.

Return type:

Point

simetri.geometry.geometry.polygon_cg(points: list[Sequence[float]]) Sequence[float][source]

Given a list of points that define a polygon, return the center point.

Parameters:

points (list[Point]) – List of points representing the polygon.

Returns:

Center point of the polygon.

Return type:

Point

simetri.geometry.geometry.polygon_internal_angles(polygon)[source]

Return the internal angles of a polygon.

Parameters:

polygon (list[Point]) – List of points representing the polygon.

Returns:

List of internal angles of the polygon.

Return type:

list[float]

simetri.geometry.geometry.polyline_length(polygon: Sequence[Sequence[float]], closed=False, dist_tol=None) float[source]

Calculate the perimeter of a polygon.

Parameters:
  • polygon (Sequence[Point]) – List of points representing the polygon.

  • closed (bool, optional) – Whether the polygon is closed. Defaults to False.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

Perimeter of the polygon.

Return type:

float

simetri.geometry.geometry.positive_angle(angle, radians=True, tol=None, atol=None)[source]

Return the positive angle in radians or degrees.

Parameters:
  • angle (float) – Input angle.

  • radians (bool, optional) – Whether the angle is in radians. Defaults to True.

  • tol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

Positive angle.

Return type:

float

simetri.geometry.geometry.project_line(line: Sequence[Sequence]) Sequence[Sequence][source]

Project a 3d line given by [(x1, y1, z1), (x2, y2, z2)] to 2d plane. :param line: Line to project. :type line: Line

Returns:

Projected line.

Return type:

Line

simetri.geometry.geometry.project_point(point: Sequence[float]) Sequence[float][source]

Project a 3d point given by (x, y, z) to 2d plane. :param point: Point to project. :type point: Point

Returns:

Projected point.

Return type:

Point

simetri.geometry.geometry.project_point_on_line(point: Vertex, line: Edge)[source]

Given a point and a line, returns the projection of the point on the line

Parameters:
  • point (Vertex) – Input point.

  • line (Edge) – Input line.

Returns:

Projection of the point on the line.

Return type:

Vertex

simetri.geometry.geometry.r_polar(a, b, theta)[source]

Return the radius (distance between the center and the intersection point) of the ellipse at the given angle.

Parameters:
  • a (float) – Semi-major axis of the ellipse.

  • b (float) – Semi-minor axis of the ellipse.

  • theta (float) – Angle in radians.

Returns:

Radius of the ellipse at the given angle.

Return type:

float

simetri.geometry.geometry.radius2side_len(n: int, radius: float) float[source]

Given a radius and the number of sides, return the side length of an n-sided regular polygon with the given radius

Parameters:
  • n (int) – Number of sides.

  • radius (float) – Radius of the polygon.

Returns:

Side length of the polygon.

Return type:

float

simetri.geometry.geometry.remove_bad_points(points)[source]

Remove redundant and collinear points from a list of points.

Parameters:

points (list[Point]) – List of points.

Returns:

List of points with redundant and collinear points removed.

Return type:

list[Point]

simetri.geometry.geometry.remove_collinear_points(points: list[Sequence[float]], rtol: float | None = None, atol: float | None = None) list[Sequence[float]][source]

Return a list of points with collinear points removed.

Parameters:
  • points (list[Point]) – List of points.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

List of points with collinear points removed.

Return type:

list[Point]

simetri.geometry.geometry.remove_duplicate_points(points: list[Sequence[float]], dist_tol=None) list[Sequence[float]][source]

Return a list of points with duplicate points removed.

Parameters:
  • points (list[Point]) – List of points.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

List of points with duplicate points removed.

Return type:

list[Point]

simetri.geometry.geometry.right_handed(polygon: Sequence[Sequence[float]], dist_tol=None) float[source]

If polygon is counter-clockwise, return True

Parameters:
  • polygon (Sequence[Point]) – List of points representing the polygon.

  • dist_tol (float, optional) – Distance tolerance. Defaults to None.

Returns:

True if the polygon is counter-clockwise, False otherwise.

Return type:

bool

simetri.geometry.geometry.right_turn(p1, p2, p3)[source]

Return True if p1, p2, p3 make a right turn.

Parameters:
  • p1 (Point) – First point.

  • p2 (Point) – Second point.

  • p3 (Point) – Third point.

Returns:

True if the points make a right turn, False otherwise.

Return type:

bool

simetri.geometry.geometry.rotate_3D(point: Sequence[float], line: Sequence[Sequence], angle: float) Sequence[float][source]

Rotate a 2d point (out of paper) about a 2d line by the given angle. This is used for animating mirror reflections.

Args:

point (Point): Point to rotate. line (Line): Line to rotate about. angle (float): Angle of rotation in radians.

Returns:

Point: Rotated point.

simetri.geometry.geometry.rotate_line(line: Sequence[Sequence], about: Sequence[Sequence], angle: float) Sequence[Sequence][source]

Rotate a 3d line about a 3d line by the given angle

Parameters:
  • line (Line) – Line to rotate.

  • about (Line) – Line to rotate about.

  • angle (float) – Angle of rotation in radians.

Returns:

Rotated line.

Return type:

Line

simetri.geometry.geometry.rotate_point(point, center, angle)[source]

Rotate a point around a center by an angle in radians.

Parameters:
  • point (Point) – Point to rotate.

  • center (Point) – Center of rotation.

  • angle (float) – Angle of rotation in radians.

Returns:

Rotated point.

Return type:

Point

simetri.geometry.geometry.rotate_point_around_line(point, line_point, line_direction, angle_degrees)[source]

Rotates a 3D point around a 3D line by a given angle.

Parameters:
  • point (numpy.ndarray) – The 3D point to rotate (x, y, z).

  • line_point (numpy.ndarray) – A point on the line (x, y, z).

  • line_direction (numpy.ndarray) – The direction vector of the line (x, y, z).

  • angle_degrees (float) – The angle of rotation in degrees.

Returns:

The rotated 3D point (x, y, z).

Return type:

numpy.ndarray

simetri.geometry.geometry.round_point(point: list[float], n_digits: int = 2) list[float][source]

Round a point (x, y) to a given precision.

Parameters:
  • point (list[float]) – Input point.

  • n_digits (int, optional) – Number of decimal places to round to. Defaults to 2.

Returns:

Rounded point.

Return type:

list[float]

simetri.geometry.geometry.round_segment(segment: Sequence[Sequence[float]], n_digits: int = 2)[source]

Round a segment to a given precision.

Parameters:
  • segment (Sequence[Point]) – Input segment.

  • n_digits (int, optional) – Number of decimal places to round to. Defaults to 2.

Returns:

Rounded segment.

Return type:

Sequence[Point]

simetri.geometry.geometry.segmentize_catmull_rom(a: float, b: float, c: float, d: float, n: int = 100) Sequence[float][source]

a and b are the control points and c and d are start and end points respectively, n is the number of segments to generate.

Parameters:
  • a (float) – First control point.

  • b (float) – Second control point.

  • c (float) – Start point.

  • d (float) – End point.

  • n (int, optional) – Number of segments to generate. Defaults to 100.

Returns:

List of points representing the segments.

Return type:

Sequence[float]

simetri.geometry.geometry.segmentize_line(line: Sequence[Sequence], segment_length: float) list[Sequence[Sequence]][source]

Return a list of points that would form segments with the given length.

Parameters:
  • line (Line) – Input line.

  • segment_length (float) – Length of each segment.

Returns:

List of segments.

Return type:

list[Line]

simetri.geometry.geometry.set_vertices(points)[source]

Set the next and previous vertices of a list of vertices.

Parameters:

points (list[Vertex]) – List of vertices.

simetri.geometry.geometry.side_len_to_radius(n: int, side_len: float) float[source]

Given a side length and the number of sides, return the radius of an n-sided regular polygon with the given side_len length

Parameters:
  • n (int) – Number of sides.

  • side_len (float) – Side length of the polygon.

Returns:

Radius of the polygon.

Return type:

float

simetri.geometry.geometry.sine_wave(amplitude: float, frequency: float, duration: float, sample_rate: float, phase: float = 0, damping: float = 1) ndarray[source]

Generate a sine wave.

Parameters:
  • amplitude (float) – Amplitude of the wave.

  • frequency (float) – Frequency of the wave.

  • duration (float) – Duration of the wave.

  • sample_rate (float) – Sample rate.

  • phase (float, optional) – Phase angle of the wave. Defaults to 0.

  • damping (float, optional) – Damping factor. Defaults to 1.

Returns:

Time and signal arrays representing the sine wave.

Return type:

np.ndarray

simetri.geometry.geometry.slope(start_point: Sequence[float], end_point: Sequence[float], rtol=None, atol=None) float[source]

Return the slope of a line given by two points. Order makes a difference.

Parameters:
  • start_point (Point) – Start point of the line.

  • end_point (Point) – End point of the line.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

Slope of the line.

Return type:

float

simetri.geometry.geometry.stitch(lines: list[Sequence[Sequence]], closed: bool = True, return_points: bool = True, rtol: float | None = None, atol: float | None = None) list[Sequence[float]][source]

Stitches a list of lines together.

Parameters:
  • lines (list[Line]) – List of lines to stitch.

  • closed (bool, optional) – Whether the lines form a closed shape. Defaults to True.

  • return_points (bool, optional) – Whether to return points or lines. Defaults to True.

  • rtol (float, optional) – Relative tolerance. Defaults to None.

  • atol (float, optional) – Absolute tolerance. Defaults to None.

Returns:

Stitched list of points or lines.

Return type:

list[Point]

simetri.geometry.geometry.stitch_lines(line1: Sequence[Sequence], line2: Sequence[Sequence]) Sequence[Sequence[Sequence]][source]

if the lines intersect, trim the lines if the lines don’t intersect, extend the lines

Parameters:
  • line1 (Line) – First line.

  • line2 (Line) – Second line.

Returns:

Trimmed or extended lines.

Return type:

Sequence[Line]

simetri.geometry.geometry.surface_normal(p1: Sequence[float], p2: Sequence[float], p3: Sequence[float]) Sequence[float][source]

Calculates the surface normal of a triangle given its vertices.

Parameters:
  • p1 (Point) – First vertex.

  • p2 (Point) – Second vertex.

  • p3 (Point) – Third vertex.

Returns:

Surface normal vector.

Return type:

VecType

simetri.geometry.geometry.tokenize_svg_path(path: str) list[str][source]

Tokenize an SVG path string.

Parameters:

path (str) – SVG path string.

Returns:

List of tokens.

Return type:

list[str]

simetri.geometry.geometry.translate_line(dx: float, dy: float, line: Sequence[Sequence]) Sequence[Sequence][source]

Return a translated line by dx and dy

Parameters:
  • dx (float) – Translation distance in x-direction.

  • dy (float) – Translation distance in y-direction.

  • line (Line) – Input line.

Returns:

Translated line.

Return type:

Line

simetri.geometry.geometry.tri_to_cart(points)[source]

Convert a list of points from triangular to cartesian coordinates.

Parameters:

points (list[Point]) – List of points in triangular coordinates.

Returns:

List of points in cartesian coordinates.

Return type:

np.ndarray

simetri.geometry.geometry.triangle_area(a: float, b: float, c: float) float[source]

Given side lengths a, b and c, return the area of the triangle.

Parameters:
  • a (float) – Length of side a.

  • b (float) – Length of side b.

  • c (float) – Length of side c.

Returns:

Area of the triangle.

Return type:

float

simetri.geometry.geometry.trim_line(line1: Sequence[Sequence], line2: Sequence[Sequence]) Sequence[Sequence][source]

Trim line1 to the intersection of line1 and line2. Extend it if necessary.

Parameters:
  • line1 (Line) – First line.

  • line2 (Line) – Second line.

Returns:

Trimmed line.

Return type:

Line

simetri.geometry.geometry.unit_vector(line: Sequence[Sequence]) Sequence[float][source]

Return the unit vector of a line

Parameters:

line (Line) – Input line.

Returns:

Unit vector of the line.

Return type:

VecType

simetri.geometry.geometry.unit_vector_(line: Sequence[Sequence]) Sequence[Sequence[float]][source]

Return the cartesian unit vector of a line with the given line’s start and end points

Parameters:

line (Line) – Input line.

Returns:

Cartesian unit vector of the line.

Return type:

Sequence[VecType]

simetri.geometry.geometry.vec_along_line(line: Sequence[Sequence], magnitude: float) Sequence[float][source]

Return a vector along a line with the given magnitude.

Parameters:
  • line (Line) – Input line.

  • magnitude (float) – Magnitude of the vector.

Returns:

Vector along the line with the given magnitude.

Return type:

VecType

simetri.geometry.geometry.vec_dir_angle(vec: Sequence[float]) float[source]

Return the direction angle of a vector

Parameters:

vec (Sequence[float]) – Input vector.

Returns:

Direction angle of the vector.

Return type:

float

simetri.geometry.hobby module

class simetri.geometry.hobby.HobbyCurve(points: list[tuple], tension: float = 1, cyclic: bool = False, begin_curl: float = 1, end_curl: float = 1, debug: bool = False)[source]

Bases: object

A class for calculating the control points required to draw a Hobby curve.

points

The list of points defining the curve.

Type:

list[HobbyPoint]

ctrl_pts

The calculated control points.

Type:

list[tuple]

is_cyclic

Whether the curve is closed.

Type:

bool

begin_curl

Curl value for the beginning of the curve.

Type:

float

end_curl

Curl value for the end of the curve.

Type:

float

num_points

Number of points in the curve.

Type:

int

debug_mode

Whether to print debug information.

Type:

bool

calculate_ctrl_pts() list[tuple][source]

Calculate the Bezier control points between consecutive points.

Returns:

A list of (x, y) tuples representing the control points, with two control points for each curve segment between consecutive points.

calculate_d_vals() None[source]

Calculate the pairwise distances between consecutive points in the curve.

calculate_phi_vals() None[source]

Calculate the phi values using the relationship theta + phi + psi = 0.

calculate_psi_vals() None[source]

Calculate the psi values by finding the angle of the polygonal turns.

Raises:

ZeroDivisionError – If consecutive points have the same coordinates.

calculate_theta_vals() None[source]

Calculate the theta values by solving a linear system of equations.

This is the core of Hobby’s algorithm, creating and solving a system of equations to find the optimal angles for smooth splines.

get_ctrl_points() list[tuple][source]

Calculate and return all of the control points of the Hobby curve.

Executes the Hobby algorithm by calculating distance values, psi values, theta values, and phi values, then uses these to compute control points.

Returns:

A list of (x, y) tuples representing the Bezier control points.

show_debug_msg() None[source]

Display debug information for each point if debug mode is enabled.

class simetri.geometry.hobby.HobbyPoint(x: float, y: float, tension: float)[source]

Bases: complex

A class for associating numerical quantities from Hobby’s algorithm with points that appear on a Hobby curve.

We subclass complex to perform complex arithmetic with points on the Hobby curve, as required in the algorithm.

x

The x-coordinate of the point.

Type:

float

y

The y-coordinate of the point.

Type:

float

alpha

The reciprocal of tension for incoming segment.

Type:

float

beta

The reciprocal of tension for outgoing segment.

Type:

float

d_val

Distance between this point and next.

Type:

float

theta

Angle of polygonal line from this point to next.

Type:

float

phi

Offset angle.

Type:

float

psi

Another offset angle.

Type:

float

debug_info() str[source]

Return a string with the point’s information.

Returns:

A string containing the point’s coordinates and all of its computational values.

simetri.geometry.hobby.hobby_ctrl_points(points: list[tuple], tension: float = 1, cyclic: bool = False, begin_curl: float = 1, end_curl: float = 1, debug: bool = False) list[tuple][source]

Calculate cubic Bezier control points using John Hobby’s algorithm.

Parameters:
  • points – List of (x, y) tuples representing the curve’s points.

  • tension – Controls the “tightness” of the curve (lower is tighter).

  • cyclic – Whether the curve should be closed.

  • begin_curl – Curl value for the beginning of the curve.

  • end_curl – Curl value for the end of the curve.

  • debug – Whether to print debug information.

Returns:

A list of (x, y) tuples representing the Bezier control points.

simetri.geometry.hobby.hobby_shape(points, cyclic=False, tension=1, begin_curl=1, end_curl=1, debug=False)[source]

Create a Shape object from points using John Hobby’s algorithm.

This function calculates cubic Bezier control points using Hobby’s algorithm, then creates a Shape object by generating points along the resulting Bezier curves.

Parameters:
  • points – List of (x, y) tuples representing the curve’s points.

  • cyclic – Whether the curve should be closed.

  • tension – Controls the “tightness” of the curve (lower is tighter).

  • begin_curl – Curl value for the beginning of the curve.

  • end_curl – Curl value for the end of the curve.

  • debug – Whether to print debug information.

Returns:

A Shape object containing points along the smooth Hobby curve.

simetri.geometry.hobby.velocity(theta: float, phi: float) float[source]

Calculate the “velocity” function used in Metafont’s curve algorithm.

This function implements the specific velocity formula from Knuth’s Metafont.

Parameters:
  • theta – The theta angle value.

  • phi – The phi angle value.

Returns:

The computed velocity value used in control point calculations.

Module contents