mechanics_functions¶
shortfx.fxNumeric.mechanics_functions
¶
Moments of inertia, centroids, and section properties.
Classical formulas for mass properties and centroids of common geometric shapes from Murray R. Spiegel's Mathematical Handbook of Formulas and Tables.
Functions¶
centroid_circular_sector(r: float, alpha: float) -> Tuple[float, float]
¶
Returns centroid distance from center of a circular sector.
For a sector of half-angle α symmetric about x-axis, centroid is at (2r sin(α)/(3α), 0).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Radius. |
required |
alpha
|
float
|
Half-angle of the sector in radians (0 < α <= π). |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Centroid as (x_c, 0). |
Example
x, _ = centroid_circular_sector(3, math.pi / 2) round(x, 6) 1.273240
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
centroid_cone(h: float) -> float
¶
Returns the height of the centroid of a solid cone above its base.
The centroid is at h/4 from the base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
h
|
float
|
Height of the cone. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Distance from base to centroid. |
Example
centroid_cone(12) 3.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
centroid_hemisphere(r: float) -> float
¶
Returns the height of the centroid of a solid hemisphere above the flat face.
The centroid is at 3r/8 from the base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Distance from flat face to centroid. |
Example
centroid_hemisphere(4) 1.5
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
centroid_polygon(vertices: List[Tuple[float, float]]) -> Tuple[float, float]
¶
Computes the centroid of a simple polygon using the Shoelace-derived formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
List[Tuple[float, float]]
|
Ordered list of (x, y) vertices (not repeated at end). |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Centroid as (x, y). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If polygon has fewer than 3 vertices or has zero area. |
Example
centroid_polygon([(0, 0), (4, 0), (4, 4), (0, 4)]) (2.0, 2.0)
Complexity: O(n)
Source code in shortfx/fxNumeric/mechanics_functions.py
centroid_semicircle(r: float) -> Tuple[float, float]
¶
Returns the centroid of a semicircle of radius r lying above the x-axis.
The centroid is at (0, 4r/(3π)) above the diameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Centroid as (0, y_c). |
Example
_, y = centroid_semicircle(3) round(y, 6) 1.273240
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
centroid_triangle(p1: Tuple[float, float], p2: Tuple[float, float], p3: Tuple[float, float]) -> Tuple[float, float]
¶
Computes the centroid of a triangle given its vertices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p1
|
Tuple[float, float]
|
First vertex (x, y). |
required |
p2
|
Tuple[float, float]
|
Second vertex (x, y). |
required |
p3
|
Tuple[float, float]
|
Third vertex (x, y). |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Centroid as (x, y). |
Example
centroid_triangle((0, 0), (6, 0), (0, 6)) (2.0, 2.0)
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
mass_moment_cone(m: float, r: float) -> float
¶
Mass moment of inertia of a solid cone about its axis.
I = (3/10)mr².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
float
|
Mass. |
required |
r
|
float
|
Base radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
mass_moment_cone(10, 2) 12.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
mass_moment_cylinder(m: float, r: float) -> float
¶
Mass moment of inertia of a solid cylinder about its axis.
I = mr²/2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
float
|
Mass. |
required |
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
mass_moment_cylinder(10, 2) 20.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
mass_moment_cylinder_transverse(m: float, r: float, h: float) -> float
¶
Mass moment of inertia of a solid cylinder about a transverse centroidal axis.
I = m(3r² + h²)/12.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
float
|
Mass. |
required |
r
|
float
|
Radius. |
required |
h
|
float
|
Height. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
round(mass_moment_cylinder_transverse(10, 2, 6), 6) 40.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
mass_moment_disk(m: float, r: float) -> float
¶
Mass moment of inertia of a thin uniform disk about its axis.
I = mr²/2 (same as solid cylinder about axis).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
float
|
Mass. |
required |
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
mass_moment_disk(10, 3) 45.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
mass_moment_hollow_sphere(m: float, r: float) -> float
¶
Mass moment of inertia of a thin hollow sphere about any diameter.
I = (2/3)mr².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
float
|
Mass. |
required |
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
round(mass_moment_hollow_sphere(10, 2), 6) 26.666667
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
mass_moment_rod(m: float, length: float) -> float
¶
Mass moment of inertia of a thin rod about its center (perpendicular axis).
I = mL²/12.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
float
|
Mass. |
required |
length
|
float
|
Length of the rod. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
round(mass_moment_rod(6, 4), 6) 8.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
mass_moment_sphere(m: float, r: float) -> float
¶
Mass moment of inertia of a solid sphere about any diameter.
I = (2/5)mr².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m
|
float
|
Mass. |
required |
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
mass_moment_sphere(10, 2) 16.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
moment_of_inertia_annulus(r_outer: float, r_inner: float) -> float
¶
Computes the area moment of inertia of an annulus (hollow circle) about a diameter.
I = π(R⁴ - r⁴)/4.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r_outer
|
float
|
Outer radius. |
required |
r_inner
|
float
|
Inner radius (< r_outer). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If r_inner >= r_outer. |
Example
round(moment_of_inertia_annulus(3, 2), 6) 50.267544
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
moment_of_inertia_circle(r: float) -> float
¶
Computes the area moment of inertia of a circle about a diameter.
I = πr⁴/4.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I. |
Example
round(moment_of_inertia_circle(2), 6) 12.566371
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
moment_of_inertia_ellipse(a: float, b: float) -> Tuple[float, float]
¶
Computes the area moments of inertia of an ellipse about its centroidal axes.
I_x = πab³/4 (about major axis), I_y = πa³b/4 (about minor axis).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Semi-axis along x. |
required |
b
|
float
|
Semi-axis along y. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple (I_x, I_y). |
Example
ix, iy = moment_of_inertia_ellipse(3, 2) (round(ix, 6), round(iy, 6)) (18.849556, 42.411501)
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
moment_of_inertia_rectangle(b: float, h: float) -> Tuple[float, float]
¶
Computes the area moments of inertia of a rectangle about centroidal axes.
I_x = bh³/12 (about horizontal axis), I_y = hb³/12 (about vertical axis).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
float
|
Width (base). |
required |
h
|
float
|
Height. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, float]
|
Tuple (I_x, I_y). |
Example
ix, iy = moment_of_inertia_rectangle(4, 6) (ix, iy) (72.0, 32.0)
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
moment_of_inertia_semicircle(r: float) -> float
¶
Computes the area moment of inertia of a semicircle about its diameter.
I = πr⁴/8.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
r
|
float
|
Radius. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I about the diameter. |
Example
round(moment_of_inertia_semicircle(2), 6) 6.283185
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
moment_of_inertia_triangle(b: float, h: float) -> float
¶
Computes the area moment of inertia of a triangle about its base.
I = bh³/12.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
float
|
Base length. |
required |
h
|
float
|
Height. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I about the base. |
Example
moment_of_inertia_triangle(6, 4) 32.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
moment_of_inertia_triangle_centroidal(b: float, h: float) -> float
¶
Computes the area moment of inertia of a triangle about its centroidal axis.
I = bh³/36.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
float
|
Base length. |
required |
h
|
float
|
Height. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia I about centroidal axis parallel to base. |
Example
round(moment_of_inertia_triangle_centroidal(6, 4), 6) 10.666667
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
parallel_axis_theorem(i_cm: float, m: float, d: float) -> float
¶
Applies the parallel axis theorem: I = I_cm + md².
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i_cm
|
float
|
Moment of inertia about the centroidal axis. |
required |
m
|
float
|
Mass (or area for second moment of area). |
required |
d
|
float
|
Distance between the two parallel axes. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Moment of inertia about the new parallel axis. |
Example
parallel_axis_theorem(8.0, 6, 3) 62.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
polar_moment_of_inertia(ix: float, iy: float) -> float
¶
Computes the polar moment of inertia J = I_x + I_y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ix
|
float
|
Moment of inertia about x-axis. |
required |
iy
|
float
|
Moment of inertia about y-axis. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Polar moment of inertia J. |
Example
polar_moment_of_inertia(72, 32) 104
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
radius_of_gyration(i: float, m: float) -> float
¶
Computes the radius of gyration k = sqrt(I/m).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
float
|
Moment of inertia. |
required |
m
|
float
|
Mass (or area). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Radius of gyration. |
Example
round(radius_of_gyration(48, 12), 6) 2.0
Complexity: O(1)
Source code in shortfx/fxNumeric/mechanics_functions.py
section_modulus(i: float, c: float) -> float
¶
Computes the section modulus S = I/c.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
i
|
float
|
Moment of inertia about the neutral axis. |
required |
c
|
float
|
Distance from neutral axis to extreme fiber. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Section modulus S. |
Example
section_modulus(72, 3) 24.0
Complexity: O(1)