Product : Engine, Version : 5.0.1.1036, ArticleID : 41023864

HowTo : Chamfer on polylines

Article41023864
TypeHowTo
ProductEngine
Version5.0.1.1036
Date Added2/21/2005
Submitted byLevi Azevedo
Keywords

Subject

Chamfer on polylines

Summary

I'd like to add to a polyline the chamfer command for a specific vertex.

Solution

It is quite easy for a developer to add it to his application. This code can be easily altered to chamfer alll vertexes of a polyline.

Public Sub Camfer(vdPoly As vdPolyline, PolyVertex As Long, Dist1 As Double, Optional Dist2 As Double)
Dim I As Long
Dim vert As Variant
Dim BulgeList As Variant
    vert = vdPoly.VertexList
    BulgeList = vdPoly.BulgeList
    For I = 0 To UBound(BulgeList)
        If BulgeList(I) <> 0 Then
            MsgBox "Polyline has bulges. Chamfer canceled"
            Exit Sub
        End If
    Next I
    If Dist1 <= 0 Then
        MsgBox "Chamfer distance must be >0. Chamfer canceled"
        Exit Sub
    End If
    If Dist2 <= 0 Then
        Dist2 = Dist1
    End If
    If UBound(vert) < 2 Then
        MsgBox "Polyline must have more than 2 vertexes. Chamfer canceled"
        Exit Sub
    End If
    If PolyVertex > UBound(vert) Then
        MsgBox "Polyline has less vertexes than " & CStr(PolyVertex) & ". Chamfer canceled"
        Exit Sub
    End If
    If PolyVertex > 0 And PolyVertex < UBound(vert) Then
        Dim VertPrev As Variant
        Dim VertNext As Variant
        Dim VertCurrent As Variant
        Dim VertNew As Variant
        VertPrev = Array(vert(PolyVertex - 1, 0), vert(PolyVertex - 1, 1), vert(PolyVertex - 1, 2))
        VertNext = Array(vert(PolyVertex + 1, 0), vert(PolyVertex + 1, 1), vert(PolyVertex + 1, 2))
        VertCurrent = Array(vert(PolyVertex, 0), vert(PolyVertex, 1), vert(PolyVertex, 2))
        If VDPro1.Utility.geomDistance(VertPrev, VertCurrent) < Dist1 Or VDPro1.Utility.geomDistance(VertCurrent, VertNext) < Dist2 Then
            MsgBox "Distance specified for chamfer is very big. Chamfer canceled"
            Exit Sub
        End If
        Dim anglePrev As Double
        Dim angleNext As Double
        anglePrev = VDPro1.Utility.geomAngle(VertCurrent, VertPrev)
        angleNext = VDPro1.Utility.geomAngle(VertCurrent, VertNext)
        VertNew = VDPro1.Utility.geomPolar(VertCurrent, angleNext, Dist2)
        VertCurrent = VDPro1.Utility.geomPolar(VertCurrent, anglePrev, Dist1)
        vert(PolyVertex, 0) = VertCurrent(0)
        vert(PolyVertex, 1) = VertCurrent(1)
        vert(PolyVertex, 2) = VertCurrent(2)
        vdPoly.VertexList = vert
        vdPoly.InsertVertex PolyVertex, VertNew
        vdPoly.Invalidate
    Else
        MsgBox "Cannot chamfer the first or last vertex or polyline. Chamfer canceled"
        Exit Sub
    End If
End Sub