Added API for using spool weight/length

This commit is contained in:
Donkie
2023-04-02 15:48:30 +02:00
parent b3ba3c1594
commit c31c3dea42
4 changed files with 107 additions and 3 deletions

19
spoolson/math.py Normal file
View File

@@ -0,0 +1,19 @@
"""Various math-related functions."""
import math
def weight_from_length(*, length: float, radius: float, density: float) -> float:
"""Calculate the weight of a piece of filament.
Args:
length (float): Filament length in mm
radius (float): Filament radius in mm
density (float): Density of filament material in g/cm3
Returns:
float: Weight in g
"""
volume_mm3 = length * math.pi * radius * radius
volume_cm3 = volume_mm3 / 1000
return density * volume_cm3