But don't forget to take vertical lines into account (in a
generalized algorithm) as you can't take their slope!
On Jul 17, 2005, at 11:51 AM, Asher Dunn wrote:
On Jul 17, 2005, at 1:51 AM, Martin Dillon wrote:
Given a line from x1,y1 to x2,y2 how can I calculate the minimum
distance of a mousedown at arbitrary location x3,y3 to the line?
The shortest distance from a point to a line is perpendicular to that
line. One way to solve this is to solve for the intersection of your
line and the line perpendicular that line through your point (the
mouse point). Find the slope of your line and get the negative
reciprocal of that to find the perpendicular. Then solve for the other
components of the line equation (y = mx + b) for both lines, and then
solve for the intersection of those two lines. If (x1, y1) and (x2,
y2) define a *line*, then that is your intersection. If they define a
*line segment*, then there are a few more steps. If the intersection
point is between (x1, y1) and (x2, y2), then you have your (x3, y3).
If not, then return either (x1, y1) or (x2, y2), depending on which is
closer to the intersection point.
If you need any help with the actual math involved, don't hesitate to
ask!
HTH!
Asher Dunn
--------------------------------------------------------
President and Head Developer of Fireye Software
<http://www.fireyesoftware.com/>
AIM and Yahoo: fireye7517
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
William H Squires Jr
wsquires at satx dot rr dot com dot nospam <- remove the .nospam
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|