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
Medium Priority
574 Views
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
Question by:moshecristel
• 3
• 2

Accepted Solution

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.

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

Author Comment

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

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

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

Expert Comment

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

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