geoclide.mathope module#
Basic mathematical utilities.
This module gathers the scalar/array helper functions used by the geoclide shapes: clamping of a value into a range, solving of quadratic equations, and the gamma terms bounding the floating-point rounding errors (in simple and double precision) used by the ray-shape intersection tests.
- geoclide.mathope.clamp(val: float, val_min: float, val_max: float) float[source]#
Clamps val into the range [val_min, val_max]
- Parameters:
- valfloat
The scalar to be clamped
- val_minfloat
The minimum value
- val_maxfloat
The maximum value
- Returns:
- float
The result of the clamp
Examples
>>> import geoclide as gc >>> gc.clamp(4, val_min=5, val_max=11) 5
- geoclide.mathope.quadratic(a: ndarray, b: ndarray, c: ndarray) tuple[ndarray, ndarray, ndarray][source]#
- geoclide.mathope.quadratic(a: float, b: float, c: float) tuple[bool, float | None, float | None]
Resolve the quadratic polynomial: ax**2 + bx + c
where x is the quadratic polynomial variable and a, b and c the coefficients
- Parameters:
- afloat or ndarray
The first coefficient(s) of the quadratic polynomial. In case of an ndarray, it must be 1-D
- bfloat or ndarray
The second coefficient(s) of the quadratic polynomial. In case of an ndarray, it must be 1-D
- cfloat or ndarray
The third coefficient(s) of the quadratic polynomial. In case of an ndarray, it must be 1-D
- Returns:
- bbool or ndarray
If the quadratic can be solved return True, else False. In case of an ndarray, it is a 1-D ndarray of booleans
- x0float or None or ndarray
The first solution(s). In case of an ndarray, it is 1-D
- x1float or None or ndarray
The second solution(s). In case of an ndarray, it is 1-D
Notes
If There are 2 solutions x0 < x1. And if there is only one solution x0 = x1.
Examples
>>> import geoclide as gc >>> a = 2 >>> b = -5 >>> c = 0 >>> gc.quadratic(a, b, c) (True, 0.0, 2.5)