Jump to content

Recommended Posts

Posted

How to determine if an irregular polygon is convex or concave

with lisp.

Thanks

Posted

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))
       )
   )
)

  • Like 1
Posted

many thanks for your contribution teacher

Posted

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)
       )
   )    
)

  • 4 weeks later...
Posted

Good Morning. Executing this routine does not work if the polygon has rounded corners tells me that is not convex . help

Posted
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.

Posted

No how.

Please I need help on this topic

Many thanks teacher

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...