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: Asher Dunn <asher at fireyesoftware dot com>
Date: Sun, 17 Jul 2005 12:51:20 -0400
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <006b01c58a93$a03ac980$6400a8c0 at xp>

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>

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