introduction to computer graphics modeling 1
play

Introduction to Computer Graphics Modeling (1) April 18, 2019 - PowerPoint PPT Presentation

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.


  1. Introduction to Computer Graphics – Modeling (1) – April 18, 2019 Kenshi Takayama

  2. Some additional notes on quaternions 2

  3. 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

  4. 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

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. Modeling curves 12

  13. Parametric curves β€’ X & Y coordinates defined by parameter t ( β‰… time) β€’ Example: Cycloid 𝑦 𝑒 = 𝑒 βˆ’ sin 𝑒 𝑧 𝑒 = 1 βˆ’ cos 𝑒 β€’ Tangent (aka. derivative, gradient) vector: 𝑦 β€² 𝑒 , 𝑧 β€² 𝑒 β€’ Polynomial curve: 𝑦 𝑒 = Οƒ 𝑗 𝑏 𝑗 𝑒 𝑗 13

  14. 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

  15. 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

  16. 𝑄 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

  17. 𝑄 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

  18. 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