|
-
Aug 10th, 2002, 11:33 AM
#1
Thread Starter
New Member
Line Intersecting a Point
Hi all!
I have an easy question for you math buffs (which I have started studying once again... math... not buffs):
What is the equation to determine if a line intersects a given point? For example:
Consider Line(x1,y1)-(x2,y2)
Does this line intersect point xy?
As far as how I plan on using it:
A user may draw a line, then they may move that line by selecting it with a mouseup on the picture. I need to know if the user clicked the line, or clicked the background.
Thanks!
-
Aug 10th, 2002, 06:26 PM
#2
-
Aug 10th, 2002, 07:32 PM
#3
Thread Starter
New Member
Errr...
Thanks for your quick response, but that doesn't seem to work, with any of the numbers rearranged. Hmmn... let me try this:
Public Sub DrawPoint(byval Pnt as XYPoint)
'// draw a dot, green or red. Green if it is on the provided line.
Dim Ln as ALine '// with x1,y1,x2,y2
Dim RGBCol as RGBColor '// with R,G,B values
Ln.x1 = 50
Ln.y1 = 125
Ln.x2 = 139
Ln.y2 = 420
If IsOnThisLine(Pnt,Ln)
RGBCol.R = 0
RGBCol.G = 255
Else
RGBCol.R = 255
RGBCol.G = 0
End If
PictureTarget.PSet (Pnt.x,Pnt.y),RGB(RGBCol.R, RGBCol.G,0)
End Sub
Private Function IsOnThisLine(ByVal Pnt as XYPoint, ByVal Ln as ALine) As Boolean
Dim Res1 as Single
Dim Res2 as Single
'.... super code here....
End Function
-
Aug 11th, 2002, 11:39 AM
#4
-
Aug 11th, 2002, 12:00 PM
#5
Thread Starter
New Member
Actually, I did test it and with a little bit of modification it works well enough!
result1 = (x - x1) / (x2 - x1)
result2 = (Y - y1) / (y2 - y1)
result1 = Round(result1, 1)
result2 = Round(result2, 1)
If result1 = result2 Then
IsOnThisLine = True
Else
IsOnThisLine = False
End If
With a little additional logic (since its actually a line segment, not an infinite line) I will be now be able to determine if a user clicks close to the line! Yay!
Thanks man!
-
Aug 11th, 2002, 12:16 PM
#6
Frenzied 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
|