Jump to content

Calculate the bulge of an arc.


The Buzzard

Recommended Posts

I was using a program that has polyline command calls to make an elbow.

I am changing this to an entmake program that makes the same type elbow from one continuous polyline.

 

Here is an example of a list returned from that elbow.

 

In the following list, DXF code 42 represent the BULGE of an arc.

 

(-1 . <Entity name: 7ef6fe40>)
(0 . "LWPOLYLINE")
(330 . <Entity name: 7ef6dcf8>)
(5 . "A30")
(100 . "AcDbEntity")
(67 . 0)
(410 . "Model")
(8 . "M-HVAC-SUPP")
(100 . "AcDbPolyline")
(90 . 4)
(70 . 1)
(43 . 0.0)
(38 . 0.0)
(39 . 0.0)
(10 -730.727 -201.462)
(40 . 0.0)
(41 . 0.0)
[color=red](42 . 0.414214)[/color]
(10 -724.727 -195.462)
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(10 -676.727 -195.462)
(40 . 0.0)
(41 . 0.0)
[color=red](42 . -0.414214)[/color]
(10 -730.727 -249.462)
(40 . 0.0)
(41 . 0.0)
(42 . 0.0)
(210 0.0 0.0 1.0)

 

I am trying to fiqure out how to write a calculation and place its value in a variable to be use for this. I assume this is a trigonometry problem and have very little experience with it.

 

Can anybody help me figure this thing out?

Thanks in advance,

The Buzzard

Document1.jpg

Link to comment
Share on other sites

  • Replies 27
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    10

  • wizman

    9

  • Lee Mac

    3

  • gile

    2

Top Posters In This Topic

Posted Images

Bulge is tangent of 1/4 of the included angle. Positive value is CounterClockwise in Direction:

 

bulge = tan( ang/4 )

 

Thanks wizman!

 

I will give it a go.

 

The Buzzard

Link to comment
Share on other sites

Here is some old stuff from Duff Kirkland


; AutoLISP function to convert from Polyline "Bulge" representation
; of an arc to AutoCAD's normal "center, radius, start/end angles"
; form of arc.  This function applies the bulge between two adjacent
; vertices.  It assumes that global symbols "sp", "ep", and "bulge"
; contain the current vertex (start point), next vertex (end point),
; and bulge, respectively.  It sets the appropriate values in global
; symbols "cen", "rad", "sa", and "ea".

; by Duff Kurland - Autodesk, Inc.
; July 7, 1986

(defun cvtbulge (/ cotbce x1 x2 y1 y2 temp)
 (setq x1 (car  sp) x2 (car  ep))
 (setq y1 (cadr sp) y2 (cadr ep))
 (setq cotbce (/ (- (/ 1.0 bulge) bulge) 2.0))

 ; Compute center point and radius

 (setq cen (list (/ (+ x1 x2 (- (* (- y2 y1) cotbce))) 2.0)
                 (/ (+ y1 y2    (* (- x2 x1) cotbce) ) 2.0))
 )
 (setq rad (distance cen sp))

 ; Compute start and end angles

 (setq sa  (atan (- y1 (cadr cen)) (- x1 (car cen))))
 (setq ea  (atan (- y2 (cadr cen)) (- x2 (car cen))))
 (if (< sa 0.0)                      ; Eliminate negative angles
    (setq sa (+ sa (* 2.0 pi)))
 )
 (if (< ea 0.0)
    (setq ea (+ ea (* 2.0 pi)))
 )
 (if (< bulge 0.0)                   ; Swap angles if clockwise
    (progn
       (setq temp sa)
       (setq sa ea)
       (setq ea temp)
    )
 )
)

 

-David

Link to comment
Share on other sites

Here is some old stuff from Duff Kirkland


; AutoLISP function to convert from Polyline "Bulge" representation
; of an arc to AutoCAD's normal "center, radius, start/end angles"
; form of arc.  This function applies the bulge between two adjacent
; vertices.  It assumes that global symbols "sp", "ep", and "bulge"
; contain the current vertex (start point), next vertex (end point),
; and bulge, respectively.  It sets the appropriate values in global
; symbols "cen", "rad", "sa", and "ea".

; by Duff Kurland - Autodesk, Inc.
; July 7, 1986

(defun cvtbulge (/ cotbce x1 x2 y1 y2 temp)
 (setq x1 (car  sp) x2 (car  ep))
 (setq y1 (cadr sp) y2 (cadr ep))
 (setq cotbce (/ (- (/ 1.0 bulge) bulge) 2.0))

 ; Compute center point and radius

 (setq cen (list (/ (+ x1 x2 (- (* (- y2 y1) cotbce))) 2.0)
                 (/ (+ y1 y2    (* (- x2 x1) cotbce) ) 2.0))
 )
 (setq rad (distance cen sp))

 ; Compute start and end angles

 (setq sa  (atan (- y1 (cadr cen)) (- x1 (car cen))))
 (setq ea  (atan (- y2 (cadr cen)) (- x2 (car cen))))
 (if (< sa 0.0)                      ; Eliminate negative angles
    (setq sa (+ sa (* 2.0 pi)))
 )
 (if (< ea 0.0)
    (setq ea (+ ea (* 2.0 pi)))
 )
 (if (< bulge 0.0)                   ; Swap angles if clockwise
    (progn
       (setq temp sa)
       (setq sa ea)
       (setq ea temp)
    )
 )
)

 

-David

 

 

And I Thank You also David.

Lots of good stuff in there.

Link to comment
Share on other sites

From the figure, both are having same bulge values, to calculage:

 

tangent (90/4) = 0.4142

 

Thats true wizman, But one should come up positive and the other negative.

 

 

 

Sorry, I replied before your edit.

Link to comment
Share on other sites

That's ok Buzz,

 

(defun Tan (X)

(if (zerop (cos X))

(prompt "Tangent error.")

(/ (sin X) (cos X))))

 

(tan (/ (/ pi 2) 4))

=> 0.4142

Link to comment
Share on other sites

More fun with Bulge:

 

(defun c:bulge (/ *error* ENT GR INDEX OBJ P1 P2 TAN UFLAG )
 ;; Modification of code by ElpanovEvgeniy, by Lee Mac
 (vl-load-com)

 (setq *doc* (cond (*doc*) ((vla-get-ActiveDocument (vlax-get-acad-object)))))

 (defun *error* (msg)
   (and uFlag (vla-EndUndoMark *doc*))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ))

 (setq tan '((a) (/ (sin a) (cos a))))

 (while
   (progn
     (setq ent (entsel "\nSelect LWPolyline: "))

     (cond (  (vl-consp ent)

              (if (eq "LWPOLYLINE" (cdr (assoc 0 (entget (car ent)))))
                (progn
                  (setq uFlag (not (vla-StartUndoMark *doc*)))
                  
                  (setq index (fix (vlax-curve-getParamatPoint (car ent)
                                     (vlax-curve-getClosestPointto (car ent) (cadr ent)))))

                  (mapcar (function set) '(p1 p2)
                          (mapcar (function vlax-curve-getPointatParam) (list (car ent) (car ent))
                                  (list index (1+ index))))

                  (setq obj (vlax-ename->vla-object (car ent)))

                  (while (= 5 (car (setq gr (grread 't 4 0))))
                    (vla-SetBulge obj index (tan (/ (- (angle (cadr gr) p2) (angle p1 (cadr gr))) 2.))))

                  (setq uFlag (vla-EndUndomark *doc*)))

                (princ "\n** Object Must be an LWPolyline **"))))))
 (princ))

 

(defun c:cam3 (/ ANG BLG C1 CEN CEN2 CODE DATA DELTA DIS
                EN GR IANG LEN LST POLY RAD RAD1 RAD2 TAN)
 ;; by Lee McDonnell (Lee Mac)  ~  19.12.2009
 
 (vl-load-com)

 (if (setq cen (getpoint "\nPick Center of First Radius: "))
   (progn
     (setq poly (entmakex
                  (list
                    (cons 0 "LWPOLYLINE")
                    (cons 100 "AcDbEntity")
                    (cons 100 "AcDbPolyline")
                    (cons 90 2)
                    (cons 70 1)
                    (cons 10 cen)
                    (cons 10 (polar cen 0 1.))))

           en   (reverse
                  (vl-member-if
                    (function
                      (lambda (x)
                        (= 39 (car x))))

                    (reverse (entget poly)))))
     
     (princ "\nPick First Radius: ")
     
     (while
       (progn
         (setq gr (grread 't 15 0) code (car gr) data (cadr gr))

         (cond (  (and (= 5 code) (listp data))

                  (setq ang (angle cen data)

                        dis (distance cen data))

                  (entmod
                    (append en
                      (setq lst
                        (list
                          (cons 10 data)
                          (cons 42 1.)
                          (cons 10 (polar data (+ ang pi) (* 2. dis)))
                          (cons 42 1.))))))

               (  (and (= 3 code) (listp data))

                  (setq en
                    (append en
                      (setq lst
                        (list
                          (cons 10 data)
                          (cons 42 1.)
                          (cons 10 (polar data (+ ang pi) (* 2. dis)))
                          (cons 42 1.)
                          (cons 10 data))))

                        en (reverse
                             (vl-member-if
                               (function
                                 (lambda (x)
                                   (= 39 (car x))))

                               (reverse
                                 (entmod
                                   (subst (cons 90 3) (assoc 90 en) en)))))
                        
                        rad (distance cen data))

                  (princ "\nPick Center of Second Radius: ")

                  (while
                    (progn
                      (setq gr (grread 't 15 0) code (car gr) data (cadr gr))

                      (cond (  (and (= 5 code) (listp data))

                               (setq dis (distance cen data) ang (angle cen data))

                               (if (< rad dis)
                                 (progn

                                   (setq tan  (sqrt (- (* dis dis) (* rad rad)))

                                         iAng (atan tan rad)

                                         blg  (/ (sin (* 0.5 (- pi iAng)))
                                                 (cos (* 0.5 (- pi iAng)))))

                                   (entmod
                                     (append en
                                       (setq lst
                                         (list
                                           (cons 10 data)
                                           (cons 10 (polar cen (+ ang iAng) rad))
                                           (cons 42 blg)
                                           (cons 10 (polar cen (- ang iAng) rad))))))) t))

                            (  (and (= 3 code) (listp data))

                               (setq dis (distance cen data) ang (angle cen data))

                               (if (< rad dis)
                                 (progn

                                   (setq tan  (sqrt (- (* dis dis) (* rad rad)))

                                         iAng (atan tan rad)

                                         blg  (/ (sin (* 0.5 (- pi iAng)))
                                                 (cos (* 0.5 (- pi iAng)))))

                                   (setq en
                                     (append en
                                       (list
                                         (cons 10 data)
                                         (cons 10 data)
                                         (cons 10 (polar cen (+ ang iAng) rad))
                                         (cons 42 blg)
                                         (cons 10 (polar cen (- ang iAng) rad)))))

                                   (setq en (reverse
                                              (vl-member-if
                                                (function
                                                  (lambda (x)
                                                    (= 39 (car x))))

                                                (reverse
                                                  (entmod
                                                    (subst (cons 90 4) (assoc 90 en) en)))))

                                         cen2 data len (distance cen cen2) ang (angle cen cen2))

                                   (princ "\nPick Second Radius: ")
                                   
                                   (while
                                     (progn
                                       (setq gr (grread 't 15 0) code (car gr) data (cadr gr))
                                       
                                       (cond (  (and (= 5 code) (listp data))
                                              
                                                (setq rad2 (distance cen2 data) delta (- rad rad2))

                                                (if (< (abs delta) len)
                                                  (progn

                                                    (setq tan  (sqrt (- (* len len) (* delta delta))) iAng (atan tan delta)
                                                    
                                                          blg1 (/ (sin (* 0.5 (- pi iAng))) (cos (* 0.5 (- pi iAng))))

                                                          blg2 (/ (sin (* 0.5 iAng))        (cos (* 0.5 iAng))))
                                              
                                                    (entmod
                                                      (append en
                                                        (list
                                                          (cons 10 (polar cen  (+ ang iAng) rad))
                                                          (cons 42 blg1)
                                                          (cons 10 (polar cen  (- ang iAng) rad))
                                                      
                                                          (cons 10 (polar cen2 (- ang iAng) rad2))
                                                          (cons 42 blg2)
                                                          (cons 10 (polar cen2 (+ ang iAng) rad2)))))) t))
                                             
                                             (  (and (= 3 code) (listp data)) nil)

                                             (t )))))))
                            (t )))))
               (t ))))))
 (princ))

Link to comment
Share on other sites

That's ok Buzz,

 

(defun Tan (X)

(if (zerop (cos X))

(prompt "Tangent error.")

(/ (sin X) (cos X))))

 

(tan (/ (/ pi 2) 4))

=> 0.4142

 

wizman,

 

When making the calculation in lisp, Does the angle or ang need to be expressed in radians?

Link to comment
Share on other sites

buzz, lisp always needs angles in radians

 

It seems no matter which way I write it the value comes out wrong.

(setq BF1# (atan (/ (MD_DTR 90) 4))

(defun MD_DTR (a)(* pi (/ a 180.0)))

 

Returns 0.374197

Link to comment
Share on other sites

not a built-in function, i posted it already for you on the first page...'-)

 

 

 

 

Perfect! That does exactly what I need.

 

 

Thanks again wizman

Link to comment
Share on other sites

Hi,

 

AFAIK, there's no need to test if the cosine equals 0 to avoid an error.

The cos LISP function is implemented so that (cos (/ pi 2)) returns 6.12323e-017 and (cos (* pi 1.5)) -1.83697e-016 rather than 0.

 

So I currently use:

(defun tan (a) (/ (sin a) (cos a)))

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...