Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3357366
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:37:27+00:00 2026-05-18T02:37:27+00:00

I need to create rectangles that are rotated around their center (so they don’t

  • 0

I need to create rectangles that are rotated around their center (so they don’t need to be parallel to the axes of the coordinate system). So basicelly each rectangle can be defined by center-X, center-Y, width, height and angle. What I want to do then is to perform calculations on whether certain points are contained in these rectangles or not (so no drawing will be involved). I guess I cant use the Rectangle2D class because these rectangles will always be parallel to the x and y-axis of the coordinate system. Is the only way to get this functionality by writing my own rectangle class or is there anything existing (similar to Rectangle2D) I can use?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:37:27+00:00Added an answer on May 18, 2026 at 2:37 am

    Rotate all the points you want to test and use contains(Point) method of the Rectangle2D as Mihai did.

    But if you really want to rotate the rectangles you can do it like this (this is the integer version but probably you can do it with Rectangle2D aswell :)).

    public class TestRotate {
        public static void main(String... args) {
    
            Rectangle r = new Rectangle(50, 50, 100, 100);
            Point check = new Point(100, 151); // clearly outside
    
            System.out.println("first: " + r.contains(check));
    
            AffineTransform at = AffineTransform.getRotateInstance(
                    Math.PI/4, r.getCenterX(), r.getCenterY());
    
            Polygon p = new Polygon(); 
    
            PathIterator i = r.getPathIterator(at);
            while (!i.isDone()) {
                double[] xy = new double[2];
                i.currentSegment(xy);
                p.addPoint((int) xy[0], (int) xy[1]);
                System.out.println(Arrays.toString(xy));
    
                i.next();
            }
    
            // should now be inside :)
            System.out.println("second: " + p.contains(check));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create a backup of a SQL Server 2005 Database that's only
I am uploading logos to my system, and they need to fix in a
I need to create a gradient that is 230dp high (i.e., not the whole
I'm trying to create a simple app that draws rectangles within the Canvas tag.
I am working on a project where I need to create a boundary around
i need to create a login screen in android that will look like this.
I need to create a rectangle bubble with rounded corners with text inside, like
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.