rectangle contains point

Discussion in 'Java' started by bob smith, Oct 5, 2012.

  1. bob smith

    bob smith Guest

    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.
    bob smith, Oct 5, 2012
    #1
    1. Advertising

  2. bob smith

    markspace Guest

    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.
    markspace, Oct 5, 2012
    #2
    1. Advertising

  3. bob smith

    Eric Sosman Guest

    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
    d
    Eric Sosman, Oct 5, 2012
    #3
  4. bob smith

    Jeff Higgins Guest

    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.
    Jeff Higgins, Oct 5, 2012
    #4
  5. bob smith

    bob smith Guest

    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
    >
    > d


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

    Thanks.
    bob smith, Oct 5, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James Dyer
    Replies:
    5
    Views:
    643
  2. Kenneth

    Rectangle object in asp.net?

    Kenneth, Jan 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    544
    Steve C. Orr [MVP, MCSD]
    Jan 15, 2004
  3. Alberto

    Paint a rectangle

    Alberto, Jan 1, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    437
    Scott Mitchell [MVP]
    Jan 1, 2005
  4. Saraswati lakki
    Replies:
    0
    Views:
    1,322
    Saraswati lakki
    Jan 6, 2012
  5. Math55
    Replies:
    4
    Views:
    99
    Tad McClellan
    Jul 14, 2003
Loading...

Share This Page