8.8 - Chained Bezier Paths

Complex animations can be defined by a series of connected Bezier paths. Special care must be taken when connecting two Bezier paths to make sure that the speed and acceleration at the point of connection are consistent. An instantaneous change in either speed or acceleration can cause a visible “jerk” or “jump” in motion that is typically undesirable.

To connect two Bezier paths and maintain contiguous location, the p0 control point for the second path must be equal to the p3 control point of the first path.

To make the speed between two Bezier paths consistent you must make the vector <p1-p0> of the second path be equal to the vector <p3-p2> of the first path.

To make the acceleration between two Bezier paths consistent you must make the vector <6*(-1)(p1-p0) + 6*(p2-p1)> of the second path be equal to vector <6*(-1)(p2-p1) + 6*(p3-p2)> of the first path. An instantaneous change in acceleration is not as visibly noticeable as an instantaneous change in speed. Therefore you can often ignore the sync’ing of the accelerations because the visual artifacts might be minimal.

Mathematical Proof

The criteria to sync two Bezier paths is easily derived from the Bezier parametric equations.

Bezier parametric equation

p = (1-t)3 * p0 + 3*(1-t)2*t* p1 + 3*(1-t)*t2* p2 + t3* p3;

Using derivatives we have:

speed = d(p)/dt = 3*[(1-t)^2(p1-p0) + 2(1-t)(t)(p2-p1) + (t^2)(p3-p2)]
acceleration = d(speed)/dt = 6*[(-1+t)(p1-p0) + (1-2t)(p2-p1) + t(p3-p2)]

To synchronize two paths we need to know the speed and acceleration at the end-points of the path. This is easily calculated by setting t to 0.0 and 1.0 respectively.

  path starts when t===0.0 path ends when t===1.0
speed = <3*(p1-p0)> <3*(p3-p2)>
acceleration = <6*(-1)(p1-p0) + 6*(p2-p1)> <6*(-1)(p2-p1) + 6*(p3-p2)>

A WebGL Program

The following WebGL program defines a complex path using four connected Bezier parametric equations. A class named BezierPath defines a path using four control points along with a starting and ending frame to define when the motion occurs. You can experiment with the animation by changing the control points and the frame intervals in the bezier_chained_scene.js code, lines 81-101. A new class called BezierSeries implements functionality to track a frame counter over the various Bezier paths. It is defined in the bezier_chained.js file in lines 204-262.

Please experiment with this WebGL program and then study the comments below.

Show: Code   Canvas   Run Info
 
1
/**
2
 * bezier_path.js, By Wayne Brown, Fall 2017
3
 */
4
5
/**
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2015 C. Wayne Brown
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in all
18
 * copies or substantial portions of the Software.
19
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 * SOFTWARE.
27
 */
28
29
"use strict";
30
31
/**------------------------------------------------------------------------
32
 * Store and manipulate a path defined by four control points.
33
 * @param control_points {Array} of four glPoint4 locations
34
 * @param start_frame {number} the frame to start the path animation
35
 * @param end_frame {number} the frame to end the path animation
36
 * @param color {Array} RGBA color for displaying the path
37
 * @constructor
38
 */
39
window.BezierPath = function (control_points,
40
                              start_frame, end_frame,
41
                              color) {
42
  // Constructor
257
 
1
/**
2
 * bezier_scene.js, By Wayne Brown, Fall 2017
3
 */
4
5
/**
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2015 C. Wayne Brown
9
 *
10
 * Permission is hereby granted, free of charge, to any person obtaining a copy
11
 * of this software and associated documentation files (the "Software"), to deal
12
 * in the Software without restriction, including without limitation the rights
13
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
 * copies of the Software, and to permit persons to whom the Software is
15
 * furnished to do so, subject to the following conditions:
16
 *
17
 * The above copyright notice and this permission notice shall be included in all
18
 * copies or substantial portions of the Software.
19
20
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
 * SOFTWARE.
27
 */
28
29
"use strict";
30
31
/** -----------------------------------------------------------------------
32
 * Create a WebGL 3D scene, store its state, and render its models.
33
 *
34
 * @param id {string} The id of the webglinteractive directive
35
 * @param download {SceneDownload} An instance of the SceneDownload class
36
 * @param vshaders_dictionary {object} A dictionary of vertex shaders.
37
 * @param fshaders_dictionary {object} A dictionary of fragment shaders.
38
 * @param models {object} A dictionary of models.
39
 * @constructor
40
 */
41
window.BezierChainedScene = function (id, download, vshaders_dictionary,
42
                                fshaders_dictionary, models) {
../_static/08_bezier_chained/bezier_chained.html

A series of connected Bezier paths.

Please use a browser that supports "canvas"

Timing:
current frame 0 : 0 120
Path segments:
Show path 0 (in black)
Show path 1 (in red)
Show path 2 (in green)
Show path 3 (in blue)

Open this webgl program in a new tab or window

Please note the following characteristics of the above demonstration program:

  • The first segment of the path sets p0 and p1 at the same location. This makes the initial speed zero, which means the object starts from a stationary position. The same technique is used for p2 and p3 of the last path segment so that the speed is zero at the end of the motion.
  • The starting and ending vectors defined by the control-points of each segment are deliberately set to make the speed and acceleration consistent over the transition from one path segment to the next, except in the last transition, where the speed vector makes a hard turn in direction. There is a visible “jump” or “jerk” in the animation at this transition point. (Try to change the definition of the last segment to remove this discontiuity.)
  • If you drag or click on the HTML slider that manipulates the frame counter, it becomes the active input element and it will accept keyboard commands. Use the arrow keys on the keyboard to step through the animation sequence one frame at a time to see the detailed motion of the object along the path.

Summary

A series of connected Bezier paths can describe complex motion by giving an animator control over the location, speed, and acceleration of an animated object. Careful design and placement of the control points is required to achieve control of all three path characteristics at the same time.

Glossary

Bezier parametric equation
A function of one variable, t, that calculates changes along a “path”.
Speed vector
The first derivative of an equation of motion. Speed always has a direction and a magnitude.

Self Assessment

Q-355: What is required for a Bezier path to have a speed of zero at its starting location?






Q-356: If vectors u and n are known, how can vector v be calculated.





Q-357: How can you make an object move more slowly along a path – without changing the path’s location?





Next Section - 8.9 - Other Parametric Equations