Questions similar to these appear in the Be Communities MicroStation Programming Forum.
Q How do I create a centre line between two existing lines? That is, I have two similar lines that are approximately 'parallel' and I want to construct a new line that runs mid-way between those lines.
A This article describes a MicroStation VBA project that provide two separate ways to create a centre-line. The macro …
If you want to get started with using this macro, go to Download.
The starting point is a pair of similar lines that are 'parallel' (but we use the term parallel very loosely). In this example the lines have the same number of vertices …
The VBA macro first gets the vertices from each line, then constructs a set of chords (lines) that start at a vertex of the first line and ends at the corresponding vertex of the second line …
The VBA macro steps along the first line by a fixed distance and gets the point at each step. From each point it drop a perpendicular onto the second line and gets the point of intersection. It constructs the chord from the pair of coordinates found at each step …
The macro calculates the centre point of each chord.
From that set of points it constructs a new line (VBA LineStringElement
) that connects the
mid-point of each chord …
Method 2 works for DGN elements that don't implement the IVertexList
interface.
For example, arcs and curves.
However, an element must provide the point-at-distance method (DistanceAtPoint
) which is part of the TraversableElement
object.
Here are two arc elements …
Here is the result of applying Method 2 to those arcs …
While calculating the chords, the macro keeps a record of the maximum and minimum lengths. The result is displayed in the dialog box.
The macro shows how to pick the initial line-strings using a locate class that Implements ILocateCommandEvents
.
The calculation of the chords and their mid-points is straightforward.
The macro creates the chord LineElements
as transients.
Class clsChords
does the work of calculating chords and creating the centre-line.
It provides two different methods to analyse the lines and generate the centre-line …
ConstructChordsByVertex
works only with two lines that implement the IVertexList
interface
ConstructChordsByPerpendicular
works with two lines that inherit the TraversableElement
class
When using Method 1, the initial lines must be oriented in the same direction. Otherwise, the chords become twisted and the centre line will not be what you expect. The button labelled Reverse Line 2 lets you reverse the direction of the second line.
When using Method 2, the initial line orientation is unimportant. It's also much more adaptable to different DGN elements: it works with almost any line or curve. For example, here's a line-string and a B-Spline curve …
Download the
Create Centre Line ZIP archive, and unpack it to a suitable location such as
\Workspace\Standards\macros
.
Start the macro using the key-in …
vba run [CreateCentreLine]modMain.Main
Post questions about MicroStation programming to the MicroStation Programming Forum.