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
Need a lisp to get the coordinates of the center of an arc within a polyline
« 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
« Last Edit: April 24, 2022, 12:42:00 PM by tefached »

Lee Mac

• Seagull
• Posts: 12658
• London, England
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #1 on: April 24, 2022, 01:12:05 PM »
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
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #2 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!

iautolisp

• Mosquito
• Posts: 8
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #3 on: May 01, 2022, 02:34:17 AM »
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.             (lambda (l1 l2 / b p q)
10.               (setq p (cdr (assoc 10 l1))
11.                     q (cdr (assoc 10 l2))
12.                     b (cdr (assoc 42 l1))
13.               )
14.                 (LM:bulgecentre p q b)
15.                 (list (LM:bulgeradius p q b))
16.               )
17.             )
18.           )
19.           lst
20.           (if (= 1 (logand 1 (cdr (assoc 70 enx))))
21.             (append (cdr lst) (list (car lst)))
22.             (cdr lst)
23.           )
24.         )
25.   )
26.   (setq p1 (list (caar lst) (cadar lst) 0))
27.   (command "circle" p1 60)
28.   (setvar "osmode" os)
29.   (setvar "cmdecho" 1)
30.   (princ)
31. )
32.
33.
34.
35. (defun LM:lwvertices (e)
36.   (if (setq e (member (assoc 10 e) e))
37.     (cons
38.       (list
39.         (assoc 10 e)
40.         (assoc 40 e)
41.         (assoc 41 e)
42.         (assoc 42 e)
43.       )
44.       (LM:lwvertices (cdr e))
45.     )
46.   )
47. )
48.
49.
50. (defun LM:bulgeradius (p1 p2 b)
51.   (/ (* (distance p1 p2) (1+ (* b b))) 4 (abs b))
52. )
53.
54.
55. (defun LM:bulgecentre (p1 p2 b)
56.   (polar p1
57.          (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b))))
58.          (/ (* (distance p1 p2) (1+ (* b b))) 4 b)
59.   )
60. )
61.
62.

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
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #4 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.
« Last Edit: May 03, 2022, 02:49:58 PM by mhupp »

iautolisp

• Mosquito
• Posts: 8
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #5 on: May 03, 2022, 11:45:24 PM »
I tried setting the value of AUPREC to 1, it still doesn't work

Lee Mac

• Seagull
• Posts: 12658
• London, England
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #6 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. )

iautolisp

• Mosquito
• Posts: 8
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #7 on: May 09, 2022, 11:59:15 PM »
thanks mac you are a genius at autolisp

ronjonp

• Needs a day job
• Posts: 7404
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #8 on: May 10, 2022, 10:16:19 AM »
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
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #9 on: May 10, 2022, 03:03:36 PM »
You're both too kind

Marc'Antonio Alessi

• Swamp Rat
• Posts: 1305
• Marco
Re: Need a lisp to get the coordinates of the center of an arc within a polyline
« Reply #10 on: May 11, 2022, 04:21:27 AM »
You're both too kind
We are many more than two... Thanks Lee