Author Topic: Need a lisp to get the coordinates of the center of an arc within a polyline  (Read 527 times)

0 Members and 1 Guest are viewing this topic.

tefached

  • Mosquito
  • Posts: 2
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
« Last Edit: April 24, 2022, 12:42:00 PM by tefached »

Lee Mac

  • Seagull
  • Posts: 12658
  • London, England
You're welcome to use my Bulge Conversion functions 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).

tefached

  • Mosquito
  • Posts: 2
wow this is amazing! this is exactly what i'm looking for thank you so much good sir!

iautolisp

  • Mosquito
  • Posts: 8
You're welcome to use my Bulge Conversion functions 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


« Last Edit: May 01, 2022, 02:44:28 AM by iautolisp »

mhupp

  • Newt
  • Posts: 136
Didn't run the code but your AUPREC is set to 0 that might affect the calculation.
« Last Edit: May 03, 2022, 02:49:58 PM by mhupp »

iautolisp

  • Mosquito
  • Posts: 8
I tried setting the value of AUPREC to 1, it still doesn't work

Lee Mac

  • Seagull
  • Posts: 12658
  • London, England
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. )


iautolisp

  • Mosquito
  • Posts: 8
thanks mac you are a genius at autolisp

ronjonp

  • Needs a day job
  • Posts: 7404
thanks mac you are a genius at autolisp
Yes he is.  :-)

Windows 11 x64 - AutoCAD /C3D 2022

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12658
  • London, England
You're both too kind  :-)