Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get center of 2 arcs that forms a circle

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
JCprog
507 Views, 9 Replies

Get center of 2 arcs that forms a circle

Hello everyone 🙂

 

I have this circle-like entity which is really two arcs facing together and joined. So when I select it says "Polyline" but it still have its "center". There are thousands of these in one drawing and they are not individual blocks either. What I need is a routine to place "Point" in the center of each circle-like objects perhaps I can say center of arcs (but that would place two points in each objects coz they're actually two arcs joined together).

 

Please help.......Thanks in advance 🙂

 

9 REPLIES 9
Message 2 of 10
Kent1Cooper
in reply to: JCprog


@JCprog wrote:

... 

I have this circle-like entity which is really two arcs facing together and joined. So when I select it says "Polyline" but it still have its "center". There are thousands of these in one drawing and they are not individual blocks either. What I need is a routine to place "Point" in the center of each circle-like objects perhaps I can say center of arcs (but that would place two points in each objects coz they're actually two arcs joined together).

.... 


If converting them to true Circles will get you started, try out the P2C command in CirclePolylineSwap.lsp, here.  If you need them to remain as multi-arc-segment Polylines [for example, if they have width, which Circles can't have], I'm sure it would not be difficult to place Points at the center of each, without ending up with one for each arc segment.

Kent Cooper, AIA
Message 3 of 10
JCprog
in reply to: Kent1Cooper

I dont think thats going to work as these entities are all over the drawing with so many other objects so selection is like needle in a haystack. They're not on their own layer as well. Isolating these objects is quite tricky.

 

I cant download to the link u provided. Probly u can attach it here instead.

Message 4 of 10
Kent1Cooper
in reply to: JCprog


@JCprog wrote:

I dont think thats going to work as these entities are all over the drawing with so many other objects so selection is like needle in a haystack. They're not on their own layer as well. Isolating these objects is quite tricky.

 

I cant download to the link u provided. Probly u can attach it here instead.


The link just worked for me, but whatever the problem, here's the file.  I don't think isolation is as tricky as you expect.  It [or an independent routine] could certainly be made to find all Polylines in the drawing for you, narrow them down to just those with only arc segments, and then go into the evaluation of whether they are circular, and finally with only those, either convert them to Circles to get their centers, or find the Polylines' centers directly, to use for Point placement.

 

EDIT:  Are they always all two-equal-half-circle-arc-segment Polylines, such as those made by the Donut command?  In that case, both the narrowing down to the right ones [to isolate those from, say, Revcloud Polylines which are also all arc segments] and the finding of their centers [halfway between the two vertices] would be greatly simplified.

Kent Cooper, AIA
Message 5 of 10
Lee_Mac
in reply to: JCprog

Here's a quick snippet of code which should perform as required:

 

(defun c:pcen ( / e i s )
    (if (setq s (ssget '((0 . "LWPOLYLINE") (90 . 2) (-4 . "<NOT") (42 . 0.0) (-4 . "NOT>"))))
        (repeat (setq i (sslength s))
            (setq e (entget (ssname s (setq i (1- i)))))
            (entmake
                (list '(0 . "POINT")
                    (cons 10
                        (LM:bulgecentre
                            (cdr (assoc 10 e))
                            (cdr (assoc 10 (reverse e)))
                            (cdr (assoc 42 e))
                        )
                    )
                )
            )
        )
    )
    (princ)
)

;; Bulge Centre  -  Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b  - bulge
;; Returns the centre of the arc described by the given bulge and vertices
 
(defun LM:BulgeCentre ( p1 p2 b )
    (polar p1
        (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b))))
        (/ (* (distance p1 p2) (1+ (* b b))) 4 b)
    )
)
(princ)

 

Message 6 of 10
JCprog
in reply to: Lee_Mac

Thanks for the code Lee! as always.....worked perfect! Smiley Very Happy

Message 7 of 10
JCprog
in reply to: Kent1Cooper

Thanks for attaching the file Kent I'll give it a try as well
Message 8 of 10
Lee_Mac
in reply to: JCprog

JCprog wrote:

Thanks for the code Lee! as always.....worked perfect! Smiley Very Happy

 

You're welcome!

Message 9 of 10
Kent1Cooper
in reply to: Lee_Mac


@Lee_Mac wrote:

Here's a quick snippet of code which should perform as required:

.... 


This may be only a possibility, but just be aware...  The ones at which the OP wants center Points added won't be like the ones in this image, but if there are any others like these [either closed with two arc segments (yellow) but not circular, or open with one arc segment (red)], as I read the routine it will also find those, and place Points at the center of [in the case of the yellow ones, one of the bulges of] each of them, too.  The evaluation of whether a two-vertex-arc-segments-only Polyline is circular is a little more complicated.

 

NonCircular2VertexArcPolylines.png

Kent Cooper, AIA
Message 10 of 10
Lee_Mac
in reply to: Kent1Cooper

Kent1Cooper wrote:
Lee_Mac wrote:

Here's a quick snippet of code which should perform as required:

.... 

This may be only a possibility, but just be aware...  The ones at which the OP wants center Points added won't be like the ones in this image, but if there are any others like these [either closed with two arc segments (yellow) but not circular, or open with one arc segment (red)], as I read the routine it will also find those, and place Points at the center of [in the case of the yellow ones, one of the bulges of] each of them, too.  The evaluation of whether a two-vertex-arc-segments-only Polyline is circular is a little more complicated.

 

My original code was only quickly written; but restricting the user selection to permit only two equal complementary arcs should be a simple modification of the selection filter list, for example:

 

 

(defun c:pcen ( / e i s )
    (if (setq s
            (ssget
               '(   (0 . "LWPOLYLINE")
                    (90 . 2)
                    (-4 . "<OR")
                        (-4 . "<NOT") (-4 . "<>") (42 .  1.0) (-4 . "NOT>")
                        (-4 . "<NOT") (-4 . "<>") (42 . -1.0) (-4 . "NOT>")
                    (-4 . "OR>")
                )
            )
        )
        (repeat (setq i (sslength s))
            (setq e (entget (ssname s (setq i (1- i)))))
            (entmake
                (list '(0 . "POINT")
                    (cons 10
                        (LM:bulgecentre
                            (cdr (assoc 10 e))
                            (cdr (assoc 10 (reverse e)))
                            (cdr (assoc 42 e))
                        )
                    )
                )
            )
        )
    )
    (princ)
)

;; Bulge Centre  -  Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b  - bulge
;; Returns the centre of the arc described by the given bulge and vertices
 
(defun LM:BulgeCentre ( p1 p2 b )
    (polar p1
        (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b))))
        (/ (* (distance p1 p2) (1+ (* b b))) 4 b)
    )
)
(princ)

 

And validation of a general circular 2-vertex polyline is also not too difficult as far as I can see - the following simple example should suffice:

 

(defun c:pcen2 ( / a b c d e i p q s x )
    (if (setq s (ssget '((0 . "LWPOLYLINE") (90 . 2) (-4 . "<NOT") (42 . 0.0) (-4 . "NOT>"))))
        (repeat (setq i (sslength s))
            (setq e (entget (ssname s (setq i (1- i))))
                  p (cdr (assoc 10 e))
                  q (cdr (assoc 10 (reverse e)))
                  a (cdr (assoc 42 e))
                  b (cdr (assoc 42 (reverse e)))
                  c (LM:bulgecentre p q a)
                  d (LM:bulgecentre q p b)
                  x (+ (atan a) (atan b))
            )
            (if (and (equal c d 1e-8) (or (equal (/ pi 2) x 1e-8) (equal (/ pi -2) x 1e-8)))
                (entmake (list '(0 . "POINT") (cons 10 c)))
            )
        )
    )
    (princ)
)

;; Bulge Centre  -  Lee Mac
;; p1 - start vertex
;; p2 - end vertex
;; b  - bulge
;; Returns the centre of the arc described by the given bulge and vertices
 
(defun LM:BulgeCentre ( p1 p2 b )
    (polar p1
        (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b))))
        (/ (* (distance p1 p2) (1+ (* b b))) 4 b)
    )
)
(princ)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost