Skip to content

Instantly share code, notes, and snippets.

@wolfmanjm
Last active October 23, 2020 12:40
Show Gist options
  • Save wolfmanjm/c40c35ff628f71e84da3a9ee10067116 to your computer and use it in GitHub Desktop.
Save wolfmanjm/c40c35ff628f71e84da3a9ee10067116 to your computer and use it in GitHub Desktop.
# calculates E volumetric value given widthxheightxlength
# Usage: width height length
if ARGV.size < 3
puts "Usage: width height length"
exit 1
end
$layer_width = ARGV[0].to_f
$layer_height = ARGV[1].to_f
$dist = ARGV[2].to_f
def calc_e(dist)
diameter = $layer_height
circle_area = (diameter ** 2) * Math::PI / 4.0
rectangular_width = $layer_width - diameter
extrusion_crosssection_area = (rectangular_width * $layer_height) + circle_area
volume = extrusion_crosssection_area * dist
volume
end
puts "for length #{$dist} E: #{calc_e($dist)}"
# if 3rd param is radius
c = 2.0 * Math::PI * $dist
puts "for radius #{$dist} circumferance #{c} E: #{calc_e(c)}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment