Results 1 to 5 of 5
  1. #1
    Dex
    Dex is offline Member
    Join Date
    Mar 2012
    Posts
    29
    Rep Power
    0

    Unhappy Intersection of two Rectangles

    Hey, Im struck trying to write some code.
    Im trying to use the Intersection method , to print out the dimensions + position of the new rectangle(r3) that the intersection of two rectangles (randRectangle and box) makes. (hope that makes sense).
    I already know how to create my two rectangles but I do not know how to do the intersection part and i must only use: import java.awt.Rectangle;

    randRectangle and box are my two created rectangles

    This is what i have so far...
    Java Code:
        Rectangle r3 = randRectangle.intersection(box);
        System.out.println(r3.toString());


    Thanks

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default Re: Intersection of two Rectangles

    Read the API documentation for the Rectangle class; you're almost there.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    Dex
    Dex is offline Member
    Join Date
    Mar 2012
    Posts
    29
    Rep Power
    0

    Default Re: Intersection of two Rectangles

    Quote Originally Posted by JosAH View Post
    Read the API documentation for the Rectangle class; you're almost there.

    kind regards,

    Jos
    Ok thanks Ill have a look now!
    Also I tried to do an If, else statement for if there there is intersection or not but I wasn't sure what to write as I've only ever used booleans for them. Any pointers?

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,044
    Blog Entries
    7
    Rep Power
    23

    Default Re: Intersection of two Rectangles

    Quote Originally Posted by Dex View Post
    Ok thanks Ill have a look now!
    Also I tried to do an If, else statement for if there there is intersection or not but I wasn't sure what to write as I've only ever used booleans for them. Any pointers?
    It's all in the API documentation for the Rectangle class; read about it in the isEmpty() method (two Rectangles that don't intersect return an empty Rectangle).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  5. #5
    Dex
    Dex is offline Member
    Join Date
    Mar 2012
    Posts
    29
    Rep Power
    0

    Default Re: Intersection of two Rectangles

    Thank you Jos , seems to be working now :)

Similar Threads

  1. Replies: 2
    Last Post: 12-05-2011, 03:00 AM
  2. Intersection of 2 Polynomials Algorithm
    By gberg927 in forum New To Java
    Replies: 2
    Last Post: 04-17-2011, 05:07 PM
  3. Volume of Intersection
    By afifi in forum Advanced Java
    Replies: 0
    Last Post: 01-07-2011, 11:42 AM
  4. Rectangle Intersection
    By Gwindow in forum Java 2D
    Replies: 1
    Last Post: 04-24-2008, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •