Skip to content

Instantly share code, notes, and snippets.

@cawka
Created March 17, 2022 18:10
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 cawka/2688a586f31c2f171178044155d21e51 to your computer and use it in GitHub Desktop.
Save cawka/2688a586f31c2f171178044155d21e51 to your computer and use it in GitHub Desktop.
import math
import numpy
from fractions import Fraction
m = [15.25, 16, 15.25, 16.75, 16, 15.25, 16.75, 16, 12.25, 3]
m_abs = []
runner = 0
for i in m:
runner += i
m_abs.append(runner)
print(m_abs)
slope = numpy.arctan(0.5/12)
print(f"Slope: {slope * 180 / math.pi} degreees (0.5\" in 12\")")
m_abs.append(144)
base_high = 96
# raise_total = base_high * numpy.tan(slope)
print(f"Total raise: {base_high * numpy.tan(slope)}")
class Frac:
def __init__(self, val, precision=1/16):
self.val = float(val)
self.precision = precision
def __str__(self):
whole = math.floor(self.val)
frac = self.val - whole
precision = [2.0, 4.0, 8.0, 16.0]
for p in precision:
r = math.floor(frac / (1.0 / p))
rem = frac - r * (1.0 / p)
if rem < self.precision:
break
if r > 0:
return f"{whole}~{r}/{round(p)}".rjust(10)
else:
return f"{whole}".rjust(10)
def __repr__(self):
return str(self)
runs = []
studs = []
studs_actual = []
for i in m_abs:
run = i / numpy.cos(slope)
runs.append(Frac(run))
stud = i * numpy.tan(slope)
studs.append(Frac(stud))
studs_actual.append(Frac(base_high - stud))
print("Base")
print([Frac(i) for i in m_abs])
print("\nRuns")
print(runs)
print("\nStuds extra/cut")
print(studs)
print("\nStuds actual")
print(studs_actual)
# base_high * numpy.tan(slope)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment