;; ---------------------------------------------------- ;; half-hexagon grammar ;; april 10, 2001 ;; ;; program by Haldane Liew ;; for use with NITROS (developed by Takehiko Nagakura) ;; ;; adapted from "The Logic of Architecture" ;; by William Mitchell, p.143 ;; ---------------------------------------------------- ;; --------------------- ;; some useful utilities ;; --------------------- (defun tan (xradians) (/ (sin xradians) (cos xradians)) ) (defun deg->rad (xdegrees) (* pi (/ xdegrees 180.0)) ) ;; ----------------- ;; type declarations ;; ----------------- ;; explanation of variables ;; xo, yo, zo : origin point for the ucs ;; zaxis : direction of the z axis (1 or -) ;; rot : rotational angle for the ucs ;; width : width of the hexagon ;; height : height of the hexagon (nt_def_type "hal_terminal" 'hal_terminal '(("xo" . 0) ("yo" . 0) ("zo" . 0) ("zaxis" . 1) ("rot" . 0) ("width" . 30) ("height" . 10) )) (nt_add_seed_type "hal_terminal") (nt_def_type "hal_marker" 'hal_marker '(("xo" . 0) ("yo" . 0) ("zo" . 0) ("zaxis" . 1) ("rot" . 0) ("width" . 30) ("height" . 10) )) (nt_add_seed_type "hal_marker") (nt_def_type "hal_rule1" 'hal_rule1 '(("xo" . 0) ("yo" . 0) ("zo" . 0) ("zaxis" . 1) ("rot" . 0) ("width" . 30) ("height" . 10) )) (nt_def_type "hal_rule2" 'hal_rule2 '(("xo" . 0) ("yo" . 0) ("zo" . 0) ("zaxis" . 1) ("rot" . 0) ("width" . 30) ("height" . 10) )) (nt_def_type "hal_rule3" 'hal_rule3 '(("xo" . 0) ("yo" . 0) ("zo" . 0) ("zaxis" . 1) ("rot" . 0) ("width" . 30) ("height" . 10) )) (nt_def_type "hal_rule4" 'hal_rule4 '(("xo" . 0) ("yo" . 0) ("zo" . 0) ("zaxis" . 1) ("rot" . 0) ("width" . 30) ("height" . 10) )) ;; -------------------- ;; geometry definitions ;; -------------------- ;; how to draw terminal half hexagon (defun hal_terminal (xo yo zo zaxis rot width height / pointa pointb pointc pointd shape) (command "ucs" "world") (command "ucs" "za" (list xo yo zo) (list xo yo zaxis)) (command "ucs" "z" rot) (setq pointa (list 0 0 0) pointb (list width 0 0) pointc (polar pointb (angtof "120") (/ height (cos (deg->rad 30)))) pointd (polar pointa (angtof "60" ) (/ height (cos (deg->rad 30)))) ) (command "pline" pointa pointb pointc pointd "c") (setq shape (entlast)) (command "ucs" "world") shape ) ;; how to draw a marked half hexagon (defun hal_marker (xo yo zo zaxis rot width height / item1 item2 x_center y_center shape) (hal_terminal xo yo zo zaxis rot width height) (setq item1 (entlast)) (command "ucs" "world") (command "ucs" "za" (list xo yo zo) (list xo yo zaxis)) (command "ucs" "z" rot) (setq x_center (- width (* height (tan (deg->rad 30)))) y_center (/ height 3)) (command "circle" (list x_center y_center 0) 2.0) (setq item2 (entlast)) (command "ucs" "world") (setq shape (nt_make_ablock (list item1 item2))) shape ) ;; --------------------- ;; parameter definitions ;; --------------------- ;; mirror along the x-axis and translate in the x-axis. (defun hal_rule1 (xo yo zo zaxis rot width height / segment newpoint new_xo new_yo trap1_plist trap2_plist c1 c2) (command "ucs" "world") (command "ucs" "za" (list xo yo zo) (list xo yo zaxis)) (command "ucs" "z" rot) (setq segment (* height (tan (deg->rad 30)))) (setq newpoint (list (- width segment) height 0)) (setq new_xo (car (trans newpoint 1 0))) (setq new_yo (cadr (trans newpoint 1 0))) (command "ucs" "world") (setq trap1_plist (list (cons "xo" xo) (cons "yo" yo) (cons "zo" zo) (cons "zaxis" zaxis) (cons "rot" rot) (cons "width" width) (cons "height" height))) (setq trap2_plist (list (cons "xo" new_xo) (cons "yo" new_yo) (cons "zo" zo) (cons "zaxis" (* -1 zaxis)) (cons "rot" (+ (- 0 rot) 180)) (cons "width" width) (cons "height" height))) (setq c1 (list "hal_terminal" nil trap1_plist)) (setq c2 (list "hal_marker" nil trap2_plist)) (nt_composit (list c1 c2)) ) ;; a simple translate and rotation (defun hal_rule2 (xo yo zo zaxis rot width height / new_xo new_yo c1 c2 trap1_plist trap2_plist newpoint) (command "ucs" "world") (command "ucs" "za" (list xo yo zo) (list xo yo zaxis)) (command "ucs" "z" rot) (setq newpoint (list width 0 0)) (setq new_xo (car (trans newpoint 1 0))) (setq new_yo (cadr (trans newpoint 1 0))) (command "ucs" "world") (setq trap1_plist (list (cons "xo" xo) (cons "yo" yo) (cons "zo" zo) (cons "zaxis" zaxis) (cons "rot" rot) (cons "width" width) (cons "height" height))) (setq trap2_plist (list (cons "xo" new_xo) (cons "yo" new_yo) (cons "zo" zo) (cons "zaxis" zaxis) (cons "rot" (+ rot 60)) (cons "width" width) (cons "height" height))) (setq c1 (list "hal_terminal" nil trap1_plist)) (setq c2 (list "hal_marker" nil trap2_plist)) (nt_composit (list c1 c2)) ) ;; mirror the shape along the x-axis (defun hal_rule3 (xo yo zo zaxis rot width height / newpoint new_xo new_yo trap1_plist trap2_plist c1 c2) (command "ucs" "world") (command "ucs" "za" (list xo yo zo) (list xo yo zaxis)) (command "ucs" "z" rot) (setq newpoint (list 0 0 0)) (setq new_xo (car (trans newpoint 1 0))) (setq new_yo (cadr (trans newpoint 1 0))) (command "ucs" "world") (setq trap1_plist (list (cons "xo" xo) (cons "yo" yo) (cons "zo" zo) (cons "zaxis" zaxis) (cons "rot" rot) (cons "width" width) (cons "height" height))) (setq trap2_plist (list (cons "xo" new_xo) (cons "yo" new_yo) (cons "zo" zo) (cons "zaxis" (* -1 zaxis)) (cons "rot" (+ (- 0 rot) 180)) (cons "width" width) (cons "height" height))) (setq c1 (list "hal_terminal" nil trap1_plist)) (setq c2 (list "hal_marker" nil trap2_plist)) (nt_composit (list c1 c2)) ) ;; change the marker to terminal (defun hal_rule4 (xo yo zo zaxis rot width height / trap1_plist c1) (setq trap1_plist (list (cons "xo" xo) (cons "yo" yo) (cons "zo" zo) (cons "zaxis" zaxis) (cons "rot" rot) (cons "width" width) (cons "height" height))) (setq c1 (list "hal_terminal" nil trap1_plist)) (nt_composit (list c1)) ) ;; --------------------------- ;; transformation declarations ;; --------------------------- (nt_def_trans '("hal_marker") "hal_rule1" 'hal_make_rule1 nil 'replace) (nt_def_trans '("hal_marker") "hal_rule2" 'hal_make_rule2 nil 'replace) (nt_def_trans '("hal_marker") "hal_rule3" 'hal_make_rule3 nil 'replace) (nt_def_trans '("hal_marker") "hal_rule4" 'hal_make_rule4 nil 'replace) ;; --------------------------- ;; transformation declarations ;; --------------------------- (defun hal_make_rule1 (trapzoid_list trans_list / trapzoid_plist c_plist) (setq trap_plist (nt_plist (car trapzoid_list))) (setq c_plist (list (cons "xo" (nt_val "xo" trap_plist)) (cons "yo" (nt_val "yo" trap_plist)) (cons "zo" (nt_val "zo" trap_plist)) (cons "zaxis" (nt_val "zaxis" trap_plist)) (cons "rot" (nt_val "rot" trap_plist)) (cons "width" (nt_val "width" trap_plist)) (cons "height" (nt_val "height" trap_plist)) )) (list nil c_plist) ) (defun hal_make_rule2 (trapzoid_list trans_list / trapzoid_plist c_plist) (setq trap_plist (nt_plist (car trapzoid_list))) (setq c_plist (list (cons "xo" (nt_val "xo" trap_plist)) (cons "yo" (nt_val "yo" trap_plist)) (cons "zo" (nt_val "zo" trap_plist)) (cons "zaxis" (nt_val "zaxis" trap_plist)) (cons "rot" (nt_val "rot" trap_plist)) (cons "width" (nt_val "width" trap_plist)) (cons "height" (nt_val "height" trap_plist)) )) (list nil c_plist) ) (defun hal_make_rule3 (trapzoid_list trans_list / trapzoid_plist c_plist) (setq trap_plist (nt_plist (car trapzoid_list))) (setq c_plist (list (cons "xo" (nt_val "xo" trap_plist)) (cons "yo" (nt_val "yo" trap_plist)) (cons "zo" (nt_val "zo" trap_plist)) (cons "zaxis" (nt_val "zaxis" trap_plist)) (cons "rot" (nt_val "rot" trap_plist)) (cons "width" (nt_val "width" trap_plist)) (cons "height" (nt_val "height" trap_plist)) )) (list nil c_plist) ) (defun hal_make_rule4 (trapzoid_list trans_list / trapzoid_plist c_plist) (setq trap_plist (nt_plist (car trapzoid_list))) (setq c_plist (list (cons "xo" (nt_val "xo" trap_plist)) (cons "yo" (nt_val "yo" trap_plist)) (cons "zo" (nt_val "zo" trap_plist)) (cons "zaxis" (nt_val "zaxis" trap_plist)) (cons "rot" (nt_val "rot" trap_plist)) (cons "width" (nt_val "width" trap_plist)) (cons "height" (nt_val "height" trap_plist)) )) (list nil c_plist) ) ;; ----------- ;; end of file ;; -----------