_geometry module

class pyrockfall._geometry.Geometry(nodes: NDArray[floating], nodes_std: NDArray[floating] | None = None, elements: Sequence[int] | NDArray[integer] | None = None, attributes: Sequence[int] | NDArray[integer] | None = None, neighbours: NDArray[integer] | None = None)[source]

Bases: object

property neighbours: ndarray

Directed-edge neighbours per element.

Convention: for element [v0, v1], neighbours[e, 0] is before v0, and neighbours[e, 1] is after v1.

Type:

np.ndarray of shape (E, D)

property nodes: ndarray

Node coordinates (always returned as (N, D)).

Type:

np.ndarray of shape (N, D)

property elements: ndarray

Element connectivity.

Type:

np.ndarray of shape (E, M)

property attributes: ndarray | None

Element attributes.

Type:

np.ndarray of shape (E,)

property hasUncertainty: bool
property nodes_std: ndarray

Standard deviations for stochastic perturbation.

Type:

np.ndarray of shape (D, N)

property numRandomVariables: int

Number of random variables (zero if no standard deviations).

property floor: float

Lowest vertical coordinate across all slope nodes.

rvs(S: int = 1, *, random_state=None) → ndarray[source]

Vectorised sampling of nodes.

Inputs:

self.nodes : (D, M) float — mean coordinates self.nodes_std : (D, M) float — per-node std dev

Returns:

(D, M, 1) if all std == 0, else (D, M, S)

ppf(q) → ndarray[source]

Vectorised inverse-CDF for nodes.

q can be:
  • (S,) : same percentiles for every node → output (D, M, S)

  • (D, M, S) : per-node percentiles → output (D, M, S)

Returns:

(D, M, 1) if all std == 0, else (D, M, S)

exitTime(p: ndarray, v: ndarray, elem_id: ndarray, *, samples: ndarray | None = None, tol: float = 1e-12) → Tuple[ndarray, ndarray][source]

2D: time to exit current polyline segment along constant velocity. Returns (S,)-shaped arrays: next_el, t_exit

intersectParabolaMatrix(p: ndarray, v: ndarray, a: ndarray, elem_id: ndarray | None = None, *, samples: ndarray | None = None, tol: float = 1e-12) → ndarray[source]

Candidate parabola/polyline support-line intersection times.

Returns a matrix with shape (M-1, S). Entries are np.inf where the parabola has no finite intersection with the segment’s supporting line. Use feasibleImpactTime to filter by segment bounds and choose one hit per sample.

feasibleImpactTime(t: ndarray, p: ndarray, v: ndarray, a: ndarray, *, samples: ndarray | None = None, t_min: float = 0.0, t_max: float = inf, tol: float = 1e-12, position: Callable[[ndarray], ndarray] | None = None) → Tuple[ndarray, ndarray][source]

Filter candidate impact times and choose the earliest feasible hit.

The candidate matrix is tested against segment bounds, the time window, and then reduced to one segment/time pair per sample.

intersectFloor(p: ndarray, v: ndarray, a: ndarray, floor: float, *, t_min: float = 0.0, tol: float = 1e-12) → ndarray[source]

Smallest t >= t_min at which the parabola (p, v, a) reaches the floor: p[-1] + v[-1] t + 0.5 a[-1] t^2 = floor.

Returns an (S,) array of times, np.inf where no such time exists.

intersectParabola(p: ndarray, v: ndarray, a: ndarray, elem_id: ndarray, *, samples: ndarray | None = None, t_min: float = 0.0, t_max: float = inf, tol: float = 1e-12) → Tuple[ndarray, ndarray][source]

Vectorised 2D intersection between parabolic trajectories and a polyline.

Returns (seg_id, t) with shapes (S,), (S,). seg_id=-1 and t is non-finite for no hit.

intersectDamped(p: ndarray, v: ndarray, a: ndarray, damping: ndarray, elem_id: ndarray, *, samples: ndarray | None = None, t_min: float = 0.0, t_max: float = inf, t_ref: ndarray | None = None, tol: float = 1e-12, max_expand: int = 32, maxiter: int = 100) → Tuple[ndarray, ndarray][source]

Vectorised 2D intersection between damped trajectories and a polyline.

Solves, for every segment m and trajectory sample s,

n_m · (r_s(t) - A_m) = 0

where

r’(t) = v(t) v’(t) = a - damping * v

Returns:

seg_id, t – Shapes (S,), (S,). seg_id=-1 and t=nan where no valid segment intersection was found.

Return type:

Tuple[np.ndarray, np.ndarray]

getSamples(samples: ndarray | None, *, S: int | None = None, dtype: dtype | type = <class 'float'>) → ndarray[source]

Return samples with shape (D, M, S). If samples is None, derive from self.points.

  • If samples is None -> use self.points.T[:, :, None] -> (D, M, 1)

  • If last axis is 1 and S is provided -> repeat along last axis to (D, M, S)

  • If last axis is not in {1, S} -> error

verticalProjection(p: ndarray, element_id: ndarray, direction: int = 0, neighbour_check: int = 1, samples: ndarray | None = None) → tuple[ndarray, ndarray][source]

Find, for each sample, the closest segment vertically aligned with p.

Parameters:
  • p ((2, S) float) – Query points.

  • element_id ((S,) int) – Seed element(s). If -1, performs a global search.

  • direction (int) – Search direction: -1 -> only under 0 -> both 1 -> only above

  • neighbour_check (int) – Maximum number of neighbour traversals before giving up and letting the caller trigger global search.

  • samples ((2, M, 1) or (2, M, S) float, optional) – Slope node coordinates.

Returns:

  • elem_id ((S,) int) – Segment id for each sample, or -1 if none.

  • point ((2, S) float) – Vertical projection point on that segment, or nan if none.