Jump to content

Polyline


francesc

Recommended Posts

Not sure if you are looking for polylines with only the vertex on a circle, or polylines exactly like a circle (with bulges).

For the last hypothesis:

(defun is_circle (e / i o c1 c2 p1 p2)
 (setq i (vlax-curve-getendparam e)
       o T)
 (while (and (> i 0) o)
   (setq p1 (vlax-curve-getpointatparam e i)
         p2 (vlax-curve-getpointatparam e (setq i (1- i)))
         c1 (mapcar
              (if (minusp (vla-getbulge (vlax-ename->vla-object e) i)) '- '+)
              p2 (vlax-curve-getsecondderiv e i)
            )
         )
   (or
     (equal p1 p2 1e-
     (if (not c2) (setq c2 c1))
     (setq o (equal c1 c2 1e-)
     )
   )
 o
 )

(defun c:test ( / e)
 (if
   (setq e (ssget ":E:S" '((0 . "LWPOLYLINE"))))
   (if
     (is_circle (ssname e 0))
     (alert "Selected object lies on a CIRCLE")
     (alert "Not a circle")
     )
   )
 (princ)
 )

Link to comment
Share on other sites

Very good Stefan :thumbsup:

 

Here is a crude & unimaginative method:

(defun polycircle-p ( ent / _circle-p _vertexdata )

   (defun _vertexdata ( enx )
       (if (setq enx (member (assoc 10 enx) enx))
           (cons
               (list
                   (cdr (assoc 10 enx))
                   (cdr (assoc 42 enx))
               )
               (_vertexdata (cdr enx))
           )
       )
   )
   (defun _circle-p ( lst cn1 rd1 / ang cn2 rd2 )
       (or (not (cdr lst))
           (and
               (or (equal (caar lst) (caadr lst) 1e-
                   (and
                       (not (equal 0.0 (cadar lst) 1e-)
                       (setq ang (* 2 (atan (cadar lst)))
                             rd2 (/ (distance (caar lst) (caadr lst)) 2 (sin ang))
                             cn2 (polar (caar lst) (+ (- (/ pi 2) ang) (angle (caar lst) (caadr lst))) rd2)
                       )
                       (or (null cn1)
                           (and (equal cn1 cn2 1e- (equal rd1 rd2 1e-)
                       )
                       (_circle-p (cdr lst) cn2 rd2)
                   )
               )
           )
       )
   )
   (and
       (setq enx (entget ent))
       (= "LWPOLYLINE" (cdr (assoc 0 enx)))
       (= 1 (logand 1 (cdr (assoc 70 enx))))
       (cdr (setq lst (_vertexdata enx)))
       (_circle-p (cons (last lst) lst) nil nil)
   )
)

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