realbasic-games
[Top] [All Lists]

Re: 2D geometry/trigonometry question

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: 2D geometry/trigonometry question
From: William Squires <wsquires at satx dot rr dot com>
Date: Mon, 18 Jul 2005 16:46:50 -0500
Cc:
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <006b01c58a93$a03ac980$6400a8c0 at xp> <0b8e035eafcf23ace5c42b93bf04f1ad at fireyesoftware dot com>
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>

<Prev in Thread] Current Thread [Next in Thread>