|
-
Nov 26th, 2008, 03:20 PM
#1
Thread Starter
Hyperactive Member
-
Nov 26th, 2008, 03:45 PM
#2
Thread Starter
Hyperactive Member
-
Nov 26th, 2008, 06:38 PM
#3
Re: [2005] Line Collision
-
Nov 27th, 2008, 05:15 AM
#4
Thread Starter
Hyperactive Member
Re: [2005] Line Collision
Thanks but what do I put for the the a1, a2, b1 and b2 arguments?
I presume the A1 and A2 arguments are angles. Are the B1 and B2 arguments how long the line is?
At the moment my code is:
Code:
SegmentsIntersect(5,5,50,5,??,??,??,??)
What are the bold arguments?
Code:
' Return True if the segments intersect.
Private Function SegmentsIntersect(ByVal X1 As Single, _
ByVal Y1 As Single, ByVal X2 As Single, ByVal Y2 As _
Single, ByVal A1 As Single, ByVal B1 As Single, ByVal _
A2 As Single, ByVal B2 As Single) As Boolean
Dim dx As Single
Dim dy As Single
Dim da As Single
Dim db As Single
Dim t As Single
Dim s As Single
dx = X2 - X1
dy = Y2 - Y1
da = A2 - A1
db = B2 - B1
If (da * dy - db * dx) = 0 Then
' The segments are parallel.
SegmentsIntersect = False
Exit Function
End If
s = (dx * (B1 - Y1) + dy * (X1 - A1)) / (da * dy - db * _
dx)
t = (da * (Y1 - B1) + db * (A1 - X1)) / (db * dx - da * _
dy)
SegmentsIntersect = (s >= 0# And s <= 1# And _
t >= 0# And t <= 1#)
' If it exists, the point of intersection is:
' (x1 + t * dx, y1 + t * dy)
End Function
Last edited by knxrb; Nov 27th, 2008 at 05:25 AM.
Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

-
Nov 27th, 2008, 05:32 AM
#5
Re: [2005] Line Collision
At a glance I'd guess that the Xs and Ys are the end points of one line and the As and Bs are the end points of the other.
-
Nov 27th, 2008, 05:37 AM
#6
Thread Starter
Hyperactive Member
Re: [2005] Line Collision
With the arguments set to the end points of the lines it doesn't work: 
Code:
e.Graphics.DrawLine(Pens.Black, 5, 5, 50, 50)
e.Graphics.DrawLine(Pens.Black, 50, 5, 20, 80)
e.Graphics.DrawString(SegmentsIntersect(5, 5, 50, 5, 50, 50, 20, 80), Me.Font, Brushes.Black, 50, 50)
[EDIT]
What I'm trying to do is get it so I can check if the direction the circle is heading in will make the circle collide with the square(see picture).

[EDIT]
Last edited by knxrb; Nov 27th, 2008 at 05:45 AM.
Did I help you with your problem? If I did rate me by clicking here: Rate knxrb

-
Nov 27th, 2008, 05:49 AM
#7
Re: [2005] Line Collision
Why dont you use the values of the line, rather than hand written co-ords remove room for error. If that still fails can you post up your app. I may have time to take a look
Pino
-
Nov 27th, 2008, 05:52 AM
#8
Thread Starter
Hyperactive Member
-
Nov 27th, 2008, 05:56 AM
#9
Re: [2005] Line Collision
Ok, can you give me the lowdown on what you are trying to achieve?
-
Nov 27th, 2008, 06:01 AM
#10
Thread Starter
Hyperactive Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|