leave it to a VB programmer...

OK, I've always been an admitted snob when it comes to Visual Basic.  To me, Visual Basic has always represented the blocks-with-letters-on-them version of languages.  Basically, most of the people who are really big fans of VB fall solidly under the category of "Don't Want Him/Her on My Team".  I know, this will upset some people, but anyone who knows me knows that I don't really care :)

Here's what made me say the title:

I was google searching for an algorithm to give me the intersecting point of two Line Segments.  For those non-math weenies out there, a "line" is an infinite thing.  So, when you ask for the intersection of two lines, you may get a point extremely far away from your area of interest.  A "line segment" on the other hand is what you generally consider a line: the connection of two points. 

In looking around, I found this code which, by the way, doesn't solve what I want.  It solves the "line" intersection:

    'Returns the point that the lines cross and stores into LinesCross if the lines do in fact cross
    Public Function Intersect(ByRef Ln As geoLine, ByRef LinesCross As Boolean) As geoPoint
        Try
            'Calculate Denominator
            Dim Det As Double = Ln.m_A * m_B - Ln.m_B * m_A
            Dim Res As geoPoint = New geoPoint((Ln.m_C * m_B - Ln.m_B * m_C) / Det, (Ln.m_A * m_C - m_A * Ln.m_C) / Det)
            LinesCross = True
            Return Res
        Catch
            'Lines are parallel (or do not intersect within the range of a double)
            LinesCross = False
            Return New geoPoint()
        End Try

    End Function

OK, this is a Cardinal Sin of exception handling.  (S)he's using exception handling for logic flow!  That's 30 lashes with a cat o' nine tails to me.  Of course a VB person may applaud his/her ingenuity...

T

posted on Friday, June 02, 2006 9:45 AM by Tom

Comments