TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: tefached on April 24, 2022, 12:28:24 PM

Title: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: tefached on April 24, 2022, 12:28:24 PM
hi, anybody can help me get the coordinates of the center of an arc within a polyline?

i did my best to try to get it but i can't and i'm only able to get the radius using the bulge and pt1 and pt2 (ends of the arc)

added a picture for reference

thanks in advance
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: Lee Mac on April 24, 2022, 01:12:05 PM
You're welcome to use my Bulge Conversion functions (http://lee-mac.com/bulgeconversion.html) for this task - simply supply the two vertex coordinates and the bulge value to either my 'LM:Bulge->Arc' function (to obtain both the centre & radius), or my 'LM:BulgeCenter' function (to obtain only the centre).
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: tefached on April 24, 2022, 02:48:18 PM
wow this is amazing! this is exactly what i'm looking for thank you so much good sir!
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: iautolisp on May 01, 2022, 02:34:17 AM
You're welcome to use my Bulge Conversion functions (http://lee-mac.com/bulgeconversion.html) for this task - simply supply the two vertex coordinates and the bulge value to either my 'LM:Bulge->Arc' function (to obtain both the centre & radius), or my 'LM:BulgeCenter' function (to obtain only the centre).


Code - Auto/Visual Lisp: [Select]
  1. (defun c:ccm (/ os ss ent enx lst p1)
  2.   (setq os (getvar "osmode"))
  3.   (setvar "osmode" 0)
  4.   (setq ss (ssget "_+.:E:S" '((0 . "lwpolyline"))))
  5.   (setq
  6.     enx (entget (ssname ss 0))
  7.     lst (LM:lwvertices enx)
  8.     lst (mapcar
  9.           (function
  10.             (lambda (l1 l2 / b p q)
  11.               (setq p (cdr (assoc 10 l1))
  12.                     q (cdr (assoc 10 l2))
  13.                     b (cdr (assoc 42 l1))
  14.               )
  15.               (append
  16.                 (LM:bulgecentre p q b)
  17.                 (list (LM:bulgeradius p q b))
  18.               )
  19.             )
  20.           )
  21.           lst
  22.           (if (= 1 (logand 1 (cdr (assoc 70 enx))))
  23.             (append (cdr lst) (list (car lst)))
  24.             (cdr lst)
  25.           )
  26.         )
  27.   )
  28.   (setq p1 (list (caar lst) (cadar lst) 0))
  29.   (command "circle" p1 60)
  30.   (setvar "osmode" os)
  31.   (setvar "cmdecho" 1)
  32.   (princ)
  33. )
  34.  
  35.  
  36.  
  37. (defun LM:lwvertices (e)
  38.   (if (setq e (member (assoc 10 e) e))
  39.     (cons
  40.       (list
  41.         (assoc 10 e)
  42.         (assoc 40 e)
  43.         (assoc 41 e)
  44.         (assoc 42 e)
  45.       )
  46.       (LM:lwvertices (cdr e))
  47.     )
  48.   )
  49. )
  50.  
  51.  
  52. (defun LM:bulgeradius (p1 p2 b)
  53.   (/ (* (distance p1 p2) (1+ (* b b))) 4 (abs b))
  54. )
  55.  
  56.  
  57. (defun LM:bulgecentre (p1 p2 b)
  58.   (polar p1
  59.          (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b))))
  60.          (/ (* (distance p1 p2) (1+ (* b b))) 4 b)
  61.   )
  62. )
  63.  
  64.  

Hi Mac, I am using your function and it is correct for the most part, but I seem to have found an error, I found the wrong center point in this drawing test. I uploaded the code and drawings of the problem, please help to check, thank you


Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: mhupp on May 03, 2022, 12:59:57 PM
Didn't run the code but your AUPREC is set to 0 that might affect the calculation.
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: iautolisp on May 03, 2022, 11:45:24 PM
I tried setting the value of AUPREC to 1, it still doesn't work
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: Lee Mac on May 09, 2022, 03:53:36 PM
Given that the polyline vertices are represented with respect to the Object Coordinate System (OCS), the resulting centre point will also be expressed with respect to the OCS. As such, you'll need to express this relative to the UCS before supplying the point to the CIRCLE command (which expects a point relative to the UCS).

Simply change this:
Code - Auto/Visual Lisp: [Select]
  1.     (LM:bulgecentre p q b)
  2.     (list (LM:bulgeradius p q b))
  3. )

to:
Code - Auto/Visual Lisp: [Select]
  1.     (trans (LM:bulgecentre p q b) (cdr (assoc 210 enx)) 1)
  2.     (list (LM:bulgeradius p q b))
  3. )

Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: iautolisp on May 09, 2022, 11:59:15 PM
thanks mac you are a genius at autolisp
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: ronjonp on May 10, 2022, 10:16:19 AM
thanks mac you are a genius at autolisp
Yes he is.  :-)
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: Lee Mac on May 10, 2022, 03:03:36 PM
You're both too kind  :-)
Title: Re: Need a lisp to get the coordinates of the center of an arc within a polyline
Post by: Marc'Antonio Alessi on May 11, 2022, 04:21:27 AM
You're both too kind  :)
We are many more than two... Thanks Lee  :)   ;)