## Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z # comp.cad.autocad AutoLISP FAQ (part 2/2) - samples, codeSection -  Circle/Arc Geometry: BULGE conversion, some trigonometry

( Part1 - Part2 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Cities ]

Previous Document:  Polylines
Next Document:  DCL: listboxes with tabs or monotext font
```  What is the *BULGE* in a polyline?

The bulge is the tangent of one forth of the included angle of a
curved segment. A bulge 0.0 means a straight segment.
Together with the start- and endpoint it is sufficient information to
quickly calculate all other required information of a curved segment.
A negative bulge is a rotation in clockwise direction ("mathematically
negative").

bulge     = tan( ang/4 )            (CCW: +, CW: -)
angle     = 4*atan( bulge )
bulge     = ( 2*altitude ) / chord  (CCW: +, CW: -)

for a sample program or the book "Maximizing AutoLISP" 
(Note: The R10/11 book -Vol II- contains a wrong bulge formula.)

;;; converts a bulged segment (bulge pt1 pt2) of a polyline
;;;   to a circle (ctr rad), the start- and endpoints are known
;;;   therefore the angles too: (angle ctr pt1)(angle ctr pt2)
;;; returns nil on a straight segment!
;;; (bugfixed version. Thanks to Sergei Komarov)
(defun SEG2CIR (seg / bulge p1 p2 cot x y rad dummy)
(if (zerop (car seg))  ;straight line => invalid circle
nil
cot (* 0.5 (- (/ 1.0 bulge) bulge))
x (/ (- (+ (car  p1) (car  p2))
(* (- (car  p2) (car  p1)) cot)) 2.0)
dummy (list (list x y) rad))))   ; return this, I hate progn's

;;; inverse conversion
;;; calculates segment (bulge p1 p2) of arc
;;;   with given circle (ctr rad), start-angle, end-angle
(defun ARC2SEG (cir ang1 ang2 / p1 p2)
(setq p1 (polar (car cir) ang1 (cadr cir))
p2 (polar (car cir) ang2 (cadr cir)))
(list (arc2bul p1 p2 cir) p1 p2))

;;; calculates bulge of arc given the arc points and the
;;;   circle (ctr rad) [fixed by Serge Pashkov]
(defun ARC2BUL (p1 p2 cir / ang)
(setq ang (- (angle (car cir) p2) (angle (car cir) p1)))
(if (minusp ang) (setq ang (+ (* 2.0 pi) ang)))
(tan (/ ang 4.0)))

;;; returns angle of arc (bulge)
;;; The seg format is (bulge p1 p2)
(defun BUL2ANG (seg / ctr)
(- (angle (setq ctr (car (seg2cir seg))) (cadr seg))

;;; calculates angle of arc given the chord distance and radius
(* 2.0 (atan
(/ chord 2.0
(expt (/ chord 2.0) 2)
) )      ) ) )     )  ;another way in the paren's world

;;; length of arc   = radius*angle,
;;; Note: +/-, you'll need (abs (arclen seg)) for the distance
(defun ARCLEN (seg)
4.0 (atan (car seg))))               ;angle = 4*atan(bulge)

(setq *INFINITY* 1.7e308)                 ; largest double
(defun TAN (z / cosz) ; [fixed]
(if (zerop (setq cosz (cos z))) *INFINITY*
(/ (sin z) cosz)))
(defun DTR (ang)(* pi (/ ang 180.0)))     ;degree to radian
(defun RTD (ang)(/ (* ang 180.0) pi))     ;radian to degree

```

## User Contributions:

Previous Document:  Polylines
Next Document:  DCL: listboxes with tabs or monotext font

Part1 - Part2 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
rurban@xarch.tu-graz.ac.at (Reini Urban)

Last Update March 27 2014 @ 02:11 PM