Skip to content

3-D walk layout

The corkscrew: the 2-D walk lifted by a constant step in z.

lexograph.layout.walk3d.walk3d_layout(steps, *, turn=-90.0, z_step=1.0, scale=1.0, start=(0.0, 0.0, 0.0), heading=(1.0, 0.0))

Walk the 2-D turtle in the xy-plane while climbing a constant step in z.

Parameters:

Name Type Description Default
steps Iterable[float]

One forward (in-plane) step length per unit.

required
turn float

Degrees to turn the in-plane heading after each step.

-90.0
z_step float

The constant vertical lift added per unit (the corkscrew pitch).

1.0
scale float

A multiplier applied to every in-plane step length.

1.0
start tuple[float, float, float]

The starting (x, y, z) position.

(0.0, 0.0, 0.0)
heading tuple[float, float]

The initial in-plane heading; normalised internally.

(1.0, 0.0)

Returns:

Type Description
Coords

An (N + 1, 3) float array of vertices. Row 0 is start; the

Coords

z coordinate of row i is start[2] + i * z_step.

Contract
  • The result has exactly N + 1 rows for N steps.
  • The z column increases by exactly z_step between consecutive rows.
  • The xy columns equal the 2-D walk with the same parameters.

Examples:

>>> walk3d_layout([1.0, 1.0], z_step=2.0).round(6).tolist()
[[0.0, 0.0, 0.0], [1.0, 0.0, 2.0], [1.0, -1.0, 4.0]]
Source code in lexograph/layout/walk3d.py
def walk3d_layout(
    steps: Iterable[float],
    *,
    turn: float = -90.0,
    z_step: float = 1.0,
    scale: float = 1.0,
    start: tuple[float, float, float] = (0.0, 0.0, 0.0),
    heading: tuple[float, float] = (1.0, 0.0),
) -> Coords:
    """Walk the 2-D turtle in the xy-plane while climbing a constant step in z.

    Args:
        steps: One forward (in-plane) step length per unit.
        turn: Degrees to turn the in-plane heading after each step.
        z_step: The constant vertical lift added per unit (the corkscrew pitch).
        scale: A multiplier applied to every in-plane step length.
        start: The starting ``(x, y, z)`` position.
        heading: The initial in-plane heading; normalised internally.

    Returns:
        An ``(N + 1, 3)`` float array of vertices. Row 0 is ``start``; the
        ``z`` coordinate of row ``i`` is ``start[2] + i * z_step``.

    Contract:
        - The result has exactly ``N + 1`` rows for ``N`` steps.
        - The ``z`` column increases by exactly ``z_step`` between consecutive
          rows.
        - The ``xy`` columns equal the 2-D walk with the same parameters.

    Examples:
        >>> walk3d_layout([1.0, 1.0], z_step=2.0).round(6).tolist()
        [[0.0, 0.0, 0.0], [1.0, 0.0, 2.0], [1.0, -1.0, 4.0]]
    """
    lengths = list(steps)
    xy = walk_layout(
        lengths,
        turn=turn,
        scale=scale,
        start=(start[0], start[1]),
        heading=heading,
    )
    z = start[2] + np.arange(len(lengths) + 1, dtype=float) * z_step
    return np.column_stack([xy, z])