Post

 Resources 

Console

Home | Profile | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 VBGamer
 VBGamer
 Help: Calculating point of streight line overlap

Note: You must be registered in order to post a reply.

Screensize:
UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List Spell Checker
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

   Insert an File
Check here to include your profile signature.
Check here to subscribe to this topic.
    

T O P I C    R E V I E W
cbx Posted - Jan 04 2005 : 8:38:24 PM
I created this function to find the intersection point between a vertical line and a second line that can be positioned anywhere.
The code works fine except when you try to overlap the two lines.

Public Function VLineIntersect(ByVal X1 As Single, ByVal Y1 As Single, ByVal X2 As Single, ByVal Y2 As Single, _  
                                  ByVal LineX As Single, ByVal Top As Single, ByVal Bottom As Single, ByRef Value As Single) As Boolean
        ' check if lines cross  
        If (X1 < LineX And X2 < LineX) Or (X1 > LineX And X2 > LineX) Then Return False
  
        Dim Aspect As Single
        Aspect = (Y2 - Y1) / (X2 - X1)  
        Dim YPos As Single
  
        YPos = Y1 + ((LineX - X1) * Aspect)  
        If YPos >= Top And YPos <= Bottom Then
            Value = YPos  
            Return True
        End If
  
        Return False
    End Function



Download Attachment: Line Collision Diagram.gif<br>993 Bytes

Now my problem is that I seem to have lost my precious brain somewhere and can't seem to find it. So I am having a little difficulty comming up with a mathmatical equation to calculate the intersection point.

The intersection point needs to be calculated by starting from the start of the red line, to the first position where the two lines meet. I could do this by writing a number of "If" statments but I would rather find a mathmatical solution to the problem.

In the attached image you can see the blue circle. it represents the intersection point from the start of the red line to the first position where the two lines cross each other. Any help would be apreciated. NOTE: The lines in the attached image do not overlap on purpose so that they can be better seen and demonstrate the overlap.

This equasion must also take into account that the bottom value of the vertical line may also be heigher then the top value. IE: fliped upside down.
3   L A T E S T    R E P L I E S    (Newest First)
cbx Posted - Jan 05 2005 : 10:56:07 PM
You think so? It just seems to me (looking at the code) there has to be a simpler way of doing this. (Regarding my second code post) 80% to 90% of the code is just for determining if both lines are vertical and at what point they overlap. Albeit there is no math required...
Eric Coleman Posted - Jan 05 2005 : 10:48:08 PM
A mathematical formulae may be more concise, but it won't necessarily be faster.
cbx Posted - Jan 05 2005 : 4:34:16 PM
As you can see I can use the fallowing code that relies on "If" statments to determin the intersection point ...

Public Function VLineIntersect(ByVal X1 As Single, ByVal Y1 As Single, ByVal X2 As Single, ByVal Y2 As Single, _  
                                   ByVal LineX As Single, ByVal Top As Single, ByVal Bottom As Single, ByRef Value As Single) As Boolean
        ' check if lines cross  
        If (X1 < LineX And X2 < LineX) Or (X1 > LineX And X2 > LineX) Then Return False
  
        Dim TY, BY As Single
        ' get top and bottm values for vert line  
        If Top > Bottom Then
            TY = Bottom  
            BY = Top  
        Else
            TY = Top  
            BY = Bottom  
        End If
  
        ' check if lines are both vertical and overlap  
        If X1 = X2 And X1 = LineX Then
            ' check if start point of line is inside vert line  
            If Y1 >= TY And Y1 <= BY Then
                Value = Y1  
                Return True
            End If
  
             ' check if line is pointing/facing/moving upwards  
            If Y1 > Y2 Then
                If Y1 >= BY And Y2 <= BY Then
                    Value = BY  
                    Return True
                End If
                If Y1 > BY Then Return False
            Else
                If Y1 <= TY And Y2 >= TY Then
                    Value = TY  
                    Return True
                End If
                If Y2 < TY Then Return False
            End If
        End If
  
        Dim YPos As Single
  
        YPos = Y1 + ((LineX - X1) * (Y2 - Y1) / (X2 - X1))  
  
        If YPos >= TY And YPos <= BY Then
            Value = YPos  
            Return True
        End If
  
        Return False
    End Function


... Although the code works I would like to replace the 'If ... else' logic with a mathmatical formula if possible.

VBGamer © Go To Top Of Page
This page was generated in 0.25 seconds. Snitz Forums 2000

Copyright © 2002 - 2004 Eric Coleman, Peter Kuchnio , et. al.