Results 1 to 3 of 3

Thread: Maths Stuff

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Hi,

    A few maths questions here. If i have a line that goes from 25,30 to 40,10 and another line moves towards it, how can i find if the end of the line collieds with it:


    |
    | <-- ----------------
    |
    |
    |
    |
    |
    So how would i work out if the horizontal line hit with the vertical one. Secondally. How would i do the same with too circles ?

    Excuse the art work.

  2. #2
    Hyperactive Member Wak's Avatar
    Join Date
    Nov 2000
    Location
    Brisbane, Queensland
    Posts
    298

    Talking LINE COLLISION

    Let line1.name = lne1
    Let line2.name = lne2

    Code:
    Private Sub Timer1_Timer()
        Dim x As Boolean
        Dim y As Boolean
        
        If (lne2.X1 < lne1.X2) And ((lne2.X2 > lne1.X1) And (lne2.X2 > lne1.X2)) Then x = True
        If (lne2.Y1 > lne1.Y1) Then y = True
        
        If (lne2.X1 > lne1.X2) And (lne2.X2 < lne1.X1) Then x = True
        If (lne2.Y2 > lne1.Y1) And (lne2.Y1 < lne1.Y1) And x = True Then y = True
        
        If x = True And y = True Then MsgBox "Colision Detected!"
        MsgBox "X: " & x & "Y: " & y
    End Sub

    I wasn't sure whether the lines where straight or diagonal, but this should work for both.
    Visual Basic 6.0 Enterprise
    Visual C++ 6.0 Professional

    Wak

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    A Reply, Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width