;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/wood.el
;;
;; Where do you cut a piece of wood if the parts should be
;; length l and the blade is width b?
;;
;; For n cuts in n = 1, 2, ... the cuts should be at:
;;
;; l*n + (b/2)(2n - 1)
;;
;; So for 3 parts of 60 cm each and a 3 mm blade cuts are made
;; at 60.15, 120.45 and 180.75 cm.
(require 'cl-lib)
(defun cut-2 (len &optional n blade)
(or n (setq n 1))
(or blade (setq blade 0.3))
(when (> n 0)
(let ((hb (/ blade 2.0) ))
(+ (* len n)
(* hb (1- (* 2 n))) ))))
;; (cut-2 60 1) ; 60.15
;; (cut-2 60 2) ; 120.45
;; (cut-2 60 3) ; 180.75
;; (cut-2 60 4) ; 241.05
(defun cut (len &optional n blade)
(or n (setq n 3))
(or blade (setq blade 0.3))
(cl-loop repeat n
with cuts
with pos = 0
with hb = (/ blade 2.0)
do (cl-incf pos (+ len hb))
(push pos cuts)
(cl-incf pos hb)
finally return (nreverse cuts)) )
;; (cut 60 4) ; (60.15 120.45 180.75 241.05)
;; wall computation, cm
(when nil
(let*((bench-elevation 81.8)
(bench-side 250.0)
(board '(2.5 82.4 119.3))
(upright '(4.3 6.9)) )
(insert "\n\n")
(insert (format ";; bench elevation %.1f\n" bench-elevation))
(insert (format ";; bench side %.1f\n" bench-side))
(insert (format ";; board %.1fx%.1fx%.1f\n"
(car board)
(cadr board)
(caddr board) ))
(insert (format ";; upright %.1fx%.1fx%.1f"
(car upright)
(cadr upright)
(+ bench-elevation (cadr board)) )))
)
;; bench elevation 81.8
;; bench side 250.0
;; board 2.5x82.4x119.3
;; upright 4.3x6.9x164.2
;; Make a railing of equally big beams.
;;
;; Input the number of beams, the program will compute the
;; distance/space between each beam, then test for different
;; number of beams until a distance is outputted that
;; is reasonable.
(defun compute-space-distance (dist num-beams beam-width)
(let*((spaces (1+ num-beams))
(dist-covered (* num-beams beam-width))
(dist-uncovered (- dist dist-covered))
(space (/ dist-uncovered spaces 1.0) ))
space ))
;; (insert (format "\n;; %.2f" (compute-space-distance 262 16 12)))
;; 4.12
;;
;; (insert (format "\n;; %.2f" (compute-space-distance 262 17 12)))
;; 3.22
;; If one makes a grid out of beams of different sizes it
;; doesn't look asymmetric if you make the _holes_ equally
;; big (Works! see
;; https://dataswamp.org/~incal/work-photos/firewood-hut.jpg )
(defun compute-wood-distance (total beams)
(let*((sum-beam (apply #'+ beams) )
(space (- total sum-beam))
(num-holes (1+ (length beams)))
(hole-len (/ space num-holes)) )
(message "%.1f cm" hole-len) ))
;; (compute-wood-distance 139 '(6 7 9.5 9.5 9.5 9.5)) ;; 12.6 cm
;; (compute-wood-distance 28.7 '(4.9 4.8)) ;; 6.3 cm
(provide 'wood)