rectangle contains point

B

bob smith

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.
 
E

Eric Sosman

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.

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.
 
J

Jeff Higgins

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.
John B. Matthews provided a strategy for this
in a reply to another of your recent posts.
 
B

bob smith

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

(e-mail address removed)

Excellent ideas. I went with inverse transform, and it works.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top