Search code examples
androidmathrotationbounding-box

how to get rotated image region?


For example I got a picture position in 10,10 with width of 100 and height of 120. I centre rotated it clock-wise 20 degree, the position will be smaller and size will be bigger since the edge will be coming out, but how would I calculate the value for them?

No sure I made the question clear enough, will change it if I find a better way to explain it.

Trying to do this in Android


Solution

  • I assume that you want to know how the bounding box of an object is transformed if you rotate it around its center.

    If the original box has width w and height h, the new one, after rotation by r, has dimensions:

    wr = abs(sin(r)) * h + abs(cos(r)) * w
    hr = abs(sin(r)) * w + abs(cos(r)) * h