I have the coordinates of the top left point of a rectangle as well as its width, height and rotation from 0 to 180 and -0 to -180.
I am trying to get the bounding coordinates of the actual box around the rectangle.
What is a simple way of calculating the coordinates of the bounding box
- Min y, max y, min x, max x?
The A point is not always on the min y bound, it can be anywhere.
I can use matrix the transform toolkit in as3 if needed.
Although Code Guru stated the GetBounds() method, I've noticed the question is tagged as3, flex, so here is an as3 snippet that illustrates the idea.
I noticed that there two methods that seem to do the same thing: getBounds() and getRect()
if you are using GDI+ , you can create a new GrpaphicsPath -> Add any points or shapes to it -> Apply rotate transformation -> use GraphicsPath.GetBounds() and it will return a rectangle that bounds your rotated shape.
(edit) VB.Net Sample
End Sub
min_x
max_x
(min_x,min_y), (min_x,max_y), (max_x,max_y), (max_x,min_y)
AFAIK, there isn't any royal road that will get you there much faster.
If you are wondering how to transform the coordinates, try:
where (x0,y0) is the center around which you are rotating. You may need to tinker with this depending on your trig functions (do they expect degrees or radians) the sense / sign of your coordinate system vs. how you are specifying angles, etc.
I realize that you're asking for ActionScript but, just in case anyone gets here looking for the iOS or OS-X answer, it is this:
If your OS offers to do all the hard work for you, let it! :)
Swift: