francesc Posted January 16, 2015 Posted January 16, 2015 How to determine if an irregular polygon is convex or concave with lisp. Thanks Quote
Lee Mac Posted January 16, 2015 Posted January 16, 2015 Test whether each set of three consecutive vertices follow a clockwise or anticlockwise path. For example: (defun convex-p ( lst ) (apply '= (mapcar 'LM:clockwise-p lst (cdr lst) (cddr lst))) ) ;; Clockwise-p - Lee Mac ;; Returns T if p1,p2,p3 are clockwise oriented (defun LM:Clockwise-p ( p1 p2 p3 ) (< (* (- (car p2) (car p1)) (- (cadr p3) (cadr p1))) (* (- (cadr p2) (cadr p1)) (- (car p3) (car p1))) ) ) Test program: (defun c:test ( / lst sel ) (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))) (progn (setq lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget (ssname sel 0))))) (convex-p (cons (last lst) lst)) ) ) ) 1 Quote
francesc Posted January 16, 2015 Author Posted January 16, 2015 many thanks for your contribution teacher Quote
GP_ Posted January 17, 2015 Posted January 17, 2015 My ~2 cents, if there aren't collinear points. (defun c:test ( / lst sel R L) (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))) (progn (setq lst (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) (entget (ssname sel 0))))) (mapcar '(lambda ( a b c ) (if (minusp (sin (- (angle a c) (angle a b)))) (setq R t) (setq L t)) ) lst (append (cdr lst) lst) (append (cddr lst) lst) ) (/= R L) ) ) ) Quote
francesc Posted February 9, 2015 Author Posted February 9, 2015 Good Morning. Executing this routine does not work if the polygon has rounded corners tells me that is not convex . help Quote
Lee Mac Posted February 9, 2015 Posted February 9, 2015 Good Morning. Executing this routine does not work if the polygon has rounded corners tells me that is not convex . help Simply include the mid-point of each arc segment in the list of points to be tested. Quote
francesc Posted February 9, 2015 Author Posted February 9, 2015 Lee And this is done as a teacher Quote
francesc Posted February 11, 2015 Author Posted February 11, 2015 No how. Please I need help on this topic Many thanks teacher Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.