Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SER431 Lecture 14

SER431 Lecture 14

Advanced Graphics
Curves and Splines II
(201810)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez

October 03, 2018
Tweet

Transcript

  1. jgs SER 431 Advanced Graphics Lecture 14: Curves and Splines

    II Javier Gonzalez-Sanchez javiergs@asu.edu PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 2 jgs

    Bezier Curve 4 points and the Bezier blending functions P(t) = (1-t)3 P0 + 3t(1-t)2 P1 + 3t2(1-t) P2 + (t)3 P3 Where t is 0 <= t < = 1
  3. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 3 jgs

    P(t) = (1-t) P0 + (t) P1 Bezier | Linear P1 =(6,6) P0 =(3,3) P(0.25) = 0.75(3,3) + 0.25(6,6) P(0.25) = (3.75,3.75)
  4. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 4 jgs

    PA (t) = (1-t) P0 + (t) P1 PB (t) = (1-t) P1 + (t) P2 PC (t) = (1-t) PA + (t) PB PC (t) = (1-t)2 P0 + 2t(1-t) P1 + (t)2 P3 Bezier | Quadratic P1 =(6,6) P0 =(3,3) P2 =(9,3) PA PB PC
  5. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 5 jgs

    PA (t) = (1-t) P0 + (t) P1 PB (t) = (1-t) P1 + (t) P2 PC (t) = (1-t) PA + (t) PB PC (t) = (1-t)2 P0 + 2t(1-t) P1 + (t)2 P3 Bezier | Quadratic
  6. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 6 jgs

    PA (t) = (1-t) P0 + (t) P1 PB (t) = (1-t) P1 + (t) P2 PC (t) = (1-t) P2 + (t) P3 PD (t) = (1-t) PA + (t) PB PE (t) = (1-t) PB + (t) PC PF (t) = (1-t) PD + (t) PE PF (t) = (1-t)3 P0 + 3t(1-t)2 P1 + 3t2(1-t) P2 + (t)3 P3 Bezier | Cubic P1 =(6,6) P0 =(3,3) P2 =(9,3) PA PB PD P3 =(7.5,1.5) PC PE PF
  7. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 7 jgs

    PA (t) = (1-t) P0 + (t) P1 PB (t) = (1-t) P1 + (t) P2 PC (t) = (1-t) P2 + (t) P3 PD (t) = (1-t) PA + (t) PB PE (t) = (1-t) PB + (t) PC PF (t) = (1-t) PD + (t) PE PF (t) = (1-t)3 P0 + 3t(1-t)2 P1 + 3t2(1-t) P2 + (t)3 P3 Bezier | Cubic
  8. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 8 jgs

    PA (t) = (1-t) P0 + (t) P1 PB (t) = (1-t) P1 + (t) P2 PC (t) = (1-t) P2 + (t) P3 PD (t) = (1-t) PA + (t) PB PE (t) = (1-t) PB + (t) PC PF (t) = (1-t) PD + (t) PE = (1-t) ((1-t) PA + (t) PB ) + (t) ((1-t) PB + (t) PC ) = (1-t) ((1-t) ((1-t) P0 + (t) P1 ) + (t) ((1-t) P1 + (t) P2 )) + (t) ((1-t) ((1-t) P1 + (t) P2 ) + (t) ((1-t) P2 + (t) P3 ) = (1-t) (((1-t)(1-t)P0 + (1-t)(t) P1 ) + ((t)(1-t) P1 + (t)(t) P2 )) + (t) (((1-t)(1-t)P1 + (1-t)(t) P2 ) + ((t)(1-t) P2 + (t)(t) P3 )) = (1-t) ((1-t)2P0 + (1-t)(t)P1 + (1-t)(t)P1 +(t)2P2 ) + (t) ((1-t)2P1 + (1-t)(t)P2 + (1-t)(t)P2 +(t)2P3 ) = (1-t)(1-t)2P0 + (1-t)(1-t)(t)P1 + (1-t)(1-t)(t)P1 + (1-t)(t)2P2 + (1-t)2(t) P1 + (1-t)(t)(t) P2 + (1-t)(t)(t) P2 +(t)2(t) P3 = (1-t)3P0 + (1-t)2(t)P1 + (1-t)2(t)P1 + (1-t)(t)2P2 + (1-t)2(t) P1 + (1-t)(t)2 P2 + (1-t)(t)2 P2 +(t)3 P3 PF (t) = (1-t)3 P0 + 3t(1-t)2 P1 + 3t2(1-t) P2 + (t)3 P3 Bezier | Cubic
  9. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 9 jgs

    General Bezier Curves § De Casteljau's algorithm – a recursive method
  10. jgs Source Code

  11. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 11 jgs

    Step 1 // 6 control points float Points[6][3] = { { 10, 5, 0 }, { 8, -10, 0 }, { 6, -10, 0 }, { 4, 5, 0 }, { 0, -5, 0 }, { -10, 5, 0 } }; P0 P1 P2 P3 P4 P5
  12. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 12 jgs

    Step 2 // blending functions float BezierLinear(float a, float b, float t) { return a * (1.0f - t) + b * t; } float BezierQuadratic(float A, float B, float C, float t){ float AB = BezierLinear(A, B, t); float BC = BezierLinear(B, C, t); return BezierLinear(AB, BC, t); } float BezierCubic(float A, float B, float C, float D, float t) { float ABC = BezierQuadratic(A, B, C, t); float BCD = BezierQuadratic(B, C, D, t); return BezierLinear(ABC, BCD, t); } float BezierQuartic(float A, float B, float C, float D, float E, float t) { float ABCD = BezierCubic(A, B, C, D, t); float BCDE = BezierCubic(B, C, D, E, t); return BezierLinear(ABCD, BCDE, t); } float BezierQuintic(float A, float B, float C, float D, float E, float F, float t) { float ABCDE = BezierQuartic(A, B, C, D, E, t); float BCDEF = BezierQuartic(B, C, D, E, F, t); return BezierLinear(ABCDE, BCDEF, t); } float BezierSextic(float A, float B, float C, float D, float E, float F, float G, float t) { float ABCDEF = BezierQuintic(A, B, C, D, E, F, t); float BCDEFG = BezierQuintic(B, C, D, E, F, G, t); return BezierLinear(ABCDEF, BCDEFG, t); }
  13. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 13 jgs

    Step 3 glBegin(GL_LINE_STRIP); glColor3f(0, 1, 0); for (int i = 0; i != LOD; ++i) { float t = (float)i / (LOD - 1); float it = 1.0f - t; // calculate the x, y and z of the curve point float x = BezierQuintic(Points[0][0], Points[1][0], Points[2][0], Points[3][0], Points[4][0], Points[5][0], t); float y = BezierQuintic(Points[0][1], Points[1][1], Points[2][1], Points[3][1], Points[4][1], Points[5][1], t); float z = BezierQuintic(Points[0][2], Points[1][2], Points[2][2], Points[3][2], Points[4][2], Points[5][2], t); // specify the point glVertex3f(x, y, z); } glEnd();
  14. Javier Gonzalez-Sanchez | SER431 | Fall 2018 | 14 jgs

    Test Yourselves § Is it Bezier Curve (black dots) ? § What is its degree? § Could you write the source code?
  15. jgs SER431 Advanced Graphics Javier Gonzalez-Sanchez javiergs@asu.edu Fall 2018 Disclaimer.

    These slides can only be used as study material for the class SER431 at ASU. They cannot be distributed or used for another purpose.