Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rectangle contains point

78 views
Skip to first unread message

bob smith

unread,
Oct 5, 2012, 3:00:38 PM10/5/12
to
So, I have a rectangle class as follows:

public class My_Rectangle {
double x, y, width, height;
AffineTransform aft;

Anyone know a good strategy for checking if a point is in the rectangle?

The main difficulty is the transform.

markspace

unread,
Oct 5, 2012, 3:20:23 PM10/5/12
to
http://lmgtfy.com/?q=computational+geometery

Seriously, it's a big subject. I don't have any easy answers.



Eric Sosman

unread,
Oct 5, 2012, 3:23:14 PM10/5/12
to
I'll assume that x/y/width/height represent an untransformed
rectangle, and that you want to test whether the point is inside
the quadrilateral formed by transforming the rectangle with aft.
If that's the question, I see two approaches:

- Transform the rectangle and represent the result as a
Polygon, then use Polygon's contains() method.

- Inverse-transform the point and test whether the transformed
point is inside the original rectangle.

If that's not the question, please explain more fully.

--
Eric Sosman
eso...@comcast-dot-net.invalid

Jeff Higgins

unread,
Oct 5, 2012, 3:43:15 PM10/5/12
to
John B. Matthews provided a strategy for this
in a reply to another of your recent posts.

bob smith

unread,
Oct 5, 2012, 5:16:01 PM10/5/12
to
Excellent ideas. I went with inverse transform, and it works.

Thanks.
0 new messages