JUAN JOSÉ IDROVO MACÍAS

Editor – Colorist – VFX

FORMULA: Scale To Fill, Given Rotation


Formula + Animation

scale factor=r|sinθ|+|cosθ|\text{scale factor} = r\abs{\sin\theta} + \abs{\cos\theta}

After Effects Code

r = degreesToRadians(transform.rotation);
s = thisComp.width/thisComp.height*Math.abs(Math.sin(r)) + Math.abs(Math.cos(r));
[s,s]*100

Derivation

Overview

To find the scale factor, we will first construct a rectangle (black) with half-height of 11 and half-width of rr (the aspect ratio). Next, we will construct an identical rectangle (red) with rotation AA about its center. Finally, we will construct a third rectangle (blue) identical to the second but scaled to circumscribe the first rectangle. See the figure below.

To find the scale factor, we must find the length of the half-height of the blue rectangle, that is, scale factor=c+e\text{scale factor} = c+e.

Setup

We will make use of the Law of Sines. Recall that

xsin(X)=ysin(Y)\frac{x}{\sin(X)} = \frac{y}{\sin(Y)}

where xx and yy are side lengths of any triangle, and XX and YY are their corresponding opposite angles.

Rearranging

x=ysin(X)sin(Y)x = \frac{y\sin(X)}{\sin(Y)}

Proof

Using the Law of Sines, find cc and ee.

c=1sin(90)sin(B)c = \frac{1\sin(90)}{\sin(B)}
c=1sin(B)c = \frac{1}{\sin(B)}
e=dsin(E)sin(90)e = \frac{d\sin(E)}{\sin(90)}
e=dsin(E)e = d\sin(E)

Now, find dd. Recall that rr is the half-width of the rectangle.

r=a+dr = a+d
d=rad = r-a
d=r1sin(A)sin(B)d = r – \frac{1\sin(A)}{\sin(B)}

Plug into ee.

e=dsin(E)e = d\sin(E)
e=(r1sin(A)sin(B))sin(E)e = (r-\frac{1\sin(A)}{\sin(B)}) \sin(E)
e=rsin(E)sin(A)sin(E)sin(B)e = r\sin(E)-\frac{\sin(A)\sin(E)}{\sin(B)}

Notice that AEA \cong E.

e=rsin(A)sin2(A)sin(B)e = r\sin(A)-\frac{\sin^2(A)}{\sin(B)}

Combine

scale factor=c+e\text{scale factor} = c+e
[1sin(B)]+[rsin(A)sin2(A)sin(B)][\frac{1}{\sin(B)}] + [r\sin(A) – \frac{\sin^2(A)}{\sin(B)}]
rsin(A)+1sin2(A)sin(B)r\sin(A) + \frac{1-\sin^2(A)}{\sin(B)}
rsin(A)+cos2(A)sin(B)r\sin(A) + \frac{\cos^2(A)}{\sin(B)}

Notice that cos(A)=sin(B)=1c\cos(A) = \sin(B) = \frac{1}{c} .

rsin(A)+cos(A)r\sin(A) + \cos(A)

Finally, substitute AA with θ\theta, and take the absolute value.

scale factor=r|sinθ|+|cosθ|\text{scale factor} = r\abs{\sin\theta} + \abs{\cos\theta}