Introduction to Computer Graphics β Modeling (1) β April 18, 2019 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 π¦ = β Τ¦ π¦ Τ¦ π β1 π Τ¦ π Τ¦ π Τ¦ 3. Combining two reflections equivalent to the rotation leads to the formula = cos π 2 + π sin π π¦ cos π 2 β π sin π π π π Τ¦ π Τ¦ π¦ Τ¦ 2 2 3
Any rotation can be decomposed into even number of reflections β’ Mathematically proven π β’ Valid for any dimensions 3π 4 π π β’ Not unique (of course!) 2 2 π 4 R One way π π R π 2 Another way R 4
Quaternions recap β’ Complex number: real + imaginary π + π π£ β’ Quaternion: scalar + vector π + Τ¦ π€ β’ Definition of quaternion multiplication: Scalar part Vector part π 1 + π€ 1 π 2 + π€ 2 β π 1 π 2 β π€ 1 β π€ 2 + π 1 π€ 2 + π 2 π€ 1 + π€ 1 Γ π€ 2 β’ Pure vectors can take multiplication by interpreting them as quaternions: π€ 1 π€ 2 = βπ€ 1 β π€ 2 + π€ 1 Γ π€ 2 β’ Notable properties: π€ Τ¦ π€ β1 = β π€ 2 If Τ¦ π€ β π₯ = 0 , then Τ¦ π€ Τ¦ Τ¦ π€ = β Τ¦ Τ¦ π€ π₯ = βπ₯ Τ¦ π€ β’ (Relevant later) π€ 2 Τ¦ π€ is always zero Multiplying Τ¦ π€ to rhs produces 1 π€ Γ Τ¦ Τ¦ π€ π₯ = Τ¦ Τ¦ π€ Γ π₯ = βπ₯ Γ Τ¦ π€ = βπ₯ Τ¦ π€ 5
Describing reflections using quaternions β’ Reflection of a point Τ¦ π¦ across a plane orthogonal to Τ¦ π : π¦ Τ¦ Τ¦ π π¦ β β Τ¦ π¦ Τ¦ π β1 π Τ¦ π Τ¦ π Τ¦ β’ Holds essential properties of reflections: π β’ Linearity : π Τ¦ π Τ¦ π¦ π Τ¦ π π Τ¦ π¦ + π Τ¦ π§ = π π Τ¦ π Τ¦ π¦ + π π Τ¦ π Τ¦ π§ π gets mapped to β Τ¦ β’ Τ¦ π : π β1 = β Τ¦ π Τ¦ π = β Τ¦ π Τ¦ π Τ¦ π Τ¦ π β’ If a point Τ¦ π¦ satisfies Τ¦ π = 0 (i.e. on the plane), Τ¦ π¦ doesnβt move: π¦ β Τ¦ π β1 = β β Τ¦ π β1 = Τ¦ π¦ = β Τ¦ π¦ Τ¦ π¦ Τ¦ Τ¦ Because if Τ¦ π = 0 , then Τ¦ π Τ¦ π Τ¦ π Τ¦ π π¦ π¦ β Τ¦ π¦ Τ¦ π Τ¦ π¦ = β Τ¦ π 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://thimbleprojects.org/kenshi84/50110/demo/quaternion-schematic.html
Decompose rotation into two reflections 1 st reflection οΌ 2 nd reflection οΌ π β β sin π 2 π£ + cos π Τ¦ Τ¦ 2 Τ¦ π€ π β Τ¦ π€ Top view Τ¦ π π π Τ¦ π 2 8 https://thimbleprojects.org/kenshi84/50110/demo/quaternion-schematic.html
Combining two reflections π β1 = β Τ¦ π β1 Τ¦ π β1 = π β1 Τ¦ β’ Formula οΌ π π π Τ¦ = π π β Τ¦ π¦ Τ¦ π β Τ¦ π¦ Τ¦ π Τ¦ Τ¦ π β1 π Τ¦ π¦ π Τ¦ π Τ¦ Τ¦ π π¦ Τ¦ β’ Substitute to the above Τ¦ π β β sin π 2 π£ + cos π π β Τ¦ π€, 2 Τ¦ π€ β’ For the left part Τ¦ π Τ¦ π οΌ (because π£ β Τ¦ π€ = 0 ) π 2 cos π π β Τ¦ π = β sin π 2 π£ + cos π Τ¦ 2 Τ¦ π€ β Τ¦ π€ = (because π£ Γ Τ¦ π€ = π 2 π ) 2 βπ 2 sin π π Γ Τ¦ π = β sin π 2 π£ + cos π Τ¦ 2 Τ¦ π€ Γ Τ¦ π€ = 2 π Therefore, βπ 2 cos π π Τ¦ π β Τ¦ π Γ Τ¦ 2 + π sin π Τ¦ π = β Τ¦ π + Τ¦ π = 2 π β1 Τ¦ π β1 = π π π β1 Τ¦ π β1 = βπ β2 cos π β’ The right part Τ¦ π4 is analogous οΌ Τ¦ 2 β π sin π 2 β’ Finally, we get the formula οΌ = βπ 2 cos π βπ β2 cos π 2 + π sin π 2 β π sin π π π, π Τ¦ π¦ = π π π Τ¦ π Τ¦ π¦ π¦ Τ¦ 2 2 cos π 2 + π sin π π¦ cos π 2 β π sin π = Τ¦ 2 2 9
Representing and blending poses using quaternions β 4 β’ Any rotations (poses) can be π = cos π 2 + π sin π represented as unit quaternions π 2 β’ 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, π x , π y , π z ) (0, - π x ,- π y ,- π z ) β’ 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 2 , π β1 = π β1 cos π π = π cos π 2 + π sin π 2 β π sin π 2 β’ In the rotation formula, the scaling part is cancelled π¦ π β1 = π cos π π¦ π β1 cos π 2 + π sin π 2 β π sin π = cos π 2 + π sin π π¦ cos π 2 β π sin π π Τ¦ Τ¦ Τ¦ 2 2 2 2 π 2 ο¨ 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 π 1 +π 2 π¦ β π β Τ¦ Τ¦ π¦ π cos π + π Γ Τ¦ π¦ sin π + π β Τ¦ π¦ π 2 π = 1 β’ Can get axis & angle only after normalization β’ Un-normalized can cause artifact when interpolated π 1 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 = π¦ 0 β’ Cubic polynomial curve interpolating π¦ 1 = π¦ 1 derivative constraints at both ends β² π¦β²(0) = π¦ 0 π¦ β² 1 = π¦ 1 (Hermite interpolation) 0 1 t β² β’ 4 constraints ο¨ 4 DoF needed π¦ 0 = π 0 = π¦ 0 ο¨ 4 coefficients ο¨ cubic π¦ 1 = π 0 + π 1 + π 2 + π 3 = π¦ 1 π¦ β² 0 = π 1 β² = π¦ 0 β’ π¦ π’ = π 0 + π 1 π’ + π 2 π’ 2 + π 3 π’ 3 π¦ β² 1 = π 1 + 2 π 2 + 3 π 3 β² = π¦ 1 β’ π¦β² π’ = π 1 + 2π 2 π’ + 3π 3 π’ 2 ο¨ π 0 = π¦ 0 β’ Coeffs determined by substituting β² π 1 = π¦ 0 β² β π¦ 1 constrained values & derivatives β² π 2 = β3 π¦ 0 + 3 π¦ 1 β 2 π¦ 0 β² + π¦ 1 β² π 3 = 2 π¦ 0 β 2 π¦ 1 + π¦ 0 14
Bezier curves β’ Input: 3 control points (CPs) π 0 , π π 1 , π 2 1 β’ Coordinates of points in arbitrary domain (2D, 3D, ...) π π’ = ? Eq. of Bezier curve π 2 β’ Output: Curve π π’ satisfying t=1 π 0 = π 0 π 0 π π’ = 1 β π’ π 0 + π’ π 2 π 1 = π 2 t=0 Eq. of line segment while being βpulledβ by π 1 15
π 1 Bezier curves Eq. of line π’ π 12 π’ 1 β π’ Eq. of line 1 β π’ β’ π 01 π’ = 1 β π’ π 0 + π’ π π 01 π’ π’ 1 β π’ 1 π 012 π’ β’ π 12 π’ = 1 β π’ π 1 + π’ π 2 π 2 β’ π 01 0 = π 0 π’ β’ π 12 1 = π 2 π 0 β’ Idea: βInterpolate the interpolationβ As π’ changes 0 β 1 , smoothly transition from π 01 to π 12 β’ π 012 π’ = 1 β π’ π 01 π’ + π’ π 12 π’ = 1 β π’ 1 β π’ π 0 + π’ π 1 + π’ 1 β π’ π 1 + π’ π 2 = 1 β π’ 2 π 0 + 2π’ 1 β π’ π 1 + π’ 2 π 2 Quadratic Bezier curve 16
π 1 Bezier curves β’ π 01 π’ = 1 β π’ π 0 + π’ π 1 β’ π 12 π’ = 1 β π’ π 1 + π’ π 2 π 2 β’ π 01 0 = π 0 β’ π 12 1 = π 2 π 0 β’ Idea: βInterpolate the interpolationβ As π’ changes 0 β 1 , smoothly transition from π 01 to π 12 β’ π 012 π’ = 1 β π’ π 01 π’ + π’ π 12 π’ = 1 β π’ 1 β π’ π 0 + π’ π 1 + π’ 1 β π’ π 1 + π’ π 2 = 1 β π’ 2 π 0 + 2π’ 1 β π’ π 1 + π’ 2 π 2 Quadratic Bezier curve 17
Cubic Bezier curve Quad. Bezier π 123 π’ π 2 π 1 β’ Exact same idea applied to 4 points π 0 , π 1 , π 2 π 3 : Quad. Bezier 1 β π’ π 012 π’ β’ As π’ changes 0 β 1 , transition from π 012 to π π 0123 π’ 123 π 3 π’ π 0 β’ π 0123 π’ = 1 β π’ π 012 π’ + π’ π 123 π’ = 1 β π’ 1 β π’ 2 π 0 + 2π’ 1 β π’ π 1 + π’ 2 π 2 + π’ 1 β π’ 2 π 1 + 2π’ 1 β π’ π 2 + π’ 2 π 3 1 + 3π’ 2 1 β π’ π 2 + π’ 3 π 3 = 1 β π’ 3 π 0 + 3π’ 1 β π’ 2 π Cubic Bezier curve 18
Recommend
More recommend