[02 Nov 2012]

# Trigonometry in Computer Graphics

During implementation of geometrical methods or development of shaders it's often required to make best possible optimizations to reduce number of calls of costly trigonometrical functions. Following article contains formulas that can be used during optimizations.

Angles

Radian is the unit of angular measure for 2D angles. One radian corresponds to arc of a circle with length that is equal radius of the circle.

• $1\;rad = 57.2957^{\circ}$
• $1^{\circ} = 0.0175\;rad$
• $inRadians = \frac{inAngles * \pi }{180}$
• $inAngles= \frac{inRadians*180}{\pi}$

Trigonometrical functions
From right triangle:
we get:
$sin(\theta)=\frac{opposite}{hypotenuse}=\frac{a}{c}$            $cos(\theta)=\frac{adjacent}{hypotenuse}=\frac{b}{c}$
$tan(\theta)=\frac{opposite}{adjacent}=\frac{a}{b}$            $cot(\theta)=\frac{adjacent}{opposite}=\frac{b}{a}$
$csc(\theta)=\frac{hypotenuse}{opposite}=\frac{c}{b}$            $sec(\theta)=\frac{hypotenuse}{adjacent}=\frac{c}{a}$

Reflected angle

$sin(-\theta)=-sin(\theta)$
$cos(-\theta)=cos(\theta)$
$tan(-\theta)= -tan(\theta)$

Angle and shift of 90 degrees

$sin(\frac{\pi}{2}-\theta)=cos(\theta)$
$cos(\frac{\pi}{2}-\theta)=sin(\theta)$
$tan(\frac{\pi}{2}-\theta)=cot(\theta)$

Other basic relations

$sin^{2}(\theta)+cos^{2}(\theta)=1$
$1+tan^{2}(\theta)=sec^{2}(\theta)$
$1+cot^{2}(\theta)=csc^{2}(\theta)$

Angle sum and difference

$sin(a\pm b)=sin(a)cos(b)\pm cos(a)sin(b)$
$cos(a\pm b)=cos(a)cos(b)\mp sin(a)sin(b)$
$tan(a\pm b)=\frac{tan(a)\pm tan(b)}{1\mp tan(a)tan(b)}$

Double-angle

$sin(2\theta)=2sin(\theta)cos(\theta)$
$cos(2\theta)=cos^{2}(\theta)-sin^{2}(\theta)=1-2sin^{2}(\theta)=2cos^{2}(\theta)-1$
$tan(2\theta)=\frac{2tan(\theta)}{1-tan^{2}(\theta)}$

Laws of cosines and sines

From arbitrary triangle:
we get:
$a=\sqrt{b^{2}+c^{2}-2bc*cos(A)}$
$a=b*cos(C)\pm \sqrt{c^{2}-b^{2}sin^{2}(C)}$
$C=arccos(\frac{a^{2}+b^{2}-c^{2}}{2ab})$
$\frac{sin(A)}{a}=\frac{sin(B)}{b}=\frac{sin(C)}{c}$

Sun and Black Cat- Igor Dykhta () © 2007-2014