Introduction to Computer Graphics β Modeling (1) β April 16, 2020 Kenshi Takayama
Some additional notes on quaternions 2
Another explanation for quaternions (overview) 1. Any rotation can be decomposed into even number of reflections 2. Quaternions can concisely describe reflections in 3D π¦ = β β π¦ β π #$ π β " β π β 3. Combining two reflections equivalent to the rotation leads to the formula = cos $ % + π sin $ π¦ cos $ % β π sin $ π ! π β # β π¦ β % % 3
Any rotation can be decomposed into even number of reflections β’ Mathematically proven π β’ Valid for any dimensions R $! # ! ! " " β’ Not unique (of course!) ! # R π One way R π R R ! " Another way R 4
Quaternions recap β’ Complex number: real + imaginary π + π π£ β’ Quaternion: scalar + vector π + β π€ β’ Definition of quaternion multiplication: Scalar part Vector part π ! + π€ ! π " + π€ " β π ! π " β π€ ! β π€ " + π ! π€ " + π " π€ ! + π€ ! Γπ€ " β’ Pure vectors can take multiplication by interpreting them as quaternions: π€ ! π€ " = βπ€ ! β π€ " + π€ ! Γπ€ " β’ Notable properties: π€ β π€ #! = β π€ " π€ β β π€ = β β β If β π€ β π₯ = 0 , then β π€ π₯ = βπ₯ β π€ β’ (Relevant later) π€ " β π€Γ β β π€ is always zero Multiplying β π€ to rhs produces 1 π€ π₯ = β β π€Γπ₯ = βπ₯Γ β π€ = βπ₯ β π€ 5
Describing reflections using quaternions β’ Reflection of a point β π¦ across a plane orthogonal to β π¦ β π : β π π¦ β β β π¦ β π #$ π β " β π β π β’ Holds essential properties of reflections: β’ Linearity : π β # β π¦ π β ' π β π¦ + π β π§ = π π β ' β π¦ + π π β ' β π§ β’ β π gets mapped to β β π : π () = β β ' β π = β β π β π β π β π π¦ β β β’ If a point β π¦ satisfies β π = 0 (i.e. on the plane), β π¦ doesnβt move: π () = β β β π () = β π¦ = β β π¦ β π¦ β β π β ' β π β π π¦ π¦ β β π = 0 , then β π¦ β Because if β π β π¦ = β β π 6 https://math.stackexchange.com/a/7263
Setup for rotation around arbitrary axis π§ β β’ Rotation axis (unit vector) οΌ π π β’ Rotation angle οΌ π π¦ β β’ Point before rotation οΌ β π¦ β’ Point after rotation οΌ β π§ β π %, ' β π¦ β’ Think of local 2D coordinate system οΌ π β β π¦ π β’ βRightβ vector οΌ π£ β β π¦ β π β β π¦ π π€ β β’ βUpβ vector οΌ β π€ β πΓ β π¦ β’ Note that π£ = π€ β π£ β’ (Letβs call it π ) π π 7 https://legacygl-js.glitch.me/demo/quaternion-schematic.html
Decompose rotation into two reflections 1 st reflection οΌ 2 nd reflection οΌ π β β sin $ % π£ + cos $ β β % β π€ π β β π€ Top view β π π π β ' , 8 https://legacygl-js.glitch.me/demo/quaternion-schematic.html
Combining two reflections π 23 = β β π 23 β π 23 = π 23 β = π ! β β π¦ β π β β π¦ β π β β π 23 β’ Formula οΌ π ! π β # β π¦ π β π β β π π¦ β β π β β sin ! " π£ + cos ! β’ Substitute π β β π€, " β π€ to the above π β β’ For the left part β π οΌ (because π£ β β π€ = 0 ) π # cos ! π β β β π = β sin ! " π£ + cos ! " β π€ β β π€ = " π€ = π " π ) (because π£Γ β βπ # sin ! πΓ β β π = β sin ! " π£ + cos ! " β π€ Γ β π€ = " π Therefore, βπ % cos . π β π β β πΓ β / + π sin . β π = β β π + β π = / π 23 β π 23 = 0 1 π 23 β π 23 = βπ 2% cos . β’ The right part β 23 is analogous οΌ β / β π sin . / β’ Finally, we get the formula οΌ = βπ ' cos ! βπ (' cos ! " + π sin ! " β π sin ! π !, # β π¦ = π $ π β & β π¦ π¦ β " " cos ! " + π sin ! π¦ cos ! " β π sin ! = β " " 9
Representing and blending poses using quaternions β # β’ Any rotations (poses) can be π π = cos ! " + π sin ! represented as unit quaternions " β’ Points on hypersphere of 4D space β’ Fix π and vary π βπ Γ¨ unit circle in 4D space π =0 (1, 0,0,0) β’ A pose after rotating 360 Β° about a certain axis is represented as another quaternion π = π π =3 π (0, π % , π & , π ' ) (0, - π % ,- π & ,- π ' ) β’ One pose corresponds to two quaternions (double cover) π =2 π β’ A geodesic between two points π, π on the (-1, 0,0,0) hypersphere represents interpolation of these poses β’ Should pick either π or βπ which is closer to π (i.e. 4D dot product is positive) 10
Normalize quaternions or not? β’ Any quaternions can be written as scaling of unit quaternions " , π () = π () cos ! π = π cos ! " + π sin ! " β π sin ! " β’ In the rotation formula, the scaling part is cancelled π¦ π () = π cos ! π¦ π () cos ! " + π sin ! " β π sin ! = cos ! " + π sin ! π¦ cos ! " β π sin ! π β β β " " " " π " Γ¨ so, normalization isnβt needed? β’ In practice, donβt use quaternion mults for computing coordinate transformation (because inefficient) β’ Just do explicit vector calc using axis & angle ) ! *) " π¦ β π β β β π¦ π cos π + πΓ β π¦ sin π + π β β π¦ π " π = 1 β’ Can get axis & angle only after normalization β’ Un-normalized can cause artifact when interpolated π ( 11
Modeling curves 12
Parametric curves β’ X & Y coordinates defined by parameter t ( β time) β’ Example: Cycloid π¦ π’ = π’ β sin π’ π§ π’ = 1 β cos π’ β’ Tangent (aka. derivative, gradient) vector: π¦ < π’ , π§ < π’ β’ Polynomial curve: π¦ π’ = β = π = π’ = 13
Cubic Hermite curves x π¦ 0 = π¦ @ β’ Cubic polynomial curve interpolating π¦ 1 = π¦ 3 B derivative constraints at both ends π¦β²(0) = π¦ @ π¦ B 1 = π¦ 3 B (Hermite interpolation) 0 1 t π¦ 0 = π @ = π¦ @ β’ 4 constraints Γ¨ 4 DoF needed π¦ 1 = π @ + π 3 + π % + π A = π¦ 3 Γ¨ 4 coefficients Γ¨ cubic π¦ B 0 = π 3 B = π¦ @ β’ π¦ π’ = π @ + π 3 π’ + π % π’ % + π A π’ A π¦ B 1 = π 3 + 2 π % + 3 π A B = π¦ 3 β’ π¦β² π’ = π 3 + 2π % π’ + 3π A π’ % Γ¨ π @ = π¦ @ B β’ Coeffs determined by substituting π 3 = π¦ @ B β π¦ 3 B constrained values & derivatives π % = β3 π¦ @ + 3 π¦ 3 β 2 π¦ @ B + π¦ 3 B π A = 2 π¦ @ β 2 π¦ 3 + π¦ @ 14
Bezier curves π β’ Input: 3 control points (CPs) π > , π $ , π , 3 β’ Coordinates of points in arbitrary domain (2D, 3D, ...) π π’ = ? π % Eq. of Bezier curve β’ Output: Curve π π’ satisfying t=1 π 0 = π > π @ π π’ = 1 β π’ π @ + π’ π % π 1 = π , t=0 Eq. of line segment while being βpulledβ by π $ 15
π 3 Bezier curves Eq. of line π’ π 3% π’ 1 β π’ 1 β π’ Eq. of line β’ π @3 π’ = 1 β π’ π @ + π’ π π @3 π’ π’ 1 β π’ 3 π @3% π’ β’ π 3% π’ = 1 β π’ π 3 + π’ π % π % β’ π *) 0 = π * π’ β’ π )' 1 = π ' π @ β’ Idea: βInterpolate the interpolationβ As π’ changes 0 β 1 , smoothly transition from π @3 to π 3% β’ π @3% π’ = 1 β π’ π @3 π’ + π’ π 3% π’ = 1 β π’ 1 β π’ π @ + π’ π 3 + π’ 1 β π’ π 3 + π’ π % = 1 β π’ % π @ + 2π’ 1 β π’ π 3 + π’ % π % Quadratic Bezier curve 16
π 3 Bezier curves β’ π @3 π’ = 1 β π’ π @ + π’ π 3 β’ π 3% π’ = 1 β π’ π 3 + π’ π % π % β’ π *) 0 = π * β’ π )' 1 = π ' π @ β’ Idea: βInterpolate the interpolationβ As π’ changes 0 β 1 , smoothly transition from π @3 to π 3% β’ π @3% π’ = 1 β π’ π @3 π’ + π’ π 3% π’ = 1 β π’ 1 β π’ π @ + π’ π 3 + π’ 1 β π’ π 3 + π’ π % = 1 β π’ % π @ + 2π’ 1 β π’ π 3 + π’ % π % Quadratic Bezier curve 17
Cubic Bezier curve Quad. Bezier π 3%A π’ π % π 3 β’ Exact same idea applied to 4 points π @ , π 3 , π % π A : Quad. Bezier 1 β π’ π @3% π’ β’ As π’ changes 0 β 1 , transition from π *)' to π π @3%A π’ )'+ π A π’ π @ β’ π @3%A π’ = 1 β π’ π @3% π’ + π’ π 3%A π’ = 1 β π’ 1 β π’ ' π * + 2π’ 1 β π’ π ) + π’ ' π ' + π’ 1 β π’ ' π ) + 2π’ 1 β π’ π ' + π’ ' π + 3 + 3π’ % 1 β π’ π % + π’ A π A = 1 β π’ A π @ + 3π’ 1 β π’ % π Cubic Bezier curve 18
Recommend
More recommend