Created
December 17, 2020 17:27
-
-
Save oliverlee/36fe78fddf7b9a42d80f4367d6bf88b5 to your computer and use it in GitHub Desktop.
Determine rough estimates for material requirements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
"""Determine rough estimates for material requirements.""" | |
from dataclasses import dataclass | |
from sympy import Symbol | |
@dataclass | |
class Body: | |
width: Symbol | |
length: Symbol | |
height: Symbol | |
density: Symbol | |
@property | |
def mass(self): | |
return self.width * self.length * self.height * self.density | |
usage = f"""usage: {__file__} <width> <height> <mass> <wood_density> <weight_density> | |
Args: | |
width: Width of the block's square base [cm] | |
height: Height of the block [cm] | |
mass: Mass of the block [g] | |
wood_density: Density of the exterior wood material [g/cm3] | |
weight_density: Density of the interior weight material [g/cm3] | |
Calculate rough estimates for material requirements of a wood-block pattern | |
weight. | |
see: https://www.metermeter.dk/wood-block-pattern-weight.html | |
where: | |
s: Width of the cubic weight [cm] | |
t_x: Wall thickness of the wood exterior along its width [cm] | |
t_z: Wall thickness of the wood exterior along its height [cm] | |
""" | |
if __name__ == "__main__": | |
import sys | |
if len(sys.argv) < 6: | |
print(usage) | |
sys.exit(1) | |
width, height, mass, wood_density, weight_density = sys.argv[1:6] | |
from sympy import solve, symbols | |
w, h, m, rho1, rho2 = symbols("w h m ρ_1 ρ_2", real=True, positive=True) | |
s, tx, tz = deps = symbols("s t_x t_z", real=True, positive=True) | |
wood_exterior = Body(w, w, h, rho1) | |
wood_interior = Body(s, s, s, rho1) | |
weight = Body(s, s, s, rho2) | |
mass_constraint = wood_exterior.mass - wood_interior.mass + weight.mass - m | |
position_constraint_xy = 2 * tx + s - w | |
position_constraint_z = 2 * tz + s - h | |
equations = [ | |
eqn.subs( | |
{w: width, h: height, m: mass, rho1: wood_density, rho2: weight_density} | |
) | |
for eqn in (mass_constraint, position_constraint_xy, position_constraint_z) | |
] | |
soln = solve(equations, deps, dict=True,) | |
if not soln: | |
print("Unable to solve.") | |
sys.exit(1) | |
print(f"s: {soln[0][s]:.2f} cm") | |
print(f"t_x: {soln[0][tx]:.2f} cm") | |
print(f"t_z: {soln[0][tz]:.2f} cm") | |
sys.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment