TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: ElpanovEvgeniy on February 20, 2007, 09:31:38 AM
-
You have a list of points:
(while (setq p (getpoint "\n Specify point: ")) (setq pt-list (cons p pt-list)))
Example:
(setq pt-list '((0. 5. 0.) (1. 10. 0.) (-2. 0. 10.) (-18. 3. -4.)))
;; Explanation - all point 3D
It is necessary to receive the dimensional container of this list
As vla-GetBoundingBox, only list point...
Write two programs:
The first program: - calculates 3D list point
(GetBoundingBox-3d pt-list) = >> '((-18.0 0.0 -4.0) (1.0 10.0 10.0))
;; Explanation - return '((min-X min-Y min-Z) (max-X max-Y max-Z))
The second program: - calculates 2D list point
(GetBoundingBox-2d pt-list) = >> '((-18.0 0.0) (1.0 10.0))
;; Explanation - return '((min-X min-Y) (max-X max-Y))
PS. Last time, I have written not clearly... :oops:
Ask also I shall explain once again! :-)
-
Hi,
Here's my contribution.
(defun GetBoundingBox-3d (pt_lst)
(list (apply 'mapcar (cons 'min pt_lst))
(apply 'mapcar (cons 'max pt_lst))
)
)
(defun GetBoundingBox-2d (pt_lst)
((lambda (l)
(list
(apply 'mapcar (cons 'min l))
(apply 'mapcar (cons 'max l))
)
)
(mapcar '(lambda (p) (list (car p) (cadr p))) pt_lst)
)
)
-
Hello gile!
My function GetBoundingBox-3d is identical to yours!
But my function GetBoundingBox-2d is easier than yours...
-
Another way for GetBoundingBox-2d
(defun GetBoundingBox-2d (pt_lst)
(mapcar '(lambda (p) (reverse (cdr (reverse p))))
(list
(apply 'mapcar (cons 'min l))
(apply 'mapcar (cons 'max l))
)
)
)
-
Already better! :)
-
Already better! :)
I wished to tell, that it is possible to reduce quantity of calculations...
-
Another way for GetBoundingBox-2d
(defun GetBoundingBox-2d (pt_lst)
(mapcar '(lambda (p) (reverse (cdr (reverse p))))
(list
(apply 'mapcar (cons 'min l))
(apply 'mapcar (cons 'max l))
)
)
)
my variant:
(defun GetBoundingBox-2d (pt_lst)
((lambda (l)
(list
(apply 'mapcar (cons 'min l))
(apply 'mapcar (cons 'max l))
) ;_ list
) ;_ lambda
(cons (list (caar pt_lst) (cadar pt_lst))
(cdr pt_lst)
) ;_ cons
)
) ;_ defun
-
Nice one, Evgeniy. :-)
I have to learn more about ((lambda ...) using :roll:
-
;; So, we can draw a box with these points...
(DEFUN _3dbbox (points_list / pa pb pc pd pe pf pg)
(IF (AND (= (LENGTH points_list) 2)
(= (TYPE (CAR points_list)) 'LIST)
(= (TYPE (CADR points_list)) 'LIST)
(= (LENGTH (CAR points_list)) 3)
(= (LENGTH (CADR points_list)) 3)
(/= (LAST (CAR points_list)) (LAST (CADR points_list)))
)
(PROGN (SETQ pa (CAR points_list)
pg (CADR points_list)
;;
pb (LIST (CAR pg) (CADR pa) (CADDR pa))
pc (LIST (CAR pg) (CADR pg) (CADDR pa))
pd (LIST (CAR pa) (CADR pg) (CADDR pa))
;;
pe (LIST (CAR pa) (CADR pa) (CADDR pg))
pf (LIST (CAR pb) (CADR pb) (CADDR pg))
ph (LIST (CAR pd) (CADR pd) (CADDR pg))
)
(COMMAND "_.PFACE")
(FOREACH x (LIST pa pb pc pd pe pf pg ph) (COMMAND "_NON" x))
(COMMAND "" ;
1 2 3 4 "" ;
5 6 7 8 "" ;
1 2 6 5 "" ;
2 3 7 6 "" ;
3 4 8 7 "" ;
4 1 5 8 "" ;
"")
)
nil
)
(PRINC)
)
;; Usage = (_3dbbox (list pa pb)) where pa and pb are 3d points, ie: (0 0 0) and (100 100 100)
-
Here's an old one by Tony Tanzillo. Obviously similar to code already posted, but I'm not sure about how it differs.
It works well for me.
;; Returns the lower left and upper right corners of a point list.
(defun extents (plist)
(list
(apply 'mapcar (cons 'min plist))
(apply 'mapcar (cons 'max plist))
)
)