Author Topic: Polyline point  (Read 12235 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Polyline point
« on: July 03, 2012, 05:44:07 AM »
Hi!

I´m trying a little complicate topic for me with polylines. In the code I can read all GC10 on screen. Now I´m thinking if a polyline have a arc-segment I would like divide the arc-segment in 3 parts to get center-point and two arc-points (start and end point from arc I already have)
I don´t know to handle  vla-getBulge what it means ?

Command: (vla-getBulge (vlax-ename->vla-object ssn) z)
-3.42231

Can I calculate radius from that ?


Code: [Select]
(defun c:T (/
    ss
    ssn
    z
    i
    p
    s
    )
  (prompt "** << Select Polylines to export their coordinates >> **" )
  (if (setq ss (ssget '((0 . "POLYLINE,LWPOLYLINE"))))
    (progn
      (repeat (setq i (sslength ss))
(setq ssn (ssname ss (setq i (1- i)))
      z -1
      p (abs (fix (vlax-curve-getendparam ssn))))

(princ (strcat "\nPolyline " (itoa i) " have "  " " (itoa p) " segments\n"))
(repeat (1+ p)
  (princ
    (strcat "\n"
    (rtos (car (setq s (apply 'list (vlax-curve-getpointatparam ssn (setq z (1+ z)))))) 2)
    " "
    (rtos (cadr s) 2)
    " "
    (rtos (caddr s) 2)
    )
    )
  )
(princ "\n")
)
      )
    (princ)
    )
  (princ)
  )


fixo

  • Guest

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Polyline point
« Reply #2 on: July 03, 2012, 06:43:21 AM »
Basically a bulge means "How curved is the segment". A bulge value of 1.0 means it's a 180 degree arc starting and stopping at the vector's endpoints.

To see some samples look at the functions in my Library (line 320 should give you an idea): http://caddons.svn.sourceforge.net/viewvc/caddons/Libraries/Math.LSP?revision=65&view=markup

From there you get the degrees of curvature. And from that it's a geometrical calculation to get the center point from the two endpoints.

Edit: BTW, a very nice explanation of how bulges work: http://www.afralisp.net/archive/lisp/Bulges1.htm
« Last Edit: July 03, 2012, 07:13:29 AM by irneb »
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #3 on: July 03, 2012, 07:50:28 AM »
Thanks it all. I can continue...

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Polyline point
« Reply #4 on: July 03, 2012, 08:09:19 AM »
Here is my take on the subject:

http://lee-mac.com/bulgeconversion.html

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Polyline point
« Reply #5 on: July 03, 2012, 08:18:42 AM »
http://elpanov.com/index.php?id=35#eea-cen-lw-seg
Code - Auto/Visual Lisp: [Select]
  1. (defun eea-cen-lw-seg (p1 p2 b)
  2.                       ;|
  3. *****************************************************************************************
  4.  
  5. by ElpanovEvgeniy
  6.  
  7. &#1041;&#1080;&#1073;&#1083;&#1080;&#1086;&#1090;&#1077;&#1095;&#1085;&#1072;&#1103; &#1092;&#1091;&#1085;&#1082;&#1094;&#1080;&#1103;,
  8.  
  9. &#1056;&#1072;&#1076;&#1080;&#1091;&#1089; &#1080; &#1094;&#1077;&#1085;&#1090;&#1088; &#1076;&#1091;&#1075;&#1086;&#1074;&#1086;&#1075;&#1086; &#1089;&#1077;&#1075;&#1084;&#1077;&#1085;&#1090;&#1072; &#1087;&#1086;&#1083;&#1080;&#1083;&#1080;&#1085;&#1080;&#1080;, &#1079;&#1072;&#1076;&#1072;&#1085;&#1085;&#1086;&#1075;&#1086; &#1076;&#1074;&#1091;&#1084;&#1103; &#1090;&#1086;&#1095;&#1082;&#1072;&#1084;&#1080; &#1080; &#1082;&#1088;&#1080;&#1074;&#1080;&#1079;&#1085;&#1086;&#1081;
  10.  
  11. p1 - &#1085;&#1072;&#1095;&#1072;&#1083;&#1100;&#1085;&#1072;&#1103; &#1090;&#1086;&#1095;&#1082;&#1072; &#1076;&#1091;&#1075;&#1086;&#1074;&#1086;&#1075;&#1086; &#1089;&#1077;&#1075;&#1084;&#1077;&#1085;&#1090;&#1072;
  12. p2 - &#1082;&#1086;&#1085;&#1077;&#1095;&#1085;&#1072;&#1103; &#1090;&#1086;&#1095;&#1082;&#1072; &#1076;&#1091;&#1075;&#1086;&#1074;&#1086;&#1075;&#1086; &#1089;&#1077;&#1075;&#1084;&#1077;&#1085;&#1090;&#1072;
  13. b  - &#1082;&#1088;&#1080;&#1074;&#1080;&#1079;&#1085;&#1072; &#1076;&#1091;&#1075;&#1086;&#1074;&#1086;&#1075;&#1086; &#1089;&#1077;&#1075;&#1084;&#1077;&#1085;&#1090;&#1072; (&#1090;&#1072;&#1085;&#1075;&#1077;&#1085;&#1089; &#1095;&#1077;&#1090;&#1074;&#1077;&#1088;&#1090;&#1080; &#1094;&#1077;&#1085;&#1090;&#1088;&#1072;&#1083;&#1100;&#1085;&#1086;&#1075;&#1086; &#1091;&#1075;&#1083;&#1072; &#1076;&#1091;&#1075;&#1080;).
  14.  
  15. &#1044;&#1072;&#1090;&#1072; &#1089;&#1086;&#1079;&#1076;&#1072;&#1085;&#1080;&#1103;      2000 - 2005 &#1075;&#1086;&#1076;&#1099;
  16. *****************************************************************************************
  17.  
  18. Library function.
  19.  
  20. Radius and the centre of an arc segment of the polyline set by two points and bulge
  21.  
  22. p1 - start segment point
  23. p2 - end segment point
  24. b  - bulge is the tangent of 1/4 of the included angle for the arc segment
  25.  
  26. Date of creation   2000 - 2005 years.
  27. *****************************************************************************************
  28.  
  29. (setq e  (entsel "\n Specify a polyline, in the necessary arc segment...")
  30.       b  (cdr
  31.           (nth
  32.            (fix
  33.             (vlax-curve-getParamAtPoint (car e) (vlax-curve-getClosestPointTo (car e) (cadr e)))
  34.            ) ;_  fix
  35.            (vl-remove-if-not (function (lambda (x) (= (car x) 42))) (entget (car e)))
  36.           ) ;_  nth
  37.          ) ;_  cdr
  38.       p1 (fix
  39.           (vlax-curve-getParamAtPoint (car e) (vlax-curve-getClosestPointTo (car e) (cadr e)))
  40.          ) ;_  fix
  41.       p1 (vlax-curve-getPointAtParam (car e) d)
  42.       p2 (vlax-curve-getPointAtParam (car e) (1+ d))
  43. ) ;_  setq
  44.  
  45.    
  46. (eea-cen-lw-seg p1 p2 b)
  47.  
  48. *****************************************************************************************
  49. |;
  50.  ((lambda (a v r)
  51.    ((lambda (c s vx vy r)
  52.      (list (list (+ (* (- (* vx c) (* vy s)) r) (car p1))
  53.                  (+ (* (+ (* vx s) (* vy c)) r) (cadr p1))
  54.            ) ;_  list
  55.            r
  56.      ) ;_  list
  57.     ) ;_  lambda
  58.     (cos a)
  59.     (sin a)
  60.     (cos v)
  61.     (sin v)
  62.     r
  63.    )
  64.   ) ;_  lambda
  65.   (- 1.570796326794897 (* (atan b) 2.))
  66.   (angle p1 p2)
  67.   (/ (distance p1 p2) 2. (sin (* (atan b) 2.)))
  68.  )
  69. ) ;_  defun

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Polyline point
« Reply #6 on: July 03, 2012, 08:20:41 AM »
weird formatting Russian characters in the code ...  :-o

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #7 on: July 05, 2012, 04:33:38 AM »
Thanks for your examples. It´s realy complicate to understand your difficult codes

@lee-mac
Yes very good to try your codes... perfekt describtion

@fixo
It comes nearly what I want to do...

@Elpanov
Fantastic Giv me little time to do your lessons...

How can help me, I want know when I pick on a segment from polyline is it a line or arc segment


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Polyline point
« Reply #8 on: July 05, 2012, 05:15:41 AM »
How can help me, I want know when I pick on a segment from polyline is it a line or arc segment
One way would be to find the bulge value. You obtain the index of the picked segment by using the vlax-curve-* functions. In particular the vlax-curve-GetClosestPointTo to get the exact point on the polyline from the entsel's point value. Then you get the paramater at that point through vlax-curve-GetParamAtPoint. This value is a real, it's integer portion is the index of the previous vector point - so simply use fix to get the index of the selected vector.

Now get the bulge by using the ActiveX GetBulge method. So you'll need to change the ename of the polyline to a vla-object (vlax-ename->vla-object  ;) ). Then use (vla-GetBulge <vla-obj> <index>). If the value is anything else than 0.0 then it's a curve, otherwise it's a line.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Polyline point
« Reply #9 on: July 05, 2012, 05:42:52 AM »
Here's an example of what I mean:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:CheckPLArc (/ en eo)
  2.   (if (setq en (entsel "\nPick polyline segment: "))
  3.     (if (and (setq eo (vlax-ename->vla-object (car en)))
  4.              (eq (vla-get-ObjectName eo) "AcDbPolyline"))
  5.         (alert "That segment is a line.")
  6.         (alert "That segment is an arc."))
  7.       (alert "That's not a light-weight polyline")))
  8.   (princ))

And alternative method using only the vlax-curve functions and no ActiveX.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:CheckPLArc1 (/ en param)
  2.   (if (setq en (entsel "\nPick polyline segment: "))
  3.       (if (equal (angle (vlax-curve-GetPointAtParam (car en) (fix param)) (vlax-curve-GetPointAtParam (car en) (+ 0.5 (fix param))))
  4.                  (angle (vlax-curve-GetPointAtParam (car en) (fix param)) (vlax-curve-GetPointAtParam (car en) (1+ (fix param))))
  5.                  1e-12)
  6.         (alert "That segment is a line.")
  7.         (alert "That segment is an arc."))))
  8.   (princ))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Polyline point
« Reply #10 on: July 05, 2012, 07:22:31 AM »
And alternative method using only the vlax-curve functions and no ActiveX.
Code - Auto/Visual Lisp: [Select]
  1. (defun c:CheckPLArc1 (/ en param)
  2.   (if (setq en (entsel "\nPick polyline segment: "))
  3.       (if (equal (angle (vlax-curve-GetPointAtParam (car en) (fix param)) (vlax-curve-GetPointAtParam (car en) (+ 0.5 (fix param))))
  4.                  (angle (vlax-curve-GetPointAtParam (car en) (fix param)) (vlax-curve-GetPointAtParam (car en) (1+ (fix param))))
  5.                  1e-12)
  6.         (alert "That segment is a line.")
  7.         (alert "That segment is an arc."))))
  8.   (princ))

Alternatively,

Code - Auto/Visual Lisp: [Select]
  1. (defun c:CheckSeg ( / en )
  2.     (if
  3.         (and
  4.             (setq en (entsel "\nPick LWPolyline Segment: "))
  5.             (eq "LWPOLYLINE" (cdr (assoc 0 (entget (car en)))))
  6.         )
  7.         (if (equal '(0.0 0.0 0.0)
  8.                 (vlax-curve-getsecondderiv (car en)
  9.                     (vlax-curve-getparamatpoint (car en)
  10.                         (vlax-curve-getclosestpointto (car en) (trans (cadr en) 1 0))
  11.                     )
  12.                 )
  13.             )
  14.             (princ "\nSegment is a Line.")
  15.             (princ "\nSegment is an Arc.")
  16.         )
  17.         (princ "\nNothing Selected or Object is not an LWPolyline.")
  18.     )
  19.     (princ)
  20. )

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Polyline point
« Reply #11 on: July 05, 2012, 07:24:01 AM »
@lee-mac
Yes very good to try your codes... perfekt describtion

Thank you.

My methods are rather simple in comparison to Evgeniy, but I'm glad that my explanations were clear  :-)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: Polyline point
« Reply #12 on: July 05, 2012, 08:32:15 AM »
My methods are rather simple in comparison to Evgeniy, but I'm glad that my explanations were clear  :)
Lee, I really like this construct:
Code - Auto/Visual Lisp: [Select]
  1. (rem (+ pi pi (- ang2 ang1)) (+ pi pi))
A lot more elegant than my angle-Normal function  :kewl:

BTW, I've revamped my functions:
Code - Auto/Visual Lisp: [Select]
  1. (defun bulge->inclang (bulge /) (* 4. (atan bulge)))
  2.  
  3. (defun bulge->height (v1 bulge v2 /) (* (/ (distance v1 v2) 2.) (abs bulge)))
  4.  
  5. (defun bulge->radius  (v1 bulge v2 /)
  6.   (cond ((not (zerop bulge)) (abs (/ (/ (distance v1 v2) 2.) (sin (/ (bulge->inclang bulge) 2.)))))))
  7.  
  8. (defun midp (p1 p2 /) (mapcar (function (lambda (a b) (* (+ a b) 0.5))) p1 p2))
  9.  
  10. (defun bulge->center  (v1 bulge v2 / )
  11.   (cond ((or (zerop bulge) (equal bulge 1. 1e-16)) (midp v1 v2))
  12.         ((polar (midp v1 v2)
  13.                 ((if (> bulge 0.) + -) (angle v1 v2) (* pi 0.5))
  14.                 (- (bulge->radius v1 bulge v2) (bulge->height v1 bulge v2))))))
  15.  
  16. (defun bulge->arc (v1 bulge v2 / pC)
  17.   (list (setq pC (bulge->center v1 bulge v2))
  18.         (bulge->radius v1 bulge v2)
  19.         (angle pC v1)
  20.         (angle pC v2)))
  21.  
  22. (defun inclang->bulge (ang / ) ((lambda (a) (/ (sin a) (cos a))) (/ ang 4.)))
  23.  
  24. (defun arc->bulge (cP rad a1 a2 /)
  25.   (list (polar cP a1 rad)
  26.         (inclang->bulge (rem (+ pi pi (- a2 a1)) (+ pi pi)))
  27.         (polar cP a2 rad)))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: Polyline point
« Reply #13 on: July 05, 2012, 09:04:32 AM »
I´m impressed which different opportunities you have done. I´m not realy understand it all but It´s much stuff I can use and learn about "bulge " thanks so much for helping to all your are fantastic experts, I feel so smal with my Lisp-knowledge.

@irneb
how can I start your finally function ...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Polyline point
« Reply #14 on: July 05, 2012, 10:01:09 AM »
How can help me, I want know when I pick on a segment from polyline is it a line or arc segment

way to use acet-* :
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test (/ e)
  2.   (cond ((not (and (setq e (entsel "\nPick lwpolyline segment: ")) (= (cdadr (entget (car e))) "LWPOLYLINE"))
  3.          )
  4.          (princ "\n This is not lwpolyline!")
  5.         )
  6.                      (cadddr (ACET-PLINE-SEGMENT-LIST (entget (car e))))
  7.                 )
  8.          )
  9.          (princ "\n This is line segment.")
  10.         )
  11.         ((princ "\n This is arc segment."))
  12.   )
  13. )