AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN


PolyLines and Arcs
by Scott McGlynn

As we are all well aware, the bulge is defined as :

So, rearranging the equation :

Ok. Now we have the included angle for the Arc.
From trigonometry, we know that Arc Length is defined as:

So all we have to do is figure out the Radius.
We can determine that using 2 pieces of information, ½ of the chord length, and ½ the included angle as shown in Figure 1.

The Chord length can be calculated as the straightline distance between two points. We have a function defined called "Calculate3Ddistance" that does just that :

Passing in the 2 points, we get back the full chord length. Divide by 2 and we have the short leg of the triangle above (y). We can calculate the Hypotenuse which is also the radius using f, and the short leg using the following formula :

However,

so we can simplify this formula to :

Unfortunately, the Cosecant function is not defined in VB, so we are left with the 1/sin version.

Tying all of this together, we have a function called "CalculatePolylineLength" We pass the function an entity. We test to ensure it is a Polyline, then proceed to the actual work.

First, we get the upper and lower bounds of the coords variant. Then begin a For Next loop to loop through each set of 2D coordinates. Because the "GetBulge" method of the polyline object returns the bulge for a segment, and there are ½ the number of segments as thare are coordinates (2 coordinates per point), we get the bulge of the loop counter/2 instead of the loopcounter.

We then get the coordinates of the first point, x1 & y1, then the coordinates of the second point x2 & y2. Depending on the value of the bulge, we either call the "Calculate3D Distance" or "CalculateArcLength" keeping a running total of the lengths.

 
The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website