Skip to content

Instantly share code, notes, and snippets.

@jayeye
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayeye/3a3d7c984b962ba8c7f3 to your computer and use it in GitHub Desktop.
Save jayeye/3a3d7c984b962ba8c7f3 to your computer and use it in GitHub Desktop.
Convert filament length to filament weight and vice versa
PLA = 1.24
ABS = 1.03
def _normalize_density(d):
"""Density can be specified as g/cm^3 (common way) or kg/m^3 (SI way).
Assumes we are not dealing with degenerate matter!
"""
return (d < 25) and (d * 1000) or d
def l2w(length, diameter=2.85, density=PLA):
"""length in meters to weight in kilograms."""
return length * (.785e-6 * diameter * diameter * _normalize_density(density))
def w2l(weight, diameter=2.85, density=PLA):
"""weight in kilograms to length in meters."""
return weight / (.785e-6 * diameter * diameter * _normalize_density(density))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment