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.
/**
* bezier_path.js, By Wayne Brown, Fall 2017
*/
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 C. Wayne Brown
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
"use strict";
/**------------------------------------------------------------------------
* Store and manipulate a path defined by four control points.
* @param control_points {Array} of four glPoint4 locations
* @param start_frame {number} the frame to start the path animation
* @param end_frame {number} the frame to end the path animation
* @param color {Array} RGBA color for displaying the path
* @constructor
*/
window.BezierPath = function (control_points,
start_frame, end_frame,
color) {
// Constructor
/**
* bezier_scene.js, By Wayne Brown, Fall 2017
*/
/**
* The MIT License (MIT)
*
* Copyright (c) 2015 C. Wayne Brown
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
"use strict";
/** -----------------------------------------------------------------------
* Create a WebGL 3D scene, store its state, and render its models.
*
* @param id {string} The id of the webglinteractive directive
* @param download {SceneDownload} An instance of the SceneDownload class
* @param vshaders_dictionary {object} A dictionary of vertex shaders.
* @param fshaders_dictionary {object} A dictionary of fragment shaders.
* @param models {object} A dictionary of models.
* @constructor
*/
window.BezierChainedScene = function (id, download, vshaders_dictionary,
fshaders_dictionary, models) {
A series of connected Bezier paths.
current frame 0 : 0 120
Show path 0 (in black)
Show path 1 (in red)
Show path 2 (in green)
Show path 3 (in blue)
Please note the following characteristics of the above demonstration program:
- The first segment of the path sets
p0
andp1
at the same location. This makes the initial speed zero, which means the object starts from a stationary position. The same technique is used forp2
andp3
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?
u
and n
are known, how can vector v
be calculated.