Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Calculating corner points for rotated rectangle

Posted on 2003-03-11
5
Medium Priority
?
574 Views
Last Modified: 2008-03-06
I have a Rectangle object and I am trying to calculate where its four corner points would be if I were to rotate it counter-clockwise 45 degrees around its center.  Any ideas on an easy way to do this?
0
Comment
Question by:moshecristel
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
Rezantis earned 500 total points
ID: 8117669
Try the AffineTransform class, like so:

Polygon newShape = AffineTransform.getRotateInstance(angle, xCentre, yCentre).createTransformedShape(yourRectangle);

angle is the angle that you want to rotate the shape through, xCentre and yCentre are the x and y coordinates of the centre of your rectangle.

This will return you a new shape that will be your rectangle rotated through whatever angle you input.  For counterclockwise 45 degrees, you want (-Math.PI/4); at least I think so.

For more info, check the Javadocs:

http://java.sun.com/j2se/1.4.1/docs/api/java/awt/geom/AffineTransform.html
0
 

Author Comment

by:moshecristel
ID: 8119969
This seems like a very good idea but I can't seem to quite get it to work.  AffineTransform's createTransformedShape method doesn't return a Polygon but a GeneralPath and I haven't yet figured out how to get the corner points out of that.  Any ideas?
0
 

Author Comment

by:moshecristel
ID: 8120090
This seems like a very good idea but I can't seem to quite get it to work.  AffineTransform's createTransformedShape method doesn't return a Polygon but a GeneralPath and I haven't yet figured out how to get the corner points out of that.  Any ideas?
0
 

Author Comment

by:moshecristel
ID: 8129338
I was finally able to use the PathIterator to get the corner points.  Thanks for the help.
0
 

Expert Comment

by:Rezantis
ID: 8130625
Glad to help.  Sorry I didn't get back to you on the PathIterator bit; I was going to when I got home, then fell asleep when I got back from work.  ^^;
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question