examples/mesa.ss
#lang scheme

(require "../main.ss")
(require "../autocad.ss")

;; Algorithm
;; 5 points for the feet
;; Pentagon for the top (bigger, rotated)
;; extrude feet.

;; (table-top (xyz 0 0 0) 3 5 0.3)
;; table-top: (c,r,s,h)
;; c: center of the lower plane of the table top.
(define (table-top center radius sides height)
  (do-extrude (make-polygon center radius sides)
              height))

;; (table-feet (xyz 0 0 0) 2 5 4)
;; table-feet: (c,r,s,h)
;; c: center of the plane that contains the base of the feet.
(define (table-feet base-c radius sides height tortion)
  (define (draw-leg from to) ;; do-extrude . make-line => should it aplpy make-region automatically? (maybe warn)
    (do-extrude (make-region (make-polygon from (/ height 10) sides))
                from to))
  (let ([high-points (polygon-points (+z base-c height) radius sides)]
        [low-points (map (rotate-by z-axis tortion) ;; rotate-by axis angle (list of points) ?? Que tal?
                         (polygon-points base-c radius sides))])
    (apply unite (map draw-leg low-points high-points)))) ;; apply unite + map function... common?


(define (table c radius sides height height-top-factor tortion)
  (unite
   (table-top (+z c (+ height (* height height-top-factor))) radius sides (* height height-top-factor))
   (table-feet c (* radius 2/3) sides height tortion)))