Author Topic: Arc of a polyline  (Read 6638 times)

0 Members and 1 Guest are viewing this topic.

Coder

  • Swamp Rat
  • Posts: 827
Arc of a polyline
« on: December 01, 2011, 10:47:50 AM »
Hello .

I would like to know how to check if a Polyline has an arc among its segments and how to check if the Polyline is rectangle or with
straight segments .

Is it possible ?

Thank you in advance .

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Arc of a polyline
« Reply #1 on: December 01, 2011, 11:14:09 AM »
Here are two variations on a function that will return T if the supplied LWPolyline DXF data has non-zero bulge (i.e. the LWPolyline has one or more Arc segments):

Code: [Select]
(defun HasBulge ( elist / pair )
    (and (setq pair (assoc 42 elist))
         (or (not (equal 0.0 (cdr pair) 1e-10))
             (HasBulge (cdr (member pair elist)))
         )
    )
)

Code: [Select]
(defun HasBulge ( elist )
    (vl-some '(lambda ( pair ) (not (equal 0.0 (cdr pair) 1e-10))) elist)
)

e.g.:

Code: [Select]
(HasBulge (entget <LWPolyline Entity>))
« Last Edit: December 01, 2011, 11:18:34 AM by Lee Mac »

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Arc of a polyline
« Reply #2 on: December 01, 2011, 11:41:28 AM »
how to check if the Polyline is rectangle

Maybe something like:

Code: [Select]
(defun Rectangle-p ( ent / elist p1 p2 p3 p4 )
    (and
        (eq "LWPOLYLINE" (cdr (assoc 0 (setq elist (entget ent))))) ;; Is it an LWPolyline?
        (= 4 (cdr (assoc 90 elist))) ;; Does it have 4 vertices?
        (= 1 (logand 1 (cdr (assoc 70 elist)))) ;; Is it Closed?
        (not (HasBulge elist)) ;; Arc segments?
        (mapcar 'set '(p1 p2 p3 p4) ;; Collect the Vertices for further investigation
            (apply 'append
                (mapcar '(lambda ( pair ) (if (= 10 (car pair)) (list (cdr pair)))) elist)
            )
        )
        (equal (distance p1 p2) (distance p3 p4) 1e-8) ;; Two pairs of
        (equal (distance p1 p4) (distance p2 p3) 1e-8) ;; equal sides?
        (equal (distance p1 p3) (distance p2 p4) 1e-8) ;; Is it a parallelogram?
    )
)

(defun HasBulge ( elist / pair )
    (and (setq pair (assoc 42 elist))
         (or (not (equal 0.0 (cdr pair) 1e-10))
             (HasBulge (cdr (member pair elist)))
         )
    )
)

EDIT: Fixed DXF 70 check.
« Last Edit: December 01, 2011, 01:22:36 PM by Lee Mac »

Coder

  • Swamp Rat
  • Posts: 827
Re: Arc of a polyline
« Reply #3 on: December 01, 2011, 12:44:00 PM »
Thank you so much  :-)

What is the meaning of these ...

Code: [Select]
1e-8
and this
Code: [Select]
le-10

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Arc of a polyline
« Reply #4 on: December 01, 2011, 12:47:51 PM »
Shorthand for (expt 10.0 -8) and (expt 10.0 -10).
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Arc of a polyline
« Reply #5 on: December 01, 2011, 12:48:06 PM »
Thank you so much  :-)

What is the meaning of these ...

Code: [Select]
1e-8
and this
Code: [Select]
le-10

Scientific Notation

Code: [Select]
1e-8  =  0.00000001
1e-10 =  0.0000000001

Code: [Select]
(equal <expr1> <expr2> [fuzz])
fuzz
A real number defining the maximum amount by which expr1 and expr2 can differ and still be considered equal.

[ I should probably be more consistent with my tolerances... ]

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Arc of a polyline
« Reply #6 on: December 01, 2011, 01:21:53 PM »
how to check if the Polyline is rectangle

Maybe something like:
Code: [Select]
(eq (logand 1 (cdr (assoc 70 elist))) 1)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: Arc of a polyline
« Reply #7 on: December 01, 2011, 01:23:01 PM »
how to check if the Polyline is rectangle

Maybe something like:
Code: [Select]
(eq (logand 1 (cdr (assoc 70 elist))) 1)

Good catch, updated above  8-)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Arc of a polyline
« Reply #8 on: December 01, 2011, 01:25:02 PM »
how to check if the Polyline is rectangle

Maybe something like:
Code: [Select]
(eq (logand 1 (cdr (assoc 70 elist))) 1)

Good catch, updated above  8-)
One time at band camp, I caught someone in the office drawing a rectangle and wasn't aware of the rectangle command.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Arc of a polyline
« Reply #9 on: December 01, 2011, 01:27:32 PM »
Wee niggle: I prefer this coding style: (eq 1 (logand 1 (cdr (assoc 70 elist)))). To me it's clearer, especially when scanning thru lotsa of code. Mileages vary, 'twas mine. That aside, as noted: good catch. :)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Arc of a polyline
« Reply #10 on: December 01, 2011, 01:32:28 PM »
Wee niggle: I prefer this coding style: (eq 1 (logand 1 (cdr (assoc 70 elist)))). To me it's clearer, especially when scanning thru lotsa of code. Mileages vary, 'twas mine. That aside, as noted: good catch. :)
I just prefer to follow the same argument order as wcmatch so everything is formatted the same - looks cleaner to me when looking over.

eg.
Code: [Select]
((eq name "AcDbMText") blah blah)
((wcmatch (strcase name) "*LINE") blah blah)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Arc of a polyline
« Reply #11 on: December 01, 2011, 01:40:49 PM »
I see and salute your logic.

Mine stems from c/c++ coding where it's better to place literal comparisons on the left side, immediately catching an errant assignment due to a dropped equals sign:

// DOH!! c/c++ compiler allows (c# will catch it):
if (x = 1)
   do_stuff();

// All compilers will complain:
if (1 = x)
   do_stuff();

// Fixed:
if (1 == x)
   do_stuff();

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Arc of a polyline
« Reply #12 on: December 01, 2011, 01:47:09 PM »
That makes sense and I actually prefer to see the literal first, especially when the comparison is generally long-winded (logand 1 (cdr (assoc 70 elist))), but I stick with the forced argument placement of wcmatch because the mix and match irritates my OCD.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Arc of a polyline
« Reply #13 on: December 01, 2011, 01:49:37 PM »
lol, my "need to see" trumps my ocd :-D

♪♫ sung in the key of "gee" of course ♪♫

Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Arc of a polyline
« Reply #14 on: December 01, 2011, 01:54:35 PM »
 :-D
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox