Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   rectangle contains point (http://www.velocityreviews.com/forums/t953087-rectangle-contains-point.html)

bob smith 10-05-2012 07:00 PM

rectangle contains point
 
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 10-05-2012 07:20 PM

Re: rectangle contains point
 
On 10/5/2012 12:00 PM, bob smith wrote:
> 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.



http://lmgtfy.com/?q=computational+geometery

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




Eric Sosman 10-05-2012 07:23 PM

Re: rectangle contains point
 
On 10/5/2012 3:00 PM, bob smith wrote:
> 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.

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

Jeff Higgins 10-05-2012 07:43 PM

Re: rectangle contains point
 
On 10/05/2012 03:00 PM, bob smith wrote:
> 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.

bob smith 10-05-2012 09:16 PM

Re: rectangle contains point
 
On Friday, October 5, 2012 2:23:18 PM UTC-5, Eric Sosman wrote:
> On 10/5/2012 3:00 PM, bob smith wrote:
>
> > 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.
>
>
>
> --
>
> Eric Sosman
>
> esosman@comcast-dot-net.invalid


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

Thanks.


All times are GMT. The time now is 10:16 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57