java - What is the correct way to convert a Shape to a Rectangle2D.Double? -
I need to change a rectangle2D.Double
(rotate). However, I do not need to attract the shape, I need to keep the changing rectangle in the form of an object so that I can use the .intersects ()
and other methods. This is the current way I am changing it
Personal Rectangle 2D Double Transform (Rectangle2D.Double rect) {// change a new AffineTransform transform = new AffineTransform (); // Apply conversion changes. Rotate (Math.Tudian (Theta), rect.x + rect.width / 2, rect.y + rect.height / 2); // Find the resulting size s = transform.createTransformedShape (hitbox); // Final rectangular rectangle return //? }
Now, someone can think that the following will work
Rectangle2D.Double newRect = new Rectangle2D.Double (); NewRect.setFrame (transform.createTransformedShape (Rect) .getBounds2D ());
However, when it is drawn, it does not seem that it can rotate in any way, rather in large quantities (140x larger).
is: How can I get it size
, the way in which it is dragged, correctly changes to a correct form, a rectangle2D.Double
?
If this is not possible then what is a good option which is still .intersects ()
and similar methods?
rectangle 2D
is axis-axis that can not be turned on instead Try using a Path2D
is a good creator what you really want:
Personal Path 2D Double Transform (Rectangle 2D Double Rect) {AffineTransform transform = new AffineTransform (); Double Angle = Math Triadian (theta); Transform.rotate (angle, rect.x + rect.width / 2, rect.y + rect.height / 2); Return the new path 2D. Double (Rect, Transform); }
Also keep in mind that your toRadians (toRadians (theta))
is very suspicious and makes your angle too small.
Comments
Post a Comment