Bulge Conversion Functions
The curvature of a Polyline Arc segment is defined using a quantity known as bulge. This unit measures the deviation of the curve from the straight line (chord) joining the two vertices of the segment. It is defined as the ratio of the arc sagitta (versine) to half the length of the chord between the two vertices; this ratio is equal to the tangent of a quarter of the included arc angle between the two polyline vertices.
In this way, a negative bulge indicates that the arc follows a clockwise direction from the first vertex to the next, with a positive bulge describing an anticlockwise oriented arc. A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle.
An AutoCAD Arc Entity is defined by a center, radius and start & end angle. The arc is always defined to be anticlockwise oriented, that is, following an anticlockwise direction from the start angle to the end angle.
Here I demonstrate various methods to convert between the quantities used to define a Polyline Arc segment and those used to define an Arc Entity, with a brief explanation of calculations used in each method.
Arc to Bulge
Function Syntax | (LM:Arc->Bulge <c> <a1> <a2> <r>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
c | List | Arc Center |
a1, a2 | Real | Start and End Angle of Arc (respectively) |
r | Real | Arc Radius |
Returns | ||
Type | Description | |
List | List of: (<vertex> <bulge> <vertex>) describing the Polyline Arc |
This function will convert the quantities used to define an AutoCAD Arc Entity (center, start/end angle, radius) to those used to define a Polyline Arc segment (vertices, bulge).
The function first normalises the included arc angle to lie within the range 0 ≤ θ < 2π and then utilises the definition that the bulge of a Polyline Arc is the tangent of a quarter of the included arc angle.
;; Arc to Bulge - Lee Mac ;; c - center ;; a1,a2 - start, end angle ;; r - radius ;; Returns: (<vertex> <bulge> <vertex>) (defun LM:Arc->Bulge ( c a1 a2 r ) (list (polar c a1 r) ( (lambda ( a ) (/ (sin a) (cos a))) (/ (rem (+ pi pi (- a2 a1)) (+ pi pi)) 4.0) ) (polar c a2 r) ) )
Test Function
The following test function will prompt for selection of an Arc Entity and proceed to create a (green) Polyline Arc segment to match the selected arc.
(defun c:test ( / e ) (if (setq e (ssget "_+.:E:S" '((0 . "ARC")))) (progn (setq e (entget (ssname e 0))) (entmake (append '( (000 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (090 . 2) (070 . 0) ) (mapcar 'cons '(10 42 10) (LM:Arc->Bulge (cdr (assoc 10 e)) (cdr (assoc 50 e)) (cdr (assoc 51 e)) (cdr (assoc 40 e)) ) ) ) ) ) ) (princ) )
Bulge to Arc
Function Syntax | (LM:Bulge->Arc <p1> <p2> <b>) |
Current Version | 1.0 |
Donate |
Arguments | ||
---|---|---|
Symbol | Type | Description |
p1, p2 | List | Points describing the vertices of the Polyline Arc segment |
b | Real | Bulge of the Polyline Arc |
Returns | ||
Type | Description | |
List | List of: (<center> <start angle> <end angle> <radius>) describing the Arc |
This function will convert the quantities used to define a Polyline Arc segment (vertices, bulge) to those used to define an AutoCAD Arc Entity (center, start/end angle, radius).
Version 1
This version uses the relationship between the arc chord length and included angle, as illustrated by the following diagram:
;; Bulge to Arc - Lee Mac ;; p1 - start vertex ;; p2 - end vertex ;; b - bulge ;; Returns: (<center> <start angle> <end angle> <radius>) (defun LM:Bulge->Arc ( p1 p2 b / a c r ) (setq a (* 2 (atan b)) r (/ (distance p1 p2) 2 (sin a)) c (polar p1 (+ (- (/ pi 2) a) (angle p1 p2)) r) ) (if (minusp b) (list c (angle c p2) (angle c p1) (abs r)) (list c (angle c p1) (angle c p2) (abs r)) ) )
Version 2
This version uses the relationship between the arc sagitta and bulge factor, illustrated by the following diagram:
;; Bulge to Arc - Lee Mac ;; p1 - start vertex ;; p2 - end vertex ;; b - bulge ;; Returns: (<center> <start angle> <end angle> <radius>) (defun LM:Bulge->Arc ( p1 p2 b / c r ) (setq r (/ (* (distance p1 p2) (1+ (* b b))) 4 b) c (polar p1 (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b)))) r) ) (if (minusp b) (list c (angle c p2) (angle c p1) (abs r)) (list c (angle c p1) (angle c p2) (abs r)) ) )
Test Function
The following test function will prompt for selection of an LWPolyline with 2 vertices and non-zero bulge, and proceed to create a (green) Arc Entity to match the selected Polyline Arc segment.
(defun c:test ( / e ) (if (setq e (ssget "_+.:E:S" '((0 . "LWPOLYLINE") (90 . 2) (-4 . "<>") (42 . 0.0)))) (progn (setq e (entget (ssname e 0))) (entmake (cons '(0 . "ARC") (mapcar 'cons '(10 50 51 40) (LM:Bulge->Arc (cdr (assoc 10 e)) (cdr (assoc 10 (reverse e))) (cdr (assoc 42 e)) ) ) ) ) ) ) (princ) )
Additional Functions
The following functions are derived from the above Bulge to Arc functions, and will return the individual arc properties of the polyline arc segment.
The required parameters & values returned by each function are detailed in the respective code headers.
Bulge Center
;; Bulge Center - Lee Mac ;; p1 - start vertex ;; p2 - end vertex ;; b - bulge ;; Returns the center of the arc described by the given bulge and vertices (defun LM:BulgeCenter ( p1 p2 b ) (polar p1 (+ (angle p1 p2) (- (/ pi 2) (* 2 (atan b)))) (/ (* (distance p1 p2) (1+ (* b b))) 4 b) ) )
Bulge Radius
;; Bulge Radius - Lee Mac ;; p1 - start vertex ;; p2 - end vertex ;; b - bulge ;; Returns the radius of the arc described by the given bulge and vertices (defun LM:BulgeRadius ( p1 p2 b ) (/ (* (distance p1 p2) (1+ (* b b))) 4 (abs b)) )
Further Information
More information about the derivation of the bulge quantity can be found in this article by Stig Madsen. The article also explains in greater detail many of the properties and relationships of an arc used by the above functions.