hope this fix your issue The way I see it is like this... You work out the total width and total height of the rectangle. For that, you simply walk along two edges. Like this:

code :

```
dx = w * cos(theta) + h * sin(theta)
dy = h * cos(theta) + w * sin(theta)
```

```
rectratio = abs( dx / dy )
viewratio = R / K
```

```
if rectratio > viewratio
scale = R / abs(dx)
else
scale = K / abs(dy)
end
```

```
sw = scale * w
sh = scale * h
```

```
x[0] = 0
x[1] = x[0] + sw * cos(theta)
x[2] = x[1] + sh * sin(theta)
x[3] = x[2] - sw * cos(theta)
y[0] = 0
y[1] = y[0] - sw * sin(theta)
y[2] = y[1] + sh * cos(theta)
y[3] = y[2] + sw * sin(theta)
```

```
if( rectratio > viewratio )
// view is too tall, so centre vertically:
left = 0
top = (K - scale * abs(dy)) / 2.0
else
// view is too wide, so centre horizontally:
left = (R - scale * abs(dx)) / 2.0
top = 0
end
```

```
left += pxmin
top += pymin
```