Skip to content

geometry¤

Geometry functions on plain point lists: arrays of points, and projection onto and discretisation of polylines.

Arrays¤

circle_evaluate ¤

circle_evaluate(t: float, r: float, z: float = 0) -> list[float]

Evaluate a circle of radius r centred on the origin at angle t in radians.

Parameters:

  • t (float) –

    The angle in radians.

  • r (float) –

    The radius.

  • z (float, default: 0 ) –

    The elevation of the circle's plane above the XY plane.

Returns:

  • list –

    The XYZ coordinates of the point.

archimedean_spiral_evaluate ¤

archimedean_spiral_evaluate(t: float, a: float, b: float, z: float = 0) -> list[float]

Evaluate an archimedean spiral r = a + b * theta at angle t in radians.

Parameters:

  • t (float) –

    The angle in radians.

  • a (float) –

    The offset angle of the spiral.

  • b (float) –

    The radial growth per radian.

  • z (float, default: 0 ) –

    The elevation of the spiral's plane above the XY plane.

Returns:

  • list –

    The XYZ coordinates of the point.

line_array ¤

line_array(
    n: int, d: float, anchor: list[float] = [0.0, 0.0, 0.0]
) -> list[list[float]]

rectangular_array ¤

rectangular_array(
    nx: int, ny: int, dx: float, dy: float, anchor: list[float] = [0.0, 0.0, 0.0]
) -> list[list[float]]

circular_array ¤

circular_array(
    n: int, r: float, anchor: list[float] = [0.0, 0.0, 0.0]
) -> list[list[float]]

spiral_array ¤

spiral_array(
    n: int, d: float, anchor: list[float] = [0.0, 0.0, 0.0]
) -> list[list[float]]

Polylines¤

polyline_length ¤

polyline_length(points: list[list[float]]) -> float

Total length of an OPEN polyline.

point_at_length ¤

point_at_length(
    chain: list[list[float]], cumulative: list[float], s: float, tol: float = 1e-12
) -> list[float]

The point at arc length s along an open chain, by linear interpolation.

For a closed loop pass the ring (the loop with its first point repeated at the end) and wrap s yourself. Beyond either end, the last point.

closest_on_polyline ¤

closest_on_polyline(
    point: list[float], points: list[list[float]], closed: bool = False
) -> tuple[int, float, list[float], float]

(segment index, t, closest point, distance) on a polyline, in 3D.

Parameters:

  • point ([x, y, z]) –
  • points (list[[x, y, z]]) –

    Three components each; unlike the rest of this module, z is read.

  • closed (bool, default: False ) –

    Add the segment from the last point back to the first.

Returns:

  • tuple –

    (index, t, [x, y, z], distance). Distance is inf, and the other three meaningless, when no segment has non-zero length.

project_on_polyline ¤

project_on_polyline(
    point: list[float], points: list[list[float]]
) -> tuple[float, float, float]

(distance, arclength, total length) for a point near an open polyline, in XY.

Parameters:

  • point ([x, y, z]) –
  • points (list[[x, y, z]]) –

    The open polyline.

Returns:

  • tuple –

    (distance, arclength of the closest point, total length).

distance_to_polyline ¤

distance_to_polyline(point: list[float], points: list[list[float]]) -> float

Shortest distance from a point to an OPEN polyline, in XY.

distance_to_loop ¤

distance_to_loop(p: list[float], loop: list[list[float]]) -> float

Shortest distance from a point to a closed polyline (stored open), in XY.

Parameters:

  • p ([x, y, z]) –
  • loop (list[[x, y, z]]) –

    Open, the last point is not the first.

Returns:

  • float –

    inf for a loop with no segment of non-zero length.

near_loop ¤

near_loop(
    points: list[list[float]], loop: list[list[float]], radius: float, chunk: int = 2048
) -> list[bool]

distance_to_loop(p, loop) < radius for many points at once, exactly.

loop_arc_lengths ¤

loop_arc_lengths(loop: list[list[float]]) -> tuple[list[float], list[float]]

(segment lengths, cumulative arc length) of a CLOSED loop given open.

cumulative has one entry per vertex plus a last one, the loop's total length, so segment i runs from cumulative[i] to cumulative[i + 1].

loop_parameter ¤

loop_parameter(
    point: list[float], loop: list[list[float]], cumulative: list[float] | None = None
) -> tuple[float, float]

(distance, arc length) of the point of a CLOSED loop closest to point.

Parameters:

  • point ([x, y, z]) –
  • loop (list[[x, y, z]]) –

    Open, the last point is not the first.

  • cumulative (list[float], default: None ) –

    loop_arc_lengths' second value, when the caller already has it.

resample_loop ¤

resample_loop(
    points: list[list[float]], spacing: float | None = None
) -> list[list[float]]

One loop through discretise_boundary, with no scale rule.

discretise_line ¤

discretise_line(line: list[list[float]], spacing: float | None) -> list[list[float]]

Discretise one open curve at spacing (thesis eq. 4.1), keeping its extremities.

Pass the wall spacing, or a 2-point guide never becomes a Delaunay edge.

Parameters:

  • line (list[[x, y, z]]) –

    The open curve.

  • spacing (float) –

    Maximum segment length. None returns the curve unchanged apart from dropping consecutive duplicates.

Returns:

  • list[[x, y, z]] –

discretise_boundary ¤

discretise_boundary(
    outer: list[list[float]],
    inners: list[list[list[float]]] | None = None,
    alpha: float | None = 0.02,
    d_min: int | None = 5,
    spacing: float | None = None,
) -> tuple[list[list[float]], list[list[list[float]]]]

Discretise closed boundary loops per thesis eq. 4.1, d_i = max(ceil(l_i / (alpha D)), d_min).

Every input point survives; each segment is subdivided on its own.

Parameters:

  • outer (list[[x, y, z]]) –

    The outer loop, stored OPEN -- the last point is not the first. A repeated closing point is dropped, so a closed list is accepted too.

  • inners (list[list[[x, y, z]]], default: None ) –

    The holes, same convention. They are discretised against the SAME D as the outer loop, which is the point of taking them here rather than loop by loop: a small hole measured against its own bounding box would come back far denser than the wall beside it.

  • alpha (float, default: 0.02 ) –

    Fraction of D to use as the spacing when spacing is None. None for both returns the loops unchanged -- the explicit opt-out, for a caller who has already sampled its walls.

  • d_min (int, default: 5 ) –

    Fewest points per loop, whatever the target length says. None or 0 disables the floor.

  • spacing (float, default: None ) –

    Maximum segment length, given directly. Overrides alpha when not None.

Returns:

  • tuple –

    (outer, inners), both open, with the closing segment subdivided like any other.

bounding_box_diagonal ¤

bounding_box_diagonal(*loops: list[list[float]]) -> float

The diagonal of the total XY bounding box of every loop given.

Parameters:

  • *loops (list[[x, y, z]], default: () ) –

    Any number of point lists. Empty ones are ignored.

Returns:

  • float –

    0.0 if no points were given.

points_in_polygon_xy ¤

points_in_polygon_xy(
    points: list[list[float]], polygon: list[list[float]]
) -> list[bool]

compas.geometry.is_point_in_polygon_xy for many points at once.

The same ray-crossing test with the same arithmetic, so every answer -- including a point exactly on an edge -- is the one compas gives.

signed_area ¤

signed_area(loop: list[list[float]]) -> float

Signed area of a closed polygon in XY: positive when counter-clockwise.