Newsgroups: comp.robotics
Path: brunix!cat.cis.Brown.EDU!agate!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!llyene!heller.jpl.nasa.gov!Donald.Heller
From: Donald.Heller@jpl.nasa.gov (Don Heller)
Subject: Re: Point in a rectangle
Message-ID: <Donald.Heller.153.00085A91@jpl.nasa.gov>
Lines: 35
Sender: news@llyene.jpl.nasa.gov
Organization: Jet Propulsion Laboratory
X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
References:  <31q3jj$hoh@schema.fiu.edu>
Date: Fri, 5 Aug 1994 16:21:10 GMT

In article <31q3jj$hoh@schema.fiu.edu> mookherj@fiu.edu (Jay Mookherje) writes:
>Path: llyene!elroy.jpl.nasa.gov!usc!cs.utexas.edu!swrinde!emory!europa.eng.gtefsd.com!MathWorks.Com!usenet.fiu.edu!mookherj
>From: mookherj@fiu.edu (Jay Mookherje)
>Newsgroups: comp.robotics
>Subject: Point in a rectangle
>Date: 4 Aug 1994 06:58:59 GMT
>Organization: Florida International Univeristy
>Lines: 9
>Message-ID: <31q3jj$hoh@schema.fiu.edu>
>NNTP-Posting-Host: solix-gw.fiu.edu
>X-Newsreader: TIN [version 1.2 PL2]


>Maybe this question has been asked a million times before, but I would
>really appreciate if someone could tell me an efficient way of finding if
>a particular point lies inside a rectangle (of arbitrary orientation).

>Please direct all responses to mookherj@fiu.edu.

>Thanks in advance,
>Jay

Why don't you buy or borrow a first year college book on Vector Analysis.
There is an easy section on finding the distance from a point to a line.
You take each edge of the rectangle and convert it to vector notation.
Then you do this for each of the four edges.  If the two vectors (from
the point to each of the opposite parallel edges) have opposite directions,
the point is between those edges.  If the other two vectors (from the point
to each of the remaining two edges) also have opposite directions, then the
point is totally within the rectangle.  The degenerate cases are easy...
If a vector has zero length, the point is ON the edge.  If two orthogonal
vectors are both zero, the point is ON the corner.

Don

