3D Orientation 
Rotation matrix
9 numbers to represent 3D orientation, i.e. upper-left 3x3 block of a 4x4 transformation matrix. 
Usually, all other orientation representations are converted into a rotation matrix. 
 
 
Fixed angles/Euler Angles/Yaw-Pitch-Roll
3 numbers can represent any 3D orientation 
TODO: Insert image. 
Euler's rotation theorem
Any rotation can be expressed as a single rotation about some axis 
4 numbers to represent a 3D orientation 
 
 
Prone to gimbal lock . 
 
 
Quaternions
Interpolation is easy  using (S)LERP between begin and end quaternions. 
i 2 = j 2 = k 2 = i j k = − 1 i^2 = j^2 = k^2 = ijk = -1 i 2 = j 2 = k 2 = ijk = − 1 i j = k , j k = i , k i = j ij = k, jk = i, ki = j ij = k , jk = i , ki = j j i = k , k j = − i , i k = − j ji = k, kj = -i, ik = -j ji = k , kj = − i , ik = − j  
w + x i + y j + z l    ⟺    ( w , x , y , k )    ⟺    ( w , v ⃗ ) w + xi + yj + zl \iff (w, x, y, k) \iff (w, \vec{v})
 w + x i + y j + z l ⟺ ( w , x , y , k ) ⟺ ( w , v ) 
Quaternion algebra
q 0 = ( w 0 , v ⃗ 0 ) , q 1 = ( w 1 , v ⃗ 1 ) q_0 = (w_0, \vec{v}_0), q_1 = (w_1, \vec{v}_1) q 0  = ( w 0  , v 0  ) , q 1  = ( w 1  , v 1  ) q 1 q 0 = ( w 1 w 0 − v ⃗ 1 ⋅ v ⃗ 0 , w 1 v ⃗ 0 + w 0 v ⃗ 1 + v ⃗ 1 × v ⃗ 0 ) q_1q_0 = (w_1w_0 - \vec{v}_1 \cdot \vec{v}_0, w_1\vec{v}_0 + w_0\vec{v}_1 + \vec{v}_1 \times \vec{v}_0) q 1  q 0  = ( w 1  w 0  − v 1  ⋅ v 0  , w 1  v 0  + w 0  v 1  + v 1  × v 0  ) q 1 q 0 ≠ q 0 q 1 q_1 q_0 \neq q_0 q_1 q 1  q 0   = q 0  q 1   
 
Unit quaternions can be used to represent 3D rotations
Let w = cos  ( 1 2 θ ) w = \cos \left(\frac{1}{2}\theta\right) w = cos ( 2 1  θ ) v ⃗ = sin  ( 1 2 θ ) r ^ \vec{v} = \sin \left(\frac{1}{2}\theta\right)\hat{r} v = sin ( 2 1  θ ) r ^  
 
 
 
 
 
 Interpolation 
 LERP: Linear Interpolation 
q ⃗ ( u ) = ( 1 − u ) q ^ ( u ) = q ⃗ ( u ) ∥ q ⃗ ( u ) ∥ 2 \begin{align}
    \vec{q}(u) &= (1-u)\\
    \hat{q}(u) &= \frac{\vec{q}(u)}{\|\vec{q}(u)\|_2}
\end{align}
 q  ( u ) q ^  ( u )  = ( 1 − u ) = ∥ q  ( u ) ∥ 2  q  ( u )    
 SLERP: Spherical Linear Interpolation 
q ^ ( u ) = sin  ( ( 1 − u ) θ ) sin  θ q ^ 0 + sin  ( u θ ) sin  θ q ^ 1 θ = arccos  ( q ⃗ 0 ⋅ q ⃗ 1 ∥ q ⃗ 0 ∥ 2   ∥ q ⃗ 1 ∥ 2 ) \begin{align}
    \hat{q}(u) &= \frac{\sin ((1 - u) \theta)}{\sin \theta} \hat{q}_0 + \frac{\sin (u \theta)}{\sin \theta}\hat{q}_1\\
    \theta &= \arccos \left(\frac{\vec{q}_0 \cdot \vec{q}_1}{\|\vec{q}_0\|_2\,\|\vec{q}_1\|_2}\right)
\end{align}
 q ^  ( u ) θ  = sin θ sin (( 1 − u ) θ )  q ^  0  + sin θ sin ( u θ )  q ^  1  = arccos ( ∥ q  0  ∥ 2  ∥ q  1  ∥ 2  q  0  ⋅ q  1   )   
 LERP vs. SLERP 
SLERP gives constant rotation speed 
LERP can interpolate between more than 2 quaternions
q ⃗ ( α , β , γ ) = α q ^ 0 + β q ^ 1 + γ q ^ 2 \vec{q}(\alpha, \beta, \gamma) = \alpha\hat{q}_0 + \beta\hat{q}_1 + \gamma\hat{q}_2 q  ( α , β , γ ) = α q ^  0  + β q ^  1  + γ q ^  2  q ^ ( α , β , γ ) = norm ( q ⃗ ) \hat{q}(\alpha, \beta, \gamma) = \textrm{norm}(\vec{q}) q ^  ( α , β , γ ) = norm ( q  )  
 
LERP is easier to use with splines 
 
 Long vs. Short Path 
When interpolating rotations with quaternions, there is a short and long way to get to the target rotation.
For example, if we want to rotate right by 90 degrees, we can choose to add 90 degrees to our orientation or -270 degrees.
We want to choose the short path to prevent any weird artifacts.
 Arc Length Parameterization 
Problem: Distance in world space is not the same as u u u 
E.g. the distance ∥ p ( u ) ∥ \|p(u)\| ∥ p ( u ) ∥ u ∈ [ 1 , 1.1 ] u \in [1, 1.1] u ∈ [ 1 , 1.1 ] u ∈ [ 3 , 3.1 ] u \in [3, 3.1] u ∈ [ 3 , 3.1 ] 0.1 0.1 0.1 
Given 2 u u u arc length  between them?
S = ∫ u 0 u 1 ∥ p ⃗   ′ ( u ) ∥ 2   d u \begin{equation}
  S = \int_{u_0}^{u_1}\|\vec{p}^{\,\prime}(u)\|_2\,\mathrm{d}u
\end{equation}
 S = ∫ u 0  u 1   ∥ p  ′ ( u ) ∥ 2  d u   
Unfortunately, this intergral is intractable.
A crude approximation can be obtained by computing the following
S ≈ ∥ p ⃗ ( u 1 ) − p ⃗ ( u 0 ) ∥ 2 \begin{equation}
  S \approx \|\vec{p}(u_1) - \vec{p}(u_0)\|_2
\end{equation}
 S ≈ ∥ p  ( u 1  ) − p  ( u 0  ) ∥ 2    
and building a lookup table between u u u s . s. s . 
Both u u u s s s  
We increase u u u Δ u \Delta u Δ u  
Note that s s s  
 
Lookup Table Construction
u u u ← \leftarrow ← 0 0 0 s s s ← \leftarrow ← 0 0 0 insert ( u , s ) (u, s) ( u , s )  
  
while  not  done do 
s s s ← \leftarrow ← s + a r c l e n g t h ( u , u → Δ u ) s + \mathrm{arclength}(u, u \rightarrow \Delta u) s + arclength ( u , u → Δ u ) u u u ← \leftarrow ← u + Δ u u + \Delta u u + Δ u insert ( u , s ) (u, s) ( u , s )  
 
 
With this table we can perform lookups in either direction: u ↣ s u \rightarrowtail s u ↣ s s ↣ u s \rightarrowtail u s ↣ u 
Lookup Table
We'll use the following lookup table for the next few examples.
index 
u u u s s s  
 
0 
0.0 
0.0 
 
1 
0.1 
2.0 
 
2 
0.2 
3.0 
 
3 
0.3 
3.5 
 
4 
0.4 
5.0 
 
5 
0.5 
8.0 
 
 
u ↣ s u \rightarrowtail s u ↣ s 
Given u = 0.371 , u = 0.371, u = 0.371 , s ? s? s ? 
We compute the indices for the lower and upper bound of the table, the lower bound for an arbitrary u u u ⌊ u Δ u ⌋ , \left\lfloor\frac{u}{\Delta u}\right\rfloor, ⌊ Δ u u  ⌋ , 
Using these indicies, we get u 0 = 0.3 u_0 = 0.3 u 0  = 0.3 u 1 = 0.4 u_1 = 0.4 u 1  = 0.4 s 0 = 3.5 , s_0 = 3.5, s 0  = 3.5 , s 1 = 5.0. s_1 = 5.0. s 1  = 5.0. 
Then,
α = u − u 0 Δ u = 0.371 − 0.3 0.4 − 0.1 S = ( 1 − α ) S 0 + α S 1 = 3.5   ( 1 − α ) + 5   α = 4.565 \begin{align*}
    \alpha &= \frac{u - u_0}{\Delta u} = \frac{0.371 - 0.3}{0.4 - 0.1}\\
    S &= (1 - \alpha) S_0 + \alpha S_1 = 3.5\,(1 - \alpha) + 5\,\alpha = 4.565
\end{align*}
 α S  = Δ u u − u 0   = 0.4 − 0.1 0.371 − 0.3  = ( 1 − α ) S 0  + α S 1  = 3.5 ( 1 − α ) + 5 α = 4.565  
s ↣ u s \rightarrowtail u s ↣ u 
Given s = 3.2 , s = 3.2, s = 3.2 , u ? u? u ? 
First, we find S S S S . S. S . 
Unfortunately, this is not possible to do in constant time:
O ( n ) \mathcal{O}(n) O ( n ) O ( log  n ) \mathcal{O}(\log n) O ( log  n )  
In this example, 3.0 3.0 3.0 3.5 3.5 3.5 2 2 2 3 3 3 
α = ( S − S 0 ) / ( S 1 − S 0 ) = ( S − 3 ) / ( 3.5 − 3 ) = 0.4 \begin{align*}
    \alpha &= (S - S_0) / (S_1 - S_0)\\
    &= (S - 3) / (3.5 - 3)\\
    &= 0.4
\end{align*}
 α  = ( S − S 0  ) / ( S 1  − S 0  ) = ( S − 3 ) / ( 3.5 − 3 ) = 0.4  
Then,
u = ( 1 − α ) u 0 + α u 1 = ( 0.6 ) ( 0.2 ) + ( 0.4 ) ( 0.3 ) = 0.24 u = (1 - \alpha) u_0 + \alpha u_1 = (0.6)(0.2) + (0.4)(0.3) = 0.24
 u = ( 1 − α ) u 0  + α u 1  = ( 0.6 ) ( 0.2 ) + ( 0.4 ) ( 0.3 ) = 0.24 
 Time Control 
Without interpolation, the speed at which we move between control points is dependent on the positions of those points; i.e. the farther away two points the faster we move between them.
With (S)LERP we learned how to interpolate between the points at a constant speed.
Here, we talk about controling the speed with an arbitrary curve.
Note : The discontinuities in these control functions can be represented as fp NaNs or ∞ \infty ∞ 
 
We can use a cubic fit
s ( t ) = a t 3 + b t 2 + c t + d \begin{equation}
  s(t) = at^3 + bt^2 + ct + d
\end{equation}
 s ( t ) = a t 3 + b t 2 + c t + d   
we need 4 4 4 ( a , b , c , d ) . (a, b, c, d). ( a , b , c , d ) . 
Cubic Fit
TODO: Add graph.
s ( t = 0 ) = 0    ⟹    0 = a ⋅ 0 3 + b ⋅ 0 2 + c ⋅ 0 + d s ( t = 0.9 ) = 2.5    ⟹    2.5 = a ⋅ 0.9 3 + b ⋅ 0.9 2 + c ⋅ 0.9 + d s ( t = 2 ) = 1.5    ⟹    1.5 = a ⋅ 2 3 + b ⋅ 2 2 + c ⋅ 2 + d s ( t = 3 ) = 4    ⟹    4 = a ⋅ 3 3 + b ⋅ 3 2 + c ⋅ 3 + d \begin{align*}
  s(t=0) = 0 &\implies 0 = a \cdot 0^3 + b \cdot 0^2 + c \cdot 0 + d\\
  s(t=0.9) = 2.5 &\implies 2.5 = a \cdot 0.9^3 + b \cdot 0.9^2 + c \cdot 0.9 + d\\
  s(t=2) = 1.5 &\implies 1.5 = a \cdot 2^3 + b \cdot 2^2 + c \cdot 2 + d\\
  s(t=3) = 4 &\implies 4 = a \cdot 3^3 + b \cdot 3^2 + c \cdot 3 + d
\end{align*}
 s ( t = 0 ) = 0 s ( t = 0.9 ) = 2.5 s ( t = 2 ) = 1.5 s ( t = 3 ) = 4  ⟹ 0 = a ⋅ 0 3 + b ⋅ 0 2 + c ⋅ 0 + d ⟹ 2.5 = a ⋅ 0. 9 3 + b ⋅ 0. 9 2 + c ⋅ 0.9 + d ⟹ 1.5 = a ⋅ 2 3 + b ⋅ 2 2 + c ⋅ 2 + d ⟹ 4 = a ⋅ 3 3 + b ⋅ 3 2 + c ⋅ 3 + d  
Next, we express this as a system A x ⃗ = b ⃗ A\vec{x} = \vec{b} A x = b x ⃗ = ( a , b , c , d ) \vec{x} = (a, b, c, d) x = ( a , b , c , d ) b ⃗ \vec{b} b s ( t ) : s(t): s ( t ) : 
( 0 0 0 1 0.9 3 0.9 2 0.9 1 2 3 2 2 2 1 3 3 3 2 3 1 ) ( a b c d ) = ( 0 2.5 1.5 4 ) \begin{pmatrix}
  0 & 0 & 0 & 1\\
  0.9^3 & 0.9^2 & 0.9 & 1\\
  2^3 & 2^2 & 2 & 1\\
  3^3 & 3^2 & 3 & 1
\end{pmatrix}
\begin{pmatrix}
  a\\
  b\\
  c\\
  d
\end{pmatrix} =
\begin{pmatrix}
  0\\
  2.5\\
  1.5\\
  4
\end{pmatrix}
  0 0. 9 3 2 3 3 3  0 0. 9 2 2 2 3 2  0 0.9 2 3  1 1 1 1    a b c d   =  0 2.5 1.5 4   
In our assignments, we would use GLM or Eigen to solve this linear system.
Cubic Fit with Derivative
TODO: Add graph.
Additionally, we can use three points along with a derivative of the curve instead of four.
s ( t = 0.0 ) = 0 s ( t = 0.5 ) = 0.5 s ( t = 1.0 ) = 1 s ′ ( t = 0.5 ) = − 1 \begin{align*}
  s(t = 0.0) &= 0\\
  s(t = 0.5) &= 0.5\\
  s(t = 1.0) &= 1\\
  s'(t = 0.5) &= -1
\end{align*}
 s ( t = 0.0 ) s ( t = 0.5 ) s ( t = 1.0 ) s ′ ( t = 0.5 )  = 0 = 0.5 = 1 = − 1  
Let s ( t ) s(t) s ( t ) s ′ ( t ) = 3 a t 2 + 2 b t + c . s'(t) = 3at^2 + 2bt + c. s ′ ( t ) = 3 a t 2 + 2 b t + c . 
Then the constraints for s ( t ) s(t) s ( t ) s ′ ( 0.5 ) = − 1    ⟹    − 1 = 3 a ( 0.5 ) 2 + 2 b ( 0.5 ) + c . s'(0.5) = -1 \implies -1 = 3a(0.5)^2 + 2b(0.5) + c. s ′ ( 0.5 ) = − 1 ⟹ − 1 = 3 a ( 0.5 ) 2 + 2 b ( 0.5 ) + c . 
Finally, the system is given by
( 0 0 0 1 0.5 3 0.5 2 0.5 1 1 1 1 1 3 ( 0.5 ) 2 2 ( 0.5 ) 1 0 ) ( a b c d ) = ( 0 0.5 1 − 1 ) \begin{pmatrix}
  0 & 0 & 0 & 1\\
  0.5^3 & 0.5^2 & 0.5 & 1\\
  1 & 1 & 1 & 1\\
  3(0.5)^2 & 2(0.5) & 1 & 0
\end{pmatrix}
\begin{pmatrix}
  a\\
  b\\
  c\\
  d
\end{pmatrix} =
\begin{pmatrix}
  0\\
  0.5\\
  1\\
  -1
\end{pmatrix}
  0 0. 5 3 1 3 ( 0.5 ) 2  0 0. 5 2 1 2 ( 0.5 )  0 0.5 1 1  1 1 1 0    a b c d   =  0 0.5 1 − 1   
Note:  Fitting higher order polynomials are prone to oscillations (see: Runge's phenomenon ).
Soln 
 
Cubic with 2 Curves
TODO: Add graph.
s 1 ( t ) = a 1 t 3 + b 1 t 2 + c 1 t + d 1 s 2 ( t ) = a 2 t 3 + b 2 t 2 + c 2 t + d 2 \begin{align*}
  s_1(t) &= a_1 t^3 + b_1 t^2 + c_1 t + d_1\\
  s_2(t) &= a_2 t^3 + b_2 t^2 + c_2 t + d_2
\end{align*}
 s 1  ( t ) s 2  ( t )  = a 1  t 3 + b 1  t 2 + c 1  t + d 1  = a 2  t 3 + b 2  t 2 + c 2  t + d 2   
We now have 8 unknowns, so we need 8 conditions.
In our example, we want the two curves to connect at the end of s 1 s_1 s 1  s 2 , s_2, s 2  , s 1 ( t = 0.5 ) = s 2 ( t = 0.5 ) . s_1(t=0.5) = s_2(t=0.5). s 1  ( t = 0.5 ) = s 2  ( t = 0.5 ) . 
The system is given by this block matrix:
[ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ∣ ∣ ∣ ∣ 0 0 ∣ ∣ ∣ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ∣ ⋅ ⋅ ⋅ ⋅ ] [ a 1 b 1 c 1 d 1 a 2 b 2 c 2 d 2 ] = [ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0 ] \begin{bmatrix}
  \begin{matrix}
    \cdot & \cdot & \cdot & \cdot\\
    \cdot & \cdot & \cdot & \cdot\\
    \cdot & \cdot & \cdot & \cdot\\
    \cdot & \cdot & \cdot & \cdot
  \end{matrix} & \begin{matrix}|\\|\\|\\|\end{matrix} & 0\\
  \hline
  0 & \begin{matrix}|\\|\\|\end{matrix} & \begin{matrix}
    \cdot & \cdot & \cdot & \cdot\\
    \cdot & \cdot & \cdot & \cdot\\
    \cdot & \cdot & \cdot & \cdot
  \end{matrix}\\
  \hline\begin{matrix}\cdot & \cdot & \cdot & \cdot\end{matrix} &
  | &
  \begin{matrix}\cdot & \cdot & \cdot & \cdot\end{matrix}
\end{bmatrix}
\begin{bmatrix}
  a_1\\b_1\\c_1\\d_1\\a_2\\b_2\\c_2\\d_2
\end{bmatrix} =
\begin{bmatrix}
  \cdot\\\cdot\\\cdot\\\cdot\\\cdot\\\cdot\\\cdot\\0
\end{bmatrix}
  ⋅ ⋅ ⋅ ⋅  ⋅ ⋅ ⋅ ⋅  ⋅ ⋅ ⋅ ⋅  ⋅ ⋅ ⋅ ⋅  0 ⋅  ⋅  ⋅  ⋅   ∣ ∣ ∣ ∣  ∣ ∣ ∣  ∣  0 ⋅ ⋅ ⋅  ⋅ ⋅ ⋅  ⋅ ⋅ ⋅  ⋅ ⋅ ⋅  ⋅  ⋅  ⋅  ⋅      a 1  b 1  c 1  d 1  a 2  b 2  c 2  d 2    =  ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ 0   
Again, solve using some library like Eigen. Like the previous example, we can also add a constraint on the derivative, i.e. s 1 ′ ( t = 0.5 ) = s 2 ′ ( t = 0.5 ) . s_1'(t=0.5) = s_2'(t=0.5). s 1 ′  ( t = 0.5 ) = s 2 ′  ( t = 0.5 ) . 
 Gaussian Quadrature 
Recall the arc length formula Eq. (5)
s = ∫ u 0 u 1 ∥ p ⃗   ′ ( u ) ∥ 2   d u s = \int_{u_0}^{u_1}\|\vec{p}^{\,\prime}(u)\|_2\,\mathrm{d}u
 s = ∫ u 0  u 1   ∥ p  ′ ( u ) ∥ 2  d u 
Using the $us-$Table method, we linearly interpolate between u 0 u_0 u 0  u 1 u_1 u 1  Δ u \Delta u Δ u 
However, we can better approximate this integral using Gaussian quadrature,
∫ − 1 1 f ( x ) d x ≈ ∑ i = 1 n w i f ( x i ) \begin{equation}
  \int_{-1}^{1} f(x) \mathrm{d}x \approx \sum_{i=1}^{n} w_i f(x_i)
\end{equation}
 ∫ − 1 1  f ( x ) d x ≈ i = 1 ∑ n  w i  f ( x i  )   
this is a weighted sum of the function's values, as n → i n f t y n \to infty n → in f t y 
For n = 1 n = 1 n = 1 x 1 = 0 x_1 = 0 x 1  = 0 w 1 = 2 w_1 = 2 w 1  = 2  
For n = 2 n = 2 n = 2 
x 1 = − 1 / 3 , w 1 = 1 x_1 = -1/\sqrt{3}, w_1 = 1 x 1  = − 1/ 3  , w 1  = 1 x 2 = 1 / 3 , w 2 = 1 x_2 = 1/\sqrt{3}, w_2 = 1 x 2  = 1/ 3  , w 2  = 1  
 
For n = 3 n = 3 n = 3 
x 1 = 3 / 5 , w 1 = 5 / 9 x_1 = \sqrt{3/5}, w_1 = 5/9 x 1  = 3/5  , w 1  = 5/9 x 2 = 0 , w 2 = 5 / 9 x_2 = 0, w_2 = 5/9 x 2  = 0 , w 2  = 5/9 x 3 = 3 / 5 , w 3 = 5 / 9 x_3 = \sqrt{3/5}, w_3 = 5/9 x 3  = 3/5  , w 3  = 5/9  
 
See Wikipedia for n ≥ 4. n \geq 4. n ≥ 4.  
 
Gaussian Quadrature
Approximate the following using the Gaussian quadrature method:
∫ − 1 1 cos  x   d x \int_{-1}^{1} \cos x\,\mathrm{d}x
 ∫ − 1 1  cos x d x 
first with n = 1 n = 1 n = 1 n = 3. n=3. n = 3. 
For n = 1 : n = 1: n = 1 : 
∫ − 1 1 f ( x )   d x ≈ w 1 f ( x ) = 2 cos  ( 0 ) = 2 \begin{align*}
  \int_{-1}^{1} f(x)\,\mathrm{d}x &\approx w_1 f(x)\\
  &= 2 \cos(0)\\
  &= 2
\end{align*}
 ∫ − 1 1  f ( x ) d x  ≈ w 1  f ( x ) = 2 cos ( 0 ) = 2  
For n = 3 : n = 3: n = 3 : 
∫ − 1 1 f ( x )   d x ≈ w 1 f ( − 3 / 5 ) + w 2 f ( 0 ) + w 3 f ( 3 / 5 ) = 5 / 9 ( cos  ( − 3 / 5 ) + cos  0 + cos  ( 3 / 5 ) ) = 1.6830 \begin{align*}
  \int_{-1}^{1} f(x)\,\mathrm{d}x &\approx w_1 f\left(-\sqrt{3/5}\right) + w_2 f(0) + w_3 f\left(\sqrt{3/5}\right)\\
  &= 5/9 \left(\cos\left(-\sqrt{3}/5\right) + \cos 0 + \cos \left(\sqrt{3}/5\right)\right)\\
  &= 1.6830
\end{align*}
 ∫ − 1 1  f ( x ) d x  ≈ w 1  f ( − 3/5  ) + w 2  f ( 0 ) + w 3  f ( 3/5  ) = 5/9 ( cos ( − 3  /5 ) + cos 0 + cos ( 3  /5 ) ) = 1.6830  
The analytical soln 
∫ − 1 1 cos  x   d x = sin  x ∣ − 1 1 ≈ 1.6829 \int_{-1}^{1} \cos x\,\mathrm{d}x = \sin x |_{-1}^{1} \approx 1.6829
 ∫ − 1 1  cos x d x = sin x ∣ − 1 1  ≈ 1.6829 
 Change of Interval 
The method thus far works for interval [ − 1 , 1 ] , [-1, 1], [ − 1 , 1 ] , [ a , b ] : [a, b]: [ a , b ] : 
∫ a b f ( x )   d x ≈ b − a 2 ∑ i = 1 n w i f ( b − a 2 x i + a + b 2 ) \int_{a}^{b} f(x)\,\mathrm{d}x \approx \frac{b-a}{2}\sum_{i=1}^{n} w_i f\left(\frac{b-a}{2}x_i + \frac{a+b}{2}\right)
 ∫ a b  f ( x ) d x ≈ 2 b − a  i = 1 ∑ n  w i  f ( 2 b − a  x i  + 2 a + b  ) 
Quadrature Change of Interval
Approximate the following integral with n = 3 : n = 3: n = 3 : 
∫ 0 4 cos  x   d x ≈ 4 − 0 2 ∑ i = 1 3 w i cos  ( 4 − 0 2 x i + 0 + 4 2 ) = 2 ( 5 9 cos  ( 2 ( − 3 / 5 ) + 2 ) + 8 9 cos  2 + 5 9 cos  ( 2 3 / 5 + 2 ) ) = − 0.7598   \begin{align*}
    \int_{0}^{4} \cos x\,\mathrm{d}x &\approx \frac{4 - 0}{2}\sum_{i=1}^{3}w_i \cos\left(\frac{4 - 0}{2}x_i + \frac{0 + 4}{2}\right)\\
    &= 2 \left(\frac{5}{9} \cos\left(2\left(-\sqrt{3/5}\right) + 2\right) + \frac{8}{9}\cos 2 + \frac{5}{9}\cos\left(2\sqrt{3/5} + 2\right)\right)\\
    &= -0.7598
  \end{align*}
 ∫ 0 4  cos x d x  ≈ 2 4 − 0  i = 1 ∑ 3  w i  cos ( 2 4 − 0  x i  + 2 0 + 4  ) = 2 ( 9 5  cos ( 2 ( − 3/5  ) + 2 ) + 9 8  cos 2 + 9 5  cos ( 2 3/5  + 2 ) ) = − 0.7598  
Analytical soln − 0.7518. -0.7518. − 0.7518. 
 Arc Length Approximation 
s = ∫ u 0 u 1 ∥ p ⃗   ′ ( u ) ∥   d u s = \int_{u_0}^{u_1} \|\vec{p}^{\,\prime}(u)\|\,\mathrm{d}u
 s = ∫ u 0  u 1   ∥ p  ′ ( u ) ∥ d u 
p ⃗   ′ ( u ) = G B u ⃗   ′ , u ⃗   ′ = ( 0 , 1 , 2 u , 2 u 2 ) T \vec{p}^{\,\prime}(u) = GB \vec{u}^{\,\prime},\quad\vec{u}^{\,\prime} = \left(0, 1, 2u, 2u^2\right)^T
 p  ′ ( u ) = GB u ′ , u ′ = ( 0 , 1 , 2 u , 2 u 2 ) T 
Then, define ∥ p ⃗   ′ ∥ 2 = p ⃗   ′ ⋅ p ⃗   ′ \|\vec{p}^{\,\prime}\|_2 = \sqrt{\vec{p}^{\,\prime} \cdot \vec{p}^{\,\prime}} ∥ p  ′ ∥ 2  = p  ′ ⋅ p  ′  s s s 
s ≈ u 1 − u 0 2 ∑ i = 1 n w i ∥ p ⃗   ′ ( u 1 − u 0 2 x i + u 0 + u 1 2 ) ∥ 2 s \approx \frac{u_1 - u_0}{2} \sum_{i=1}^{n} w_i \left\|\vec{p}^{\,\prime}\left(\frac{u_1 - u_0}{2} x_i + \frac{u_0 + u_1}{2}\right)\right\|_2
 s ≈ 2 u 1  − u 0   i = 1 ∑ n  w i   p  ′ ( 2 u 1  − u 0   x i  + 2 u 0  + u 1   )  2  
For n = 2 , n = 2, n = 2 , 
s ≈ 0.1 2 [ ∥ p ⃗   ′ ( 0.1 2 ⋅ − 1 3 + 0.1 2 ) ∥ 2 + ∥ p ⃗   ′ ( 0.1 2 ⋅ 1 3 + 0.1 2 ) ∥ 2 ] = 1 20 ( ∥ p ⃗   ′ ( 0.02113 ) ∥ 2 + ∥ p ⃗   ′ ( 0.07887 ) ∥ 2 ) \begin{align*}
  s &\approx \frac{0.1}{2}\left[\left\|\vec{p}^{\,\prime}\left(\frac{0.1}{2} \cdot \frac{-1}{\sqrt{3}} + \frac{0.1}{2}\right)\right\|_2 + \left\|\vec{p}^{\,\prime}\left(\frac{0.1}{2} \cdot \frac{1}{\sqrt{3}} + \frac{0.1}{2}\right)\right\|_2\right]\\
  &= \frac{1}{20}\Big(\left\|\vec{p}^{\,\prime}(0.02113)\right\|_2 + \left\|\vec{p}^{\,\prime}(0.07887)\right\|_2\Big)
\end{align*}
 s  ≈ 2 0.1  [  p  ′ ( 2 0.1  ⋅ 3  − 1  + 2 0.1  )  2  +  p  ′ ( 2 0.1  ⋅ 3  1  + 2 0.1  )  2  ] = 20 1  ( ∥ p  ′ ( 0.02113 ) ∥ 2  + ∥ p  ′ ( 0.07887 ) ∥ 2  )