;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; constrainted parametric pentagonal iceray ;; ;; ;; ;; haldane liew ;; ;; version 17.05.99 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; random number generator functions ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (setq *SeedRand* nil) ; initialize the global ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; (rand16) : generates a random number between 1 and 32767, ;; ;; that is, a positive 16 bit integer(defun rand16 ( / s ) ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun rand16 ( / s ) ; when this is used for the first time, initialize the seed ; from the system clock. (if (null *SeedRand*) (progn (setq s (getvar "date")) (setq *SeedRand* (fix (* 86400 (- s (fix s))))) ) ; progn ) ; if (setq *SeedRand* (+ (* *SeedRand* 1103515245) 12345)) ; trim off the bits left of the 16th bits (logand (/ *SeedRand* 65536) 32767) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; generates a random number between min and max. ;; ;; min and max must be a non-negative integer smaller than 32678. ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun rand (min max / r16 range quotient remainder result) (setq r16 (rand16)) ; random number smaller than 32678 (setq range (+ 1 (- max min))) ; number of integers to be produced (setq quotient (/ r16 range)) ; result in non-neg. integer (setq remainder (- r16 (* quotient range))) (setq result (+ min remainder)) result ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; general geometric functions ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; finds a random point such that it lies on a line between two points and ;; ;; is between low and high percentages. low and high need to be expressed ;; ;; as whole numbers. eg. 35% = 35. ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun pointBetween (first second low high / x1 y1 x2 y2 range rangenum x3 y3 delta_x delta_y ydiff xdiff m bhere) (setq x1 (car first) y1 (cadr first) x2 (car second) y2 (cadr second) range (rand low high)) (setq rangenum (float (* range 0.01))) (setq delta_x (* (abs (- x2 x1)) rangenum)) (if (> x2 x1) (setq x3 (+ x1 delta_x)) (setq x3 (- x1 delta_x)) ) (setq ydiff (- y2 y1)) (setq xdiff (- x2 x1)) (if (= xdiff 0) (progn (setq delta_y (* (abs (- y2 y1)) rangenum)) (if (> y2 y1) (setq y3 (+ y1 delta_y)) (setq y3 (- y1 delta_y)) ) ) (progn (setq m (/ ydiff xdiff)) (setq bhere (- (cadr second) (* m (car second)))) (setq y3 (+ (* m x3) bhere)) ) ) (list x3 y3) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; take an polyline entity and returns a list of the points. ;; ;; eg. ((0 1) (1 1) (1 0)) ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun entity_to_points (entity / index entity_info numsides) (setq index 12) (setq entity_info (entget entity)) (setq numsides (cdr (assoc 90 entity_info))) (repeat numsides (setq point (cdr (nth index entity_info))) (if (= index 12) (setq pointslist (cons point ())) (setq pointslist (cons point pointslist)) ) (setq index (+ index 4)) ) (reverse pointslist) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; 6 types of constrained parametric polygonal shapes. (a-f) ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun vpent_a (x y x_gridlen y_gridlen / origin topleft botright corner p0 p1 p2 p3 p4) (setq origin (list x y) topleft (list x (+ y y_gridlen)) botright (list (+ x x_gridlen) y) corner (list (+ x x_gridlen) (+ y y_gridlen))) (setq p0 (pointBetween origin topleft point0_ymin point0_ymax) p1 (pointBetween origin topleft point1_ymin point1_ymax) p2 (list (car (pointBetween origin botright point2_xmin point2_xmax)) (cadr (pointBetween origin topleft point2_ymin point2_ymax))) p3 (list (car (pointBetween origin botright point3_xmin point3_xmax)) (cadr (pointBetween origin topleft point3_ymin point3_ymax))) p4 (list (car (pointBetween origin botright point4_xmin point4_xmax)) (cadr (pointBetween origin topleft point4_ymin point4_ymax)))) (command "pline" p0 p1 p2 p3 p4 "c" ) ) (defun vpent_b (farleftpiece leftpiece / origin topright botleft corner p0 p1 p2 p3 p4 r_points l_points) (setq l_points (entity_to_points leftpiece)) (setq f_points (entity_to_points farleftpiece)) (setq temp (inters (nth 2 f_points) (nth 3 f_points) (nth 1 l_points) (nth 2 l_points) nil)) (setq p4 (inters (nth 2 l_points) (nth 3 l_points) temp (list (+ (car temp) 1) (cadr temp)) nil)) (setq x (+ (car p4) (* x_gridlen (* (+ point4_xmin point4_xmax) 0.5 0.01))) y (- (cadr p4) (* y_gridlen (* (+ point4_ymin point4_ymax) 0.5 0.01)))) (setq origin (list x y) topright (list x (+ y y_gridlen)) botleft (list (- x x_gridlen) y) corner (list (- x x_gridlen) (- y y_gridlen))) (setq p0 (pointBetween origin topright point0_ymin point0_ymax) p1 (pointBetween origin topright point1_ymin point1_ymax) p2 (list (car (pointBetween origin botleft point2_xmin point2_xmax)) (cadr (pointBetween origin topright point2_ymin point2_ymax)))) (setq midp (pointBetween p0 p1 47 53)) (setq p3 (inters midp (list (- (car midp) 1) (cadr midp)) p4 (nth 2 l_points) nil)) (while (< (car p3) (car (nth 1 l_points))) (setq midp (pointBetween (nth 1 l_points) (nth 2 l_points) 45 55)) (setq p3 (inters midp (list (car midp) (+ (cadr midp) 1)) p4 (nth 2 l_points) nil)) ) (command "pline" p0 p1 p2 p3 p4 "c" ) ) (defun vpent_c (rightpiece leftpiece lastpiece / xunit yunit r_points l_points x_points p0 p1 p2 p3 p4 midp p3option1 p3option2 origin topright botleft corner) (setq r_points (entity_to_points rightpiece) l_points (entity_to_points leftpiece) x_points (entity_to_points lastpiece)) (setq p0 (inters (nth 2 r_points) (nth 1 r_points) (nth 3 x_points) (list (car (nth 3 x_points)) (- (cadr (nth 3 x_points)) 1)) nil)) (setq p4 (inters (nth 2 r_points) (nth 1 r_points) (nth 3 l_points) (nth 2 l_points) nil)) (setq p1_range_updown (* (- point1_ymax point1_ymin) y_gridlen 0.5 0.01)) (setq p1_range_min (list (car p0) (- (cadr (nth 1 x_points)) p1_range_updown))) (setq p1_range_max (list (car p0) (+ (cadr (nth 1 x_points)) p1_range_updown))) (setq p1 (pointBetween p1_range_min p1_range_max 0 100)) (setq p2_range_updown (* (- point2_ymax point2_ymin) y_gridlen 0.5 0.01)) (setq p2_range_leftright (* (- point2_xmax point2_xmin) x_gridlen 0.5 0.01)) (setq p2_left_x (list (- (car p4) p2_range_leftright) (cadr p4))) (setq p2_right_x (list (+ (car p4) p2_range_leftright) (cadr p4))) (setq p2_xtemp (pointBetween p2_left_x p2_right_x 0 100)) (setq p2_up_y (list (car p2_xtemp) (+ (cadr (nth 2 x_points)) p2_range_updown))) (setq p2_down_y (list (car p2_xtemp) (- (cadr (nth 2 x_points)) p2_range_updown))) (setq p2 (pointBetween p2_down_y p2_up_y 0 100)) (setq p3 (list (car p1) (+ (cadr p1) 1))) (while (> (cadr p3) (cadr p1)) (setq p3_range_updown (* (- point3_ymax point3_ymin) y_gridlen 0.5 0.01)) (setq p3_range_min (list (car p0) (- (cadr (nth 3 x_points)) p3_range_updown))) (setq p3_range_max (list (car p0) (+ (cadr (nth 3 x_points)) p3_range_updown))) (setq midp (pointBetween p3_range_min p3_range_max 0 100)) (setq p3 (inters midp (list (- (car midp) 1) (cadr midp)) p4 (nth 2 l_points) nil)) ) (if (or (< (car p3) (car (nth 1 l_points))) (> (car p3) (car (nth 2 l_points)))) (progn (setq p3_leftright (pointBetween (nth 1 l_points) (nth 2 l_points) 45 55)) (setq p3 (inters p3_leftright (list (car p3_leftright) (+ (cadr p3_leftright) 1)) p4 (nth 2 l_points) nil)) ) ) (command "pline" p0 p1 p2 p3 p4 "c" ) ) (defun vpent_d (rightpiece lastpiece / r_points x_points p0 p1 p2 p3 p4 origin topright botleft corner temp1 temp2) (setq r_points (entity_to_points rightpiece) x_points (entity_to_points lastpiece)) (setq p0 (inters (nth 2 r_points) (nth 1 r_points) (nth 3 x_points) (list (car (nth 3 x_points)) (- (cadr (nth 3 x_points)) 1)) nil)) (setq p1 (list (car p0) (cadr (nth 1 x_points)))) (setq x (car p1) y (- (cadr p1) (* y_gridlen (+ point1_ymin point1_ymax) 0.5 0.01))) (setq origin (list x y) topright (list x (+ y y_gridlen)) botleft (list (- x x_gridlen) y) corner (list (- x x_gridlen) (- y y_gridlen))) (setq p2 (list (car (pointBetween origin botleft point2_xmin point2_xmax)) (cadr (pointBetween origin topright point2_ymin point2_ymax))) p3 (list (car (pointBetween origin botleft point3_xmin point3_xmax)) (cadr (pointBetween origin topright point3_ymin point3_ymax))) temp1 (pointBetween (list (- (car p2) (* x_gridlen 0.05)) (cadr p2)) (list (+ (car p2) (* x_gridlen 0.05)) (cadr p2)) 1 99) temp2 (list (car temp1) (- (cadr temp1) 1)) p4 (inters (nth 1 r_points) (nth 2 r_points) temp1 temp2 nil)) (command "pline" p0 p1 p2 p3 p4 "c" ) ) (defun vpent_e (leftpiece rightpiece / r_points l_points p0 p1 p2 p3 p4 x y origin topleft botright corner) (setq r_points (entity_to_points rightpiece) l_points (entity_to_points leftpiece)) (setq p4 (inters (nth 2 r_points) (nth 3 r_points) (nth 1 l_points) (nth 2 l_points) nil)) (setq x (- (car p4) (* x_gridlen (* (+ point4_xmin point4_xmax) 0.5 0.01))) y (- (cadr p4) (* y_gridlen (* (+ point4_ymin point4_ymax) 0.5 0.01)))) (setq origin (list x y) topleft (list x (+ y y_gridlen)) botright (list (+ x x_gridlen) y) corner (list (+ x x_gridlen) (+ y y_gridlen))) (setq len1 (abs (- (car (nth 1 l_points)) (car (nth 2 l_points)))) len2 (abs (- (car (nth 1 l_points)) (car (nth 3 l_points)))) high (* 100 (/ len2 len1))) (setq p0 (pointBetween (nth 1 l_points) (nth 2 l_points) 60 80)) (setq p1 (pointBetween p0 (list (car p0) (cadr topleft)) point1_ymin point1_ymax)) (setq midp (pointBetween p0 p1 47 53)) (setq p3 (inters midp (list (+ (car midp) 1) (cadr midp)) p4 (nth 2 r_points) nil)) (setq p2_range_updown (* (- point2_ymax point2_ymin) y_gridlen 0.5 0.01)) (setq p2_range_leftright (* (- point2_xmax point2_xmin) x_gridlen 0.5 0.01)) (setq p2_left_x (list (- (car p4) p2_range_leftright) (cadr p4))) (setq p2_right_x (list (+ (car p4) p2_range_leftright) (cadr p4))) (setq p2_xtemp (pointBetween p2_left_x p2_right_x 0 100)) (setq p2_up_y (list (car p2_xtemp) (+ (+ (- (cadr p3) (cadr p4)) (cadr p3)) p2_range_updown))) (setq p2_down_y (list (car p2_xtemp) (- (+ (- (cadr p3) (cadr p4)) (cadr p3)) p2_range_updown))) (setq p2 (pointBetween p2_down_y p2_up_y 0 100)) (if (> (car p3) (car (nth 1 r_points))) (progn (setq p3_leftright (pointBetween (nth 1 r_points) (nth 2 r_points) 20 80)) (setq p3 (inters p3_leftright (list (car p3_leftright) (+ (cadr p3_leftright) 1)) p4 (nth 2 r_points) nil)) ) ) (command "pline" p0 p1 p2 p3 p4 "c" ) ) (defun vpent_f (leftpiece rightpiece lastpiece / xunit yunit r_points l_points x_points p0 p1 p2 p3 p4 mid01 origin topright botleft corner) (setq r_points (entity_to_points rightpiece) l_points (entity_to_points leftpiece) x_points (entity_to_points lastpiece)) (setq p0 (inters (nth 2 l_points) (nth 1 l_points) (nth 3 x_points) (list (car (nth 3 x_points)) (- (cadr (nth 3 x_points)) 1)) nil)) (setq p4 (inters (nth 2 r_points) (nth 3 r_points) (nth 1 l_points) (nth 2 l_points) nil)) (setq p1_range_updown (* (- point1_ymax point1_ymin) y_gridlen 0.5 0.01)) (setq p1_range_min (list (car p0) (- (cadr (nth 1 x_points)) p1_range_updown))) (setq p1_range_max (list (car p0) (+ (cadr (nth 1 x_points)) p1_range_updown))) (setq p1 (pointBetween p1_range_min p1_range_max 0 100)) (setq p2 (list (car p1) (- (cadr p1) 1))) (while (< (cadr p2) (cadr p1)) (setq p2_range_updown (* (- point2_ymax point2_ymin) y_gridlen 0.5 0.01)) (setq p2_range_leftright (* (- point2_xmax point2_xmin) x_gridlen 0.5 0.01)) (setq p2_left_x (list (- (car p4) p2_range_leftright) (cadr p4))) (setq p2_right_x (list (+ (car p4) p2_range_leftright) (cadr p4))) (setq p2_xtemp (pointBetween p2_left_x p2_right_x 0 100)) (setq p2_up_y (list (car p2_xtemp) (+ (cadr (nth 2 x_points)) p2_range_updown))) (setq p2_down_y (list (car p2_xtemp) (- (cadr (nth 2 x_points)) p2_range_updown))) (setq p2 (pointBetween p2_down_y p2_up_y 0 100)) ) (setq p3_range_updown (* (- point3_ymax point3_ymin) y_gridlen 0.5 0.01)) (setq p3_range_min (list (car p0) (- (cadr (nth 3 x_points)) p3_range_updown))) (setq p3_range_max (list (car p0) (+ (cadr (nth 3 x_points)) p3_range_updown))) (setq midp (pointBetween p3_range_min p3_range_max 0 100)) (setq p3 (inters midp (list (+ (car midp) 1) (cadr midp)) p4 (nth 2 r_points) nil)) (if (or (> (car p3) (car (nth 1 r_points))) (< (car p3) (car (nth 2 r_points)))) (progn (setq p3_leftright (pointBetween (nth 1 r_points) (nth 2 r_points) 20 80)) (setq p3 (inters p3_leftright (list (car p3_leftright) (+ (cadr p3_leftright) 1)) p4 (nth 2 r_points) nil)) ) ) (command "pline" p0 p1 p2 p3 p4 "c" ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; flow control of each row or pentagonal shapes ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun firstrow (x_grid_origin y_grid_origin num_units ss_master / last_entity previouspoint) (command "ucs" "") (vpent_a x_grid_origin y_grid_origin x_gridlen y_gridlen) (setq last_entity (entlast)) (ssadd last_entity ss_master) (repeat (- num_units 1) (setq previouspoint (nth 3 (entity_to_points last_entity))) (vpent_a (car previouspoint) 0 x_gridlen y_gridlen) (setq last_entity (entlast)) (ssadd last_entity ss_master) ) ) (defun evenrow (num_units ss_master / rightindex leftindex last rightpiece leftpiece last_entity) (setq last (sslength ss_master)) (setq lastpiece (ssname ss_master (- last 1))) (setq lastlastpiece (ssname ss_master (- last 2))) (vpent_b lastlastpiece lastpiece) (setq last_entity (entlast)) (ssadd last_entity ss_master) (setq last (sslength ss_master)) (setq index 2) (repeat (- num_units 1) (setq rightindex (- last index) leftindex (- last index 1)) (setq rightpiece (ssname ss_master rightindex) leftpiece (ssname ss_master leftindex)) (vpent_c rightpiece leftpiece last_entity) (setq last_entity (entlast)) (ssadd last_entity ss_master) (setq index (+ index 1))) (vpent_d leftpiece last_entity) (setq last_entity (entlast)) (ssadd last_entity ss_master) ) (defun oddrow (num_units ss_master / last index rightindex leftindex rightpiece leftpiece last_entity) (setq last (sslength ss_master)) (setq rightpiece (ssname ss_master (- last 2)) leftpiece (ssname ss_master (- last 1))) (vpent_e leftpiece rightpiece) (setq last_entity (entlast)) (ssadd last_entity ss_master) (setq last (sslength ss_master)) (setq index 3) (repeat (- num_units 1) (setq rightindex (- last index 1) leftindex (- last index)) (setq rightpiece (ssname ss_master rightindex) leftpiece (ssname ss_master leftindex)) (vpent_f leftpiece rightpiece last_entity) (setq last_entity (entlast)) (ssadd last_entity ss_master) (setq index (+ index 1))) ) (defun make-vpent-iceray (x_numunits y_numunits x_gridlen y_gridlen / ss_master evenodd) (setq x_grid_origin 0 y_grid_origin 0) ;; parameters for points in grid. (setq point0_ymin 26 point0_ymax 28 point1_ymin 72 point1_ymax 74 point2_xmin 57 point2_xmax 59 point2_ymin 98 point2_ymax 100 point3_xmin 98 point3_xmax 100 point3_ymin 49 point3_ymax 51 point4_xmin 57 point4_xmax 59 point4_ymin 0 point4_ymax 2) (setq ss_master (ssadd)) (firstrow x_grid_origin y_grid_origin x_numunits ss_master) (setq evenodd 2) (repeat (- y_numunits 1) (if (= (rem evenodd 2) 0) (evenrow x_numunits ss_master) (oddrow x_numunits ss_master)) (setq evenodd (+ evenodd 1)) ) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; interface driver for program ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:cp-5iceray () ;; number of grids in the x and y direction (setq x_numunits (getint "\nX-dimension:")) (setq y_numunits (getint "\nY-dimension:")) ;; the dimensions of each grid (setq x_gridlen (getint "\nX-grid dimension:")) (setq y_gridlen (getint "\nY-grid dimension:")) (make-vpent-iceray x_numunits y_numunits x_gridlen y_gridlen) ) (defun c:demo () (make-vpent-iceray 10 10 38 42) )