Polyline Bulges - Part 2
Given the two functions getPolySegs and getArcInfo we can now put together a command that inspects all bulges in a polyline.
(defun C:POLYARCS (/ a polysegs seg) ;; make a list of polyline segments of a ;; selected polyline (cond ((setq polysegs (getPolySegs)) ;; a is just an informative counter (setq a 0) ;; run thru each segment (foreach seg polysegs (setq a (1+ a)) ;; only process the segment if it's an arc ;; i.e. bulge /= 0.0 (cond ((not (zerop (cadr seg))) (princ (strcat "\nSegment " (itoa a) ": ")) ;; (getArcInfo seg) ) ) ) ) ) )
Command: polyarcs Select polyline: Segment 2: Included angle: 2.9932 rad (171.4974 degrees) Height of arc: 1.1422 Chord length: 2.4605 Radius of arc: 1.2336 Center of arc: -9.4965,14.9290 Segment 4: Included angle: 0.9844 rad (56.3997 degrees) Height of arc: 0.4201 Chord length: 3.3447 Radius of arc: 3.5390 Center of arc: -5.8690,19.3390 Segment 5: Included angle: 1.6177 rad (92.6872 degrees) Height of arc: 0.5787 Chord length: 2.7043 Radius of arc: 1.8689 Center of arc: -2.1545,17.4054
This concludes the code for now. Below are some useful formulas for dealing with bulges. The picture recaps some geometric details of the circular arc.
θ = (* 4.0 (atan bulge))
η = (/ θ 2.0)
φ = (+ γ ε) = (- (/ pi 2.0)(/ θ 4.0)) = (/ (- (* pi 2.0) θ) 4.0) = (- (/ pi 2.0)(atan bulge))
γ = (/ (- pi θ) 2.0) = (- (/ pi 2.0)(* 2.0 (atan bulge))) = (atan (/ a c))
ε = (/ θ 4.0) = (atan bulge) = (atan (/ s c))
c = (distance p1 p2) = (* 2.0 r (cos γ)) = (* 2.0 r (sin (/ θ 2.0)))
s = (* (/ c 2.0) bulge)
a = (sqrt (- (expt r 2.0) (expt (/ c 2.0) 2.0))) (* r (cos η))
r = (/ (+ (expt (/ c 2.0) 2.0)(expt s 2.0))(* 2.0 s)) = (/ s (* 2.0 (sin ε)(cos φ))) = (/ a (cos η))
The center point is found in the code by calculating angles and distances in order to use POLAR. In function getArcInfo are given two methods. One is calculating the apothem as a leg in the triangle P-P2-P4 and setting out the center point from P4. The other is using the angle γ and the radius to set out the point from P1. Both methods have to read the sign of the bulge to know in which direction the center point has to be set out.
Another method could be to view the arc as a part of the circumcircle to triangle P1-P2-P3. The medians to the lines P1-P3 and P2-P3 intersect in the center point. We know the gradients for these medians because both angles are known. E.g. any perpendicular to the line P1-P3 has the gradient (- (/ 1.0 gr)), where gr is the gradient of P1-P3. Once having a point of the median (midpoint of P1-P3) and the grade, it's possible to find the Y-interception and thereby the equation for the median. Doing this for both medians we can use the following formulas for finding the intersection point — which is the center point for the arc:
xi = - (m1 - m2)/(n1 - n2) yi = m1 + n1*xi where m1 = gradient for median to P1-P3 n1 = Y-interception for median to P1-P3 m2 = gradient for median to P2-P3 n2 = Y-interception for median to P2-P3
There are many other solutions for finding the center point — among those some shorter trigonometric methods — but this will have to do for now.
Because the geometry described by the 2 vertices and the bulge is relatively simple, there are many other formulas than those depicted here. The important part is to understand how the bulge is defined and how it relates to the only other two pieces of data given - the vertices. Hopefully this was able to shed a light on some of the definitions.
For more information, refer to : Unit Circle Definition of Sine and Cosine Functions