Jump to content

convex or concave


francesc

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 4 weeks later...
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.

Link to comment
Share on other sites

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