Battle of the Bulge

To handle curves on polylines, Autodesk uses the efficient bulge. A bulge is a double (real, floating, whatever you call it)  is the tangent of 1/4 of the included angle of a curve segment.

This is very efficient since with a polyline, you already have the start and end point and with this and the bulge you can figure out all the other data of a curve. Of course, this is not easy in the coding world.

I first worked with Bulges in the Lisp world and learned a lot from the nice tutorial that AfraLisp has with some clear imagery (I am a visual person.). Now I am working with them so much in .Net that I thought I would write a simple class and share it with others (see below). You can create a New Bulge by entering the bulge, start point, and end point. I will probably add to this as I go and have not tested it fully so feel free to comment.

Personal Battle of the Bulge

Since going from working out in the field to sitting behind an office, I have put on some weight. Nothing new there – I think it happens to most of us computer guys. However, I am sick of it and am ready to make some changes. Today, I start a 3 month personal challenge. If you are curious, you can follow my victories (and probably pitfalls) at http://30pndsin3mnths.blogspot.com/

The Code-

Public Class BulgeData 
    Private rad As Double = Nothing 

    Private cPnt As Point3d = Nothing 

    Private chdLen As Double = Nothing 

    Private del As Double = Nothing 

    Private startAng As Double = Nothing 

    Private endAng As Double = Nothing 

    Private bul As Double = Nothing 

    Private stPnt As Point3d = Nothing 

    Private endPt As Point3d = Nothing 

 

    Public Sub New(ByVal Bulge As Double, ByVal StartPoint As Point3d, ByVal EndPoint As Point3d) 
        Dim pt2St As New Point2d(StartPoint.X, StartPoint.Y) 
        Dim pt2End As New Point2d(EndPoint.X, EndPoint.Y) 
 

        chdLen = pt2St.GetDistanceTo(pt2End) 
 

        Dim sign As Double = 1.0 
        If Bulge > 0.0 Then sign = -1.0 


        del = Math.Atan(Math.Abs(Bulge)) * 4 


        rad = Math.Abs(chdLen / (2 * Math.Sin(del / 2.0))) 


        Dim vec As Vector3d = EndPoint - StartPoint 
        Dim pln As New Plane(New Point3d(0, 0, 0), New Vector3d(0, 0, 1)) 


        'Find the angle of the chord 

        Dim ang As Double = vec.AngleOnPlane(pln) 
        cPnt = MiscTools.PolarPoint(StartPoint, ang + (((del - Math.PI) * sign) * 0.5), rad) 


        vec = cPnt - StartPoint 
        startAng = vec.AngleOnPlane(pln) 


        vec = cPnt - EndPoint 
        endAng = vec.AngleOnPlane(pln) 


        bul = Bulge 
        stPnt = StartPoint 
        endPt = EndPoint 
        
    End Sub 



    Public Sub New(ByVal Bulge As Double) 
        bul = Bulge 
    End Sub 



    Public ReadOnly Property ChordLength() As Double 

        Get 

            ChordLength = chdLen 
        End Get 

    End Property 



    Public ReadOnly Property Delta() As Double 

        Get 

            Delta = del 
        End Get 

    End Property 



    Public ReadOnly Property Radius() As Double 

        Get 

            Radius = rad 
        End Get 

    End Property 



    Public ReadOnly Property CenterPoint() As Point3d 
        Get 

            CenterPoint = cPnt 
        End Get 

    End Property 



    Public ReadOnly Property StartAngle() As Double 

        Get 

            StartAngle = startAng 
        End Get 

    End Property 



    Public ReadOnly Property StartPoint() As Point3d 
        Get 

            StartPoint = stPnt 
        End Get 

    End Property 



    Public ReadOnly Property EndPoint() As Point3d 
        Get 

            EndPoint = endPt 
        End Get 

    End Property 



    Public ReadOnly Property EndAngle() As Double 

        Get 

            EndAngle = endAng 
        End Get 

    End Property 



    Public ReadOnly Property Bulge() As Double 

        Get 

            Bulge = bul 


        End Get 

    End Property 



End Class 

6 comments

  1. Nick Zeeben says:

    Josh,

    I commend the effort and thought you are putting into your personal battle of the bulge. If I could make one suggestion though, and I think James might even agree. Forget watching what you eat, forget watching what you drink. Get out, be active, sign up for a 5 or a 10k, run 10 or 15 miles a week. The weight comes peeling off, and you still get to knock back a six pack when you feel the need.

    • 20 miles a week will do wonders, won’t it Nick?

      Sign up and take a running class, target one of the local Half Marathons and it will be almost impossble to not lost weight in a sensible manner if you keep going to the class and keep up with the miles. I’m down 40 from about 20 months ago now, and have made only moderate changes in diet.

      Anyway, before this turns into the Jenny Craig Website, I’m going to see what I can do as far as formatting on the post. I’ll let you know if what I tweak, Josh.

  2. Thanks Nick. Good luck Josh. I am almost tempted to lose some myself and found http://jeffgalloway.typepad.com/jeff_galloways_blog/ recently. I’ve run a 5k once in each of the past two years and I resolve to increase my running this year and shed a few too!

  3. Wow guys! Thanks for the support and suggestions.

    Nick, I was expecting a running comment from James but not you. 🙂
    An exercise program (including running) was started last week. If all goes well, I will be able to do exactly as you suggest by the end of the three months. Of course, starting to run in this cold (it is all relative guys) is a bit of a challenge.

    James, Do what you need to regarding the post/comments.

    • Nick Zeeben says:

      Josh,

      Me and Dan were the instigators in getting James to enter his first 5k a couple years ago during one of his visits to Manchester. He has gone alot more hog wild than have I with the running, as I only did my first half marathon this fall.

  4. John Mayo says:

    I hope you meet your goal faster than you expect Joshua.

    Best wishes.