geometry_functions¶
shortfx.fxNumeric.geometry_functions
¶
Analytic geometry and solid geometry formulas.
Plane geometry (distances, areas, lines, conics), solid geometry (volumes, surface areas), and spherical trigonometry from Spiegel's Mathematical Handbook of Formulas and Tables.
Functions¶
annulus_area(outer_radius: float, inner_radius: float) -> float
¶
Compute the area of an annulus (ring).
A = π(R² - r²)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outer_radius
|
float
|
Outer radius R. |
required |
inner_radius
|
float
|
Inner radius r. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area of the annulus. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If radii are negative or inner ≥ outer. |
Usage Example
round(annulus_area(5.0, 3.0), 4) 50.2655
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
arc_length(radius: float, angle: float) -> float
¶
Length of a circular arc: r * theta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
angle
|
float
|
Central angle in radians (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Arc length. |
Example
round(arc_length(2, math.pi), 6) 6.283185
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
capsule_surface_area(radius: float, cylinder_length: float) -> float
¶
Compute the surface area of a capsule.
SA = 2π·r·l + 4π·r²
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius of the capsule. |
required |
cylinder_length
|
float
|
Length of the cylindrical section. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If radius ≤ 0 or cylinder_length < 0. |
Usage Example
round(capsule_surface_area(2.0, 5.0), 4) 113.0973
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
capsule_volume(radius: float, cylinder_length: float) -> float
¶
Compute the volume of a capsule (cylinder with hemispherical caps).
V = π·r²·l + (4/3)π·r³
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius of the capsule. |
required |
cylinder_length
|
float
|
Length of the cylindrical section. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If radius ≤ 0 or cylinder_length < 0. |
Usage Example
round(capsule_volume(2.0, 5.0), 4) 96.3422
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
circle_area(radius: float) -> float
¶
Area of a circle: pi * r^2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area. |
Example
round(circle_area(1), 6) 3.141593
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
circle_circumference(radius: float) -> float
¶
Circumference of a circle: 2 * pi * r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Circumference. |
Example
round(circle_circumference(1), 6) 6.283185
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
circular_ring_perimeter(outer_radius: float, inner_radius: float) -> float
¶
Compute the perimeter of an annulus (both circles).
P = 2π(R + r)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outer_radius
|
float
|
Outer radius R. |
required |
inner_radius
|
float
|
Inner radius r. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total perimeter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If radii are negative or inner ≥ outer. |
Usage Example
round(circular_ring_perimeter(5.0, 3.0), 4) 50.2655
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
cone_lateral_area(radius: float, slant_height: float) -> float
¶
Lateral surface area of a cone: pi r l.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Base radius (> 0). |
required |
slant_height
|
float
|
Slant height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Lateral surface area. |
Example
round(cone_lateral_area(3, 5), 6) 47.12389
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
cone_slant_height(radius: float, height: float) -> float
¶
Compute the slant height of a cone.
l = √(r² + h²)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Base radius. |
required |
height
|
float
|
Height of the cone. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Slant height. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If radius ≤ 0 or height ≤ 0. |
Usage Example
cone_slant_height(3.0, 4.0) 5.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
cone_volume(radius: float, height: float) -> float
¶
Volume of a right circular cone: (1/3) pi r^2 h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Base radius (> 0). |
required |
height
|
float
|
Height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Example
round(cone_volume(3, 4), 6) 37.699112
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
cuboid_space_diagonal(a: float, b: float, c: float) -> float
¶
Compute the space diagonal of a cuboid.
d = √(a² + b² + c²)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Length. |
required |
b
|
float
|
Width. |
required |
c
|
float
|
Height. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Space diagonal. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If any dimension ≤ 0. |
Usage Example
round(cuboid_space_diagonal(3.0, 4.0, 5.0), 4) 7.0711
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
cylinder_surface_area(radius: float, height: float) -> float
¶
Total surface area of a right circular cylinder: 2 pi r (r + h).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
height
|
float
|
Height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total surface area. |
Example
round(cylinder_surface_area(2, 5), 6) 87.964594
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
cylinder_volume(radius: float, height: float) -> float
¶
Volume of a right circular cylinder: pi r^2 h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
height
|
float
|
Height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Example
round(cylinder_volume(2, 5), 6) 62.831853
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
distance_2d(x1: float, y1: float, x2: float, y2: float) -> float
¶
Euclidean distance between two points in the plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1, y1
|
First point. |
required | |
x2, y2
|
Second point. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Distance d = sqrt((x2-x1)^2 + (y2-y1)^2). |
Example
distance_2d(0, 0, 3, 4) 5.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
distance_3d(x1: float, y1: float, z1: float, x2: float, y2: float, z2: float) -> float
¶
Euclidean distance between two points in 3-D space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1, y1, z1
|
First point. |
required | |
x2, y2, z2
|
Second point. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Distance. |
Example
round(distance_3d(0, 0, 0, 1, 2, 2), 6) 3.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
dodecahedron_surface_area(edge: float) -> float
¶
Compute the surface area of a regular dodecahedron.
SA = 3√(25 + 10√5) × edge²
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(dodecahedron_surface_area(1.0), 4) 20.6457
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
dodecahedron_volume(edge: float) -> float
¶
Compute the volume of a regular dodecahedron.
V = (15 + 7√5) / 4 × edge³
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(dodecahedron_volume(1.0), 4) 7.6631
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
ellipse_area(a: float, b: float) -> float
¶
Area of an ellipse: pi * a * b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Semi-major axis (> 0). |
required |
b
|
float
|
Semi-minor axis (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area. |
Example
round(ellipse_area(3, 2), 6) 18.849556
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
ellipse_eccentricity(a: float, b: float) -> float
¶
Eccentricity of an ellipse: e = sqrt(1 - (b/a)^2) where a >= b.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Semi-major axis (> 0). |
required |
b
|
float
|
Semi-minor axis (> 0, <= a). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Eccentricity in [0, 1). |
Example
round(ellipse_eccentricity(5, 3), 6) 0.8
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
ellipse_perimeter_approx(a: float, b: float) -> float
¶
Approximate perimeter of an ellipse using Ramanujan's second formula.
P ≈ pi(a+b)(1 + 3h/(10 + sqrt(4 - 3h))), h = ((a-b)/(a+b))^2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Semi-major axis (> 0). |
required |
b
|
float
|
Semi-minor axis (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Approximate perimeter. |
Example
round(ellipse_perimeter_approx(3, 2), 4) 15.8654
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
ellipsoid_volume(a: float, b: float, c: float) -> float
¶
Volume of an ellipsoid: (4/3) pi a b c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a, b, c
|
Semi-axes (all > 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Example
round(ellipsoid_volume(2, 3, 4), 4) 100.531
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
frustum_volume(r1: float, r2: float, height: float) -> float
¶
Volume of a frustum (truncated cone): (pi h / 3)(r1^2 + r1*r2 + r2^2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r1
|
float
|
Top radius (>= 0). |
required |
r2
|
float
|
Bottom radius (>= 0). |
required |
height
|
float
|
Height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Example
round(frustum_volume(2, 4, 5), 4) 146.608
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
haversine_distance(lat1: float, lon1: float, lat2: float, lon2: float, radius: float = 6371.0) -> float
¶
Great-circle distance between two points on a sphere (Haversine formula).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat1, lon1
|
Latitude and longitude of point 1 (degrees). |
required | |
lat2, lon2
|
Latitude and longitude of point 2 (degrees). |
required | |
radius
|
float
|
Sphere radius (default: Earth's mean radius in km). |
6371.0
|
Returns:
| Type | Description |
|---|---|
float
|
Distance in the same units as radius. |
Example
round(haversine_distance(40.7128, -74.0060, 51.5074, -0.1278), 0) 5570.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
heron_formula(a: float, b: float, c: float) -> float
¶
Area of a triangle from side lengths using Heron's formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a, b, c
|
Side lengths (all > 0, satisfying triangle inequality). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sides don't form a valid triangle. |
Example
heron_formula(3, 4, 5) 6.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
hyperbola_asymptotes(a: float, b: float) -> Tuple[float, float]
¶
Slopes of the asymptotes of x^2/a^2 - y^2/b^2 = 1.
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple (b/a, -b/a). |
Example
hyperbola_asymptotes(3, 4) (1.3333333333333333, -1.3333333333333333)
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
hyperbola_eccentricity(a: float, b: float) -> float
¶
Eccentricity of a hyperbola: e = sqrt(1 + (b/a)^2).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Semi-transverse axis (> 0). |
required |
b
|
float
|
Semi-conjugate axis (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Eccentricity (> 1). |
Example
round(hyperbola_eccentricity(3, 4), 6) 1.666667
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
icosahedron_surface_area(edge: float) -> float
¶
Compute the surface area of a regular icosahedron.
SA = 5√3 × edge²
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(icosahedron_surface_area(1.0), 4) 8.6603
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
icosahedron_volume(edge: float) -> float
¶
Compute the volume of a regular icosahedron.
V = (5(3 + √5) / 12) × edge³
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(icosahedron_volume(1.0), 4) 2.1817
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
law_of_cosines_angle(a: float, b: float, c: float) -> float
¶
Finds angle C opposite to side c using the law of cosines.
cos(C) = (a^2 + b^2 - c^2) / (2ab).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a, b, c
|
Side lengths forming a valid triangle. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Angle C in radians. |
Example
round(law_of_cosines_angle(3, 4, 5), 6) 1.570796
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
law_of_cosines_side(a: float, b: float, angle_c: float) -> float
¶
Finds side c using the law of cosines: c^2 = a^2 + b^2 - 2ab cos(C).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Side a. |
required |
b
|
float
|
Side b. |
required |
angle_c
|
float
|
Angle C opposite to side c, in radians. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Length of side c. |
Example
round(law_of_cosines_side(3, 4, math.pi / 2), 6) 5.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
law_of_sines_side(a: float, angle_a: float, angle_b: float) -> float
¶
Finds side b using the law of sines: b = a * sin(B) / sin(A).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Known side. |
required |
angle_a
|
float
|
Angle opposite to side a (radians). |
required |
angle_b
|
float
|
Angle opposite to the unknown side b (radians). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Length of side b. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sin(angle_a) == 0. |
Example
round(law_of_sines_side(5, math.pi / 6, math.pi / 3), 6) 8.660254
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
line_equation(x1: float, y1: float, x2: float, y2: float) -> Tuple[float, float, float]
¶
Returns coefficients (a, b, c) of the line ax + by + c = 0 through two points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1, y1
|
First point. |
required | |
x2, y2
|
Second point. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float, float]
|
Tuple (a, b, c). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the two points are identical. |
Example
line_equation(0, 0, 1, 1) (-1.0, 1.0, 0.0)
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
midpoint_2d(x1: float, y1: float, x2: float, y2: float) -> Tuple[float, float]
¶
Midpoint of the segment connecting two 2-D points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1, y1
|
First point. |
required | |
x2, y2
|
Second point. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple (mx, my). |
Example
midpoint_2d(0, 0, 4, 6) (2.0, 3.0)
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
midpoint_3d(x1: float, y1: float, z1: float, x2: float, y2: float, z2: float) -> Tuple[float, float, float]
¶
Midpoint of the segment connecting two 3-D points.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1, y1, z1
|
First point. |
required | |
x2, y2, z2
|
Second point. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float, float]
|
Tuple (mx, my, mz). |
Example
midpoint_3d(0, 0, 0, 2, 4, 6) (1.0, 2.0, 3.0)
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
octahedron_surface_area(edge: float) -> float
¶
Compute the surface area of a regular octahedron.
SA = 2√3 × edge²
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(octahedron_surface_area(1.0), 4) 3.4641
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
octahedron_volume(edge: float) -> float
¶
Compute the volume of a regular octahedron.
V = (√2 / 3) × edge³
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(octahedron_volume(1.0), 4) 0.4714
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
parabola_directrix(a: float) -> float
¶
Directrix of the parabola y = ax^2: y = -1/(4a).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Coefficient of x^2 (a != 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
y-coordinate of the directrix. |
Example
parabola_directrix(1) -0.25
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
parabola_focus(a: float) -> Tuple[float, float]
¶
Focus of the parabola y = ax^2: located at (0, 1/(4a)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Coefficient of x^2 (a != 0). |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple (0, 1/(4a)). |
Example
parabola_focus(1) (0, 0.25)
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
parallelogram_area(base: float, height: float) -> float
¶
Area of a parallelogram: base * height.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
float
|
Base length (> 0). |
required |
height
|
float
|
Height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area. |
Example
parallelogram_area(5, 3) 15.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
point_to_line_distance(px: float, py: float, a: float, b: float, c: float) -> float
¶
Distance from point (px, py) to the line ax + by + c = 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
px, py
|
Point coordinates. |
required | |
a, b, c
|
Line coefficients. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Perpendicular distance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a == 0 and b == 0. |
Example
round(point_to_line_distance(0, 0, 1, 1, -2), 6) 1.414214
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
polygon_area(vertices: List[Tuple[float, float]]) -> float
¶
Area of a simple polygon using the Shoelace formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
List[Tuple[float, float]]
|
List of (x, y) tuples in order. Minimum 3 vertices. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area >= 0. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than 3 vertices. |
Example
polygon_area([(0, 0), (4, 0), (4, 3), (0, 3)]) 12.0
Complexity: O(n)
Source code in shortfx/fxNumeric/geometry_functions.py
polygon_centroid(vertices: list[tuple[float, float]]) -> tuple[float, float]
¶
Compute the centroid of a simple polygon.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
list[tuple[float, float]]
|
List of (x, y) tuples forming the polygon (≥ 3 vertices). |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
Tuple (cx, cy) centroid coordinates. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If vertices is not a list. |
ValueError
|
If fewer than 3 vertices or polygon has zero area. |
Usage Example
polygon_centroid([(0, 0), (4, 0), (4, 3), (0, 3)]) (2.0, 1.5)
Complexity: O(n)
Source code in shortfx/fxNumeric/geometry_functions.py
prism_surface_area(base_area: float, base_perimeter: float, height: float) -> float
¶
Compute the surface area of a prism.
SA = 2·base_area + base_perimeter·height
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_area
|
float
|
Area of the base. |
required |
base_perimeter
|
float
|
Perimeter of the base. |
required |
height
|
float
|
Height of the prism. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If arguments ≤ 0. |
Usage Example
prism_surface_area(25.0, 20.0, 10.0) 250.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
prism_volume(base_area: float, height: float) -> float
¶
Compute the volume of a prism.
V = base_area × height
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_area
|
float
|
Area of the base. |
required |
height
|
float
|
Height of the prism. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If arguments ≤ 0. |
Usage Example
prism_volume(25.0, 10.0) 250.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
pyramid_surface_area(base_area: float, base_perimeter: float, slant_height: float) -> float
¶
Compute the surface area of a regular pyramid.
SA = base_area + (base_perimeter × slant_height) / 2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_area
|
float
|
Area of the base. |
required |
base_perimeter
|
float
|
Perimeter of the base. |
required |
slant_height
|
float
|
Slant height of the pyramid. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Total surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If any argument ≤ 0. |
Usage Example
pyramid_surface_area(16.0, 16.0, 5.0) 56.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
pyramid_volume(base_area: float, height: float) -> float
¶
Volume of a pyramid: (1/3) A_base h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_area
|
float
|
Area of the base (> 0). |
required |
height
|
float
|
Perpendicular height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Example
pyramid_volume(9, 4) 12.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
regular_polygon_area(n_sides: int, side: float) -> float
¶
Area of a regular n-sided polygon: (n s^2) / (4 tan(pi/n)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_sides
|
int
|
Number of sides (>= 3). |
required |
side
|
float
|
Side length (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area. |
Example
round(regular_polygon_area(6, 1), 6) 2.598076
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
regular_polygon_interior_angle(n: int) -> float
¶
Compute the interior angle of a regular n-gon in degrees.
angle = (n - 2) × 180 / n
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of sides (≥ 3). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Interior angle in degrees. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If n is not int. |
ValueError
|
If n < 3. |
Usage Example
regular_polygon_interior_angle(6) 120.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
regular_polygon_perimeter(n: int, side: float) -> float
¶
Compute the perimeter of a regular polygon.
P = n × side
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
Number of sides (≥ 3). |
required |
side
|
float
|
Side length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Perimeter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If n is not int or side is not numeric. |
ValueError
|
If n < 3 or side ≤ 0. |
Usage Example
regular_polygon_perimeter(6, 5.0) 30.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
rhombus_area(d1: float, d2: float) -> float
¶
Compute the area of a rhombus from its diagonals.
A = (d1 × d2) / 2
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d1
|
float
|
Length of first diagonal. |
required |
d2
|
float
|
Length of second diagonal. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area of the rhombus. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If either diagonal ≤ 0. |
Usage Example
rhombus_area(6.0, 8.0) 24.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
rhombus_perimeter(side: float) -> float
¶
Compute the perimeter of a rhombus.
P = 4 × side
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
side
|
float
|
Side length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Perimeter. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If side is not numeric. |
ValueError
|
If side ≤ 0. |
Usage Example
rhombus_perimeter(5.0) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
sector_area(radius: float, angle: float) -> float
¶
Area of a circular sector: (1/2) r^2 theta.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
angle
|
float
|
Central angle in radians (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area of the sector. |
Example
round(sector_area(2, math.pi / 2), 6) 3.141593
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
segment_area(radius: float, angle: float) -> float
¶
Area of a circular segment: (r^2/2)(theta - sin(theta)).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
angle
|
float
|
Central angle in radians (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area of the segment. |
Example
round(segment_area(2, math.pi), 6) 6.283185
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
shoelace_area(vertices: list[tuple[float, float]]) -> float
¶
Compute the area of a simple polygon using the shoelace formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
list[tuple[float, float]]
|
List of (x, y) tuples forming the polygon (≥ 3 vertices). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Absolute area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If vertices is not a list of tuples. |
ValueError
|
If fewer than 3 vertices. |
Usage Example
shoelace_area([(0, 0), (4, 0), (4, 3), (0, 3)]) 12.0
Complexity: O(n)
Source code in shortfx/fxNumeric/geometry_functions.py
slope_two_points(x1: float, y1: float, x2: float, y2: float) -> float
¶
Slope of the line through two points (y2-y1)/(x2-x1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1, y1
|
First point. |
required | |
x2, y2
|
Second point. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Slope m. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If x1 == x2 (vertical line). |
Example
slope_two_points(0, 0, 2, 4) 2.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
sphere_surface_area(radius: float) -> float
¶
Surface area of a sphere: 4 pi r^2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Example
round(sphere_surface_area(1), 6) 12.566371
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
sphere_volume(radius: float) -> float
¶
Volume of a sphere: (4/3) pi r^3.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Example
round(sphere_volume(1), 6) 4.18879
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
spherical_cap_surface_area(radius: float, height: float) -> float
¶
Compute the curved surface area of a spherical cap.
SA = 2π·R·h
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius of the sphere. |
required |
height
|
float
|
Height of the cap. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Curved surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If radius ≤ 0 or height not in (0, 2R]. |
Usage Example
round(spherical_cap_surface_area(5.0, 2.0), 4) 62.8319
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
spherical_cap_volume(radius: float, h: float) -> float
¶
Volume of a spherical cap: (pi h^2 / 3)(3R - h).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Sphere radius (> 0). |
required |
h
|
float
|
Height of cap (0 < h <= 2R). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If h <= 0 or h > 2*radius. |
Example
round(spherical_cap_volume(5, 2), 4) 54.4543
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
spherical_excess(a: float, b: float, c: float) -> float
¶
Spherical excess of a spherical triangle (L'Huilier's theorem).
The area of a spherical triangle on a unit sphere equals the spherical excess.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a, b, c
|
Arcs (sides) of the spherical triangle in radians. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Spherical excess E in radians. |
Example
round(spherical_excess(math.pi/2, math.pi/2, math.pi/2), 6) 1.570796
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
spherical_law_of_cosines(a: float, b: float, angle_c: float) -> float
¶
Spherical law of cosines: cos(c) = cos(a)cos(b) + sin(a)sin(b)cos(C).
All arcs and angles in radians.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Arc a (radians). |
required |
b
|
float
|
Arc b (radians). |
required |
angle_c
|
float
|
Angle C (radians). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Arc c (radians). |
Example
round(spherical_law_of_cosines(0.5, 0.6, 1.0), 6) 0.730989
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
stadium_area(radius: float, straight_length: float) -> float
¶
Compute the area of a stadium (discorectangle).
A = π·r² + 2·r·a
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
radius
|
float
|
Radius of the semicircular ends. |
required |
straight_length
|
float
|
Length of the straight sides. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not numeric. |
ValueError
|
If radius ≤ 0 or straight_length < 0. |
Usage Example
round(stadium_area(2.0, 5.0), 4) 32.5664
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
tetrahedron_surface_area(edge: float) -> float
¶
Compute the surface area of a regular tetrahedron.
SA = √3 × edge²
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(tetrahedron_surface_area(1.0), 4) 1.7321
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
tetrahedron_volume(edge: float) -> float
¶
Compute the volume of a regular tetrahedron.
V = edge³ / (6√2)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge
|
float
|
Edge length. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If edge is not numeric. |
ValueError
|
If edge ≤ 0. |
Usage Example
round(tetrahedron_volume(1.0), 4) 0.1179
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
torus_surface_area(major_r: float, minor_r: float) -> float
¶
Surface area of a torus: 4 pi^2 R r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
major_r
|
float
|
Major radius (> 0). |
required |
minor_r
|
float
|
Minor radius (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Surface area. |
Example
round(torus_surface_area(3, 1), 4) 118.4352
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
torus_volume(major_r: float, minor_r: float) -> float
¶
Volume of a torus: 2 pi^2 R r^2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
major_r
|
float
|
Distance from center of tube to center of torus (> 0). |
required |
minor_r
|
float
|
Radius of the tube (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Volume. |
Example
round(torus_volume(3, 1), 4) 59.2176
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
trapezoid_area(a: float, b: float, h: float) -> float
¶
Area of a trapezoid: (a + b) * h / 2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
First parallel side (> 0). |
required |
b
|
float
|
Second parallel side (> 0). |
required |
h
|
float
|
Height (> 0). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area. |
Example
trapezoid_area(3, 5, 4) 16.0
Complexity: O(1)
Source code in shortfx/fxNumeric/geometry_functions.py
triangle_area_vertices(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float) -> float
¶
Area of a triangle from its vertices using the Shoelace formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x1, y1
|
First vertex. |
required | |
x2, y2
|
Second vertex. |
required | |
x3, y3
|
Third vertex. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Area >= 0. |
Example
triangle_area_vertices(0, 0, 4, 0, 0, 3) 6.0
Complexity: O(1)