AVAX-software.com Forums: Distance between two lines - AVAX-software.com Forums

Jump to content

Page 1 of 1

Distance between two lines

#1 User is offline   Athanasios Gardos Icon

  • Administrator
  • Icon
  • Group: Admin
  • Posts: 333
  • Joined: 21-March 05
  • Gender:Male

Posted 31 May 2008 - 01:36 PM

VB6 source code to calculate the distance between two lines:
Option Explicit

Dim oMath As cAvaxMath

Private Sub Form_Load()
    Dim hLine1 As Long
    Dim hLine2 As Long
    Dim ax1 As Single, ay1 As Single, az1 As Single
    Dim ax2 As Single, ay2 As Single, az2 As Single
    Dim bx1 As Single, by1 As Single, bz1 As Single
    Dim bx2 As Single, by2 As Single, bz2 As Single
    Dim d1 As Single, d2 As Single
    Set oMath = New cAvaxMath
    Call cAvax1.StartAvax
    ay2 = 10
    hLine1 = cAvax1.Add_Line(ax1, ay1, az1, ax2, ay2, az2)
    bx1 = 10
    by1 = 2
    bx2 = 10
    by2 = 8
    hLine2 = cAvax1.Add_Line(bx1, by1, bz1, bx2, by2, bz2)
    d1 = DistanceFromPointToLine(ax1, ay1, bx1, by1, bx2, by2)
    d2 = DistanceFromPointToLine(ax2, ay2, bx1, by1, bx2, by2)
    If Abs(d1 - d2) <= 0.0001 Then MsgBox d1 Else MsgBox "error! not parallel lines"
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set oMath = Nothing
    Call cAvax1.EndAvax
End Sub

Function DistanceFromPointToLine(px1 As Single, py1 As Single, x1 As Single, y1 As Single, x2 As Single, y2 As Single) As Single
    Dim A As Single, B As Single, C As Single
    Call oMath.LineEquation(x1, y1, x2, y2, A, B, C)
    DistanceFromPointToLine = Abs(A * px1 + B * py1 + C) / Sqr(A ^ 2 + B ^ 2)
End Function

Athanasios Gardos
Avax-Software.com

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users